Skip to content

Commit

Permalink
Merge pull request #2 from jeesyn/master
Browse files Browse the repository at this point in the history
replace sqlite keywords both upper and lowercase
  • Loading branch information
vwbusguy committed Aug 8, 2017
2 parents 31371e4 + d16132a commit 66efb2f
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions python/sqlite3-to-mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,26 @@
'INSERT INTO "sqlite_sequence"',
]

REPLACEMAP = {"INTEGER PRIMARY KEY": "INTEGER AUTO_INCREMENT PRIMARY KEY",
"AUTOINCREMENT": "AUTO_INCREMENT",
"DEFAULT 't'": "DEFAULT '1'",
"DEFAULT 'f'": "DEFAULT '0'",
",'t'": ",'1'",
",'f'": ",'0'",
}

def _replace_match_allcase(line, src, dst):
line = line.replace(src,dst)
line = line.replace(src.lower(),dst)
return line

def _replace(line):
if any(line.startswith(prefix) for prefix in IGNOREDPREFIXES):
return
line = line.replace("INTEGER PRIMARY KEY", "INTEGER AUTO_INCREMENT PRIMARY KEY")
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'")
for (src,dst) in REPLACEMAP.items():
line = _replace_match_allcase(line, src, dst)
return line


def _backticks(line, in_string):
"""Replace double quotes by backticks outside (multiline) strings
Expand Down

0 comments on commit 66efb2f

Please sign in to comment.