CSV to SQLite Converter
Convert CSV files to SQLite database files or SQL scripts online. Auto-detects column types, handles RFC 4180 edge cases, and exports real .sqlite binary files.
About
Importing CSV data into SQLite without type validation produces TEXT-only columns. Queries against untyped columns bypass index optimizations and return incorrect results for numeric comparisons. This converter parses CSV files using a strict RFC 4180 finite-state machine, auto-infers column types (INTEGER, REAL, TEXT) by statistical sampling, and generates both executable SQL scripts and binary .sqlite database files. Empty fields map to NULL rather than empty strings. Single quotes in values are escaped per SQL standard as ''.
The type inference engine samples up to 100 rows and requires a 90% match rate (excluding blanks) before promoting a column from TEXT to a numeric type. This threshold prevents misclassification from occasional non-numeric entries like placeholder dashes or units embedded in cells. Column types can be manually overridden before export. The tool processes files entirely in your browser. No data leaves your machine.
Formulas
The CSV parser operates as a Finite State Machine with four states. Each character c at position i triggers a state transition:
State set S = { FIELD_START, UNQUOTED, QUOTED, QUOTE_IN_QUOTED }. On FIELD_START: if c = """, transition to QUOTED; if c = delimiter, emit empty field; otherwise enter UNQUOTED and append. On QUOTED: if c = """, transition to QUOTE_IN_QUOTED; otherwise append. On QUOTE_IN_QUOTED: if c = """, append literal quote and return to QUOTED; if c = delimiter or newline, emit field.
Type inference uses a threshold function for each column j:
Where matchint counts cells matching ^-?\d+$, matchreal counts cells matching the integer or floating-point pattern, and non_empty is the count of non-blank cells in the sample of up to 100 rows. Integer check runs first; if it passes, REAL is not tested.
Reference Data
| CSV Feature | RFC 4180 Rule | This Converter |
|---|---|---|
| Delimiter | Comma (,) | Auto-detect or manual: comma, semicolon, tab, pipe |
| Quoted Fields | Enclosed in double quotes | Full support, preserves inner content |
| Escaped Quotes | "" inside quoted field | Converted to single " in output |
| Newlines in Fields | Allowed inside quotes | Preserved as \n in SQL strings |
| Header Row | Optional (first record) | Toggle on/off; auto-generates col_N names |
| Trailing CRLF | Optional on last record | Stripped, no empty trailing row |
| BOM (Byte Order Mark) | Not specified | UTF-8 BOM auto-stripped |
| Empty Fields | Allowed (,,) | Mapped to NULL in SQLite |
| Mixed Line Endings | CRLF recommended | Handles CRLF, LF, and CR |
| Whitespace Trimming | Not specified | Optional toggle (default: trim) |
| Type: INTEGER | N/A | Pattern: ^-?\d+$ |
| Type: REAL | N/A | Pattern: ^-?\d*\.\d+([eE][+-]?\d+)?$ |
| Type: TEXT | N/A | Fallback for all non-numeric columns |
| SQL Escaping | N/A | Single quotes doubled: ' → '' |
| Table Name | N/A | Derived from filename, sanitized to [a-zA-Z0-9_] |
| Max Columns | No limit | SQLite limit: 2000 columns |
| Max File Size | N/A | Recommended < 50 MB for browser stability |
| Encoding | Not specified | UTF-8 (browser default via FileReader) |
| NULL Handling | No standard | Empty field → NULL; quoted empty → empty string '' |
| Column Name Sanitization | N/A | Non-alphanumeric chars replaced with _, quoted in SQL with " |