Documentation Menu
SQL Repair Tool Documentation
SQL Script Repair Engine
The SQL Script Repair Engine is a specialized, fault-tolerant parser designed to repair corrupted, truncated, and malformed .sql text dumps. Unlike generic binary repair tools, this engine utilizes a Lexical Tokenization State Machine that steps through broken scripts character-by-character, allowing it to recover valid database statements even when standard database engines crash with a syntax error.
1. How the Repair Pipeline Works
When you submit a damaged SQL file, the engine follows a strict multi-stage deterministic pipeline:
- Encoding Normalization: The file is scanned for invalid Byte Order Marks (BOMs) and invalid UTF-8 sequences. These are safely mapped or stripped without losing the surrounding data.
- Dialect Inference: The engine heuristically scans for dialect-specific keywords (e.g.,
ENGINE=InnoDBfor MySQL,pg_catalogfor PostgreSQL) to adjust quote-escaping and delimiter rules. - Lexical Chunking: A state machine traverses the file, independently tracking string literals (
'...',"...",`...`), block comments (/* ... */), and statement terminators (:orGO). - Boundary Reconstruction: When a corruption class is detected (such as a string literal left unclosed because the file abruptly ends), the engine forcefully seals the boundary to prevent the error from cascading.
- Validation Matrix: Statements are re-assembled. Missing trailing delimiters are appended, and the final script is output.
2. Supported Environments
Browser Repair (Local)
For maximum privacy, .sql files under 50MB are repaired entirely within your browser using Web Workers. Your database schema and data never leave your local machine.
Advanced Cloud Repair (Streaming)
Database dumps easily reach gigabytes in size. Files between 50MB and 10GB are automatically routed to the MyFileFixer Cloud infrastructure, which uses chunk-based streaming to repair the file without crashing your browser's V8 memory limits.
Note: AI Fallback (using LLMs for schema hallucination checks) is currently experimental and disabled for SQL text recovery to prioritize absolute data preservation.
3. Supported SQL Dialects
The engine uses dialect inference to apply the correct syntax rules. We support:
- MySQL / MariaDB: Full support for backticks (
`), hash comments (#), and InnoDB engine-specific quirks. - PostgreSQL: Supports
\connectand standardpg_catalogheuristics. - SQLite: Recognizes
PRAGMAheaders and auto-increment conventions. - SQL Server (MSSQL): Supports
GOdelimiters andNVARCHARinferences. - Generic SQL: If no specific dialect is detected, strict ANSI SQL fallback rules apply.
Limitation: While highly compatible, dialect detection relies on heuristic scanning. Highly obscure or purely custom proprietary dialects may fall back to Generic SQL rules.
4. Supported Corruption Classes
The engine isolates and classifies corruption into specific diagnostic codes:
Syntax Corruption (Class A)
- What it is: Missing parentheses in massive multi-row
INSERTblocks. - How we fix it: The engine utilizes a balancing heuristic to close hanging parentheses before applying the final statement delimiter.
Quote Corruption (Class B)
- What it is: An unescaped apostrophe or quotation mark inside a data value that causes the database server to interpret the next 500MB of the dump as a single massive string.
- How we fix it: The state machine detects when a string spans an irrational number of lines or crosses structural boundaries, forcefully escaping or sealing the quote to save the remainder of the file.
Delimiter Corruption (Class C)
- What it is: Missing semicolons (
;) orGOcommands separating distinct statements. - How we fix it: Inferred based on dialect and statement start keywords (e.g., jumping from
INSERTimmediately toCREATE).
CREATE / INSERT Corruption (Classes D & E)
- What it is: Malformed structural definitions.
- How we fix it: The engine isolates the strictly broken fragment. If an
INSERTrow is hopelessly mangled, it is discarded to save the other valid rows in the statement.
Comment Corruption (Class F)
- What it is: An unclosed
/*block comment that accidentally comments out the remainder of the database script. - How we fix it: The engine forces a
*/closure if the end of the file is reached while still inside a block comment state.
Encoding Corruption (Class G)
- What it is: Invisible UTF-16 BOMs mixed with UTF-8 data, often caused by opening the dump in a legacy text editor.
- How we fix it: Handled during Stage 1 normalization.
Truncated SQL (Class H)
- What it is: The file abruptly ends at 50% because the export process crashed or ran out of memory.
- How we fix it: The engine seals whatever statement it was currently processing and appends a trailing delimiter, ensuring the file is syntactically valid up to the cut-off point.
Duplicate / Ordering Problems (Classes I & J)
- What it is: Network packet duplication causing a statement to be written twice, or out of order dependencies.
- How we fix it: Processed during advanced chunk parsing, though dependency resolving (e.g. creating tables before foreign keys are enforced) relies primarily on your SQL server's settings (e.g.
SET FOREIGN_KEY_CHECKS=0).
5. Validation and Data Safety
Data Preservation is Priority #1. We operate on a strict rule: We never hallucinate user data.
- Original File Preserved: The repair engine works entirely on a temporary memory buffer copy. Your original uploaded file is never modified or overwritten.
- Partial Recovery: If your
.sqlfile was truncated halfway through by a failed FTP transfer, the missing data cannot magically be recovered because it was never written to the disk. The engine will successfully rescue the first 50% and safely seal the file. We prefer an honest 50% recovery over a fake 100% recovery. - No Fabrication: The engine will not invent fake table names, records, or schema data just to appease a parser. Broken chunks are isolated, reported, and safely skipped to allow the valid chunks to execute.
6. Frequently Asked Questions (FAQ)
Can I repair a corrupted SQL file?
Yes. If your database server rejects your .sql script due to syntax errors, unclosed strings, or truncation, our tool can restructure the lexical boundaries to make it valid again.
Can I repair a SQL dump?
Yes. We support standard text-based database dumps (e.g., generated by mysqldump or pg_dump).
Can SQL data be recovered after corruption? Yes, but only the data that physically exists within the file. We cannot recover data that was lost due to truncation before the export finished.
Can I repair a truncated SQL file? Absolutely. Truncation (Class H) is one of the most common issues we fix. The engine will safely seal the last open string, comment, and statement so the file can execute properly up to the truncation point.
Can I repair MySQL, PostgreSQL, or SQLite files? Yes. The engine automatically detects the dialect and applies the correct quote-escaping and delimiter rules for MySQL, PostgreSQL, SQLite, and SQL Server.
Can I repair broken INSERT or CREATE TABLE statements?
Yes. The engine isolates broken INSERT rows to preserve the valid ones, and will attempt to reconstruct damaged CREATE TABLE boundaries.
What happens if some SQL cannot be recovered? If a specific fragment is irreparably damaged (e.g., overwritten by zero-bytes), the engine will discard that specific fragment and move to the next valid statement. The final diagnostic report will show exactly how many statements were recovered vs unchanged.
Is the original SQL file modified? No. All repairs happen in-memory on a copy of the file. You download a separate repaired file.
When should I use advanced cloud repair? The system automatically routes files over 50MB to the cloud repair pipeline. You do not need to configure this manually. If your browser crashes attempting a repair, it means the file is too large for Web Workers and should be uploaded via the cloud route.
For issues with binary database formats (like Microsoft Access .mdb or Outlook .pst), please see our Outlook PST Repair Tool.
.png&w=3840&q=75)