Created
February 23, 2016 21:59
-
-
Save augustomen/5b6869445ace1c16f1e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
import sys | |
def main(): | |
sys.stdout.write("SET sql_mode='NO_BACKSLASH_ESCAPES';\n") | |
lines = sys.stdin.read().splitlines() | |
for line in lines: | |
sys.stdout.write(process_line(line)) | |
sys.stdout.write('\n') | |
sys.stdout.flush() | |
def process_line(line): | |
if (line.startswith("PRAGMA") or | |
line.startswith("BEGIN TRANSACTION;") or | |
line.startswith("COMMIT;") or | |
line.startswith("DELETE FROM sqlite_sequence;") or | |
line.startswith("INSERT INTO \"sqlite_sequence\"")): | |
return '' | |
line = line.replace("AUTOINCREMENT", "AUTO_INCREMENT") | |
line = line.replace("DEFAULT 't'", "DEFAULT '1'") | |
line = line.replace("DEFAULT 'f'", "DEFAULT '0'") | |
line = line.replace(",'t'", ",'1'") | |
line = line.replace(",'f'", ",'0'") | |
in_string = False | |
newline = '' | |
for c in line: | |
if not in_string: | |
if c == "'": | |
in_string = True | |
elif c == '"': | |
newline = newline + '`' | |
continue | |
elif c == "'": | |
in_string = False | |
newline = newline + c | |
return newline | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment