
这是一个python插件,基于Shalmanese的答案和Alex martelli在翻译Perl到Python的一些帮助我正在制做社区维基mysql sqlite3mysql sqlite3,所以请随意编辑和闭环,只要它不会破坏系统(谢天谢地我们可以回滚) - 这很难看还是很有效像如此使用(假设脚本被读取dump_for_mysql。py:sqlite3 sample。db 。dump | python dump_for_mysql。py > dump。sql然后你可以导出到mysql中提醒 - 您需要手动添加外键约束,因为sqlite实际上不支持这些这是插件:#!/usr/bin/env pythonimport reimport fileinputdef this_line_is_useless(line): useless_es = [ 'BEGIN TRANSACTION', 'COMMIT', 'sqlite_sequence', 'CREATE UNIQUE INDEX', 'PRAGMA foreign_keys=OFF', ] for useless in useless_es: if re。
search(useless, line): return Truedef has_primary_key(line): return bool(re。search(r'PRIMARY KEY', line))searching_for_end = Falsefor line in fileinput。input(): if this_line_is_useless(line): continue # this line was necessary because ''); # would be converted to \'); which isn't appropriate if re。

match(r"。*, ''\);", line): line = re。sub(r"''\);", r'``);', line) if re。match(r'^CREATE TABLE。*', line): searching_for_end = True m = re。
search('CREATE TABLE "?(\w*)"?(。*)', line) if m: name, sub = m。groups() line = "DROP TABLE IF EXISTS %(name)s;\nCREATE TABLE IF NOT EXISTS `%(name)s`%(sub)s\n" line = line % dict(name=name, sub=sub) else: m = re。
search('INSERT INTO "(\w*)"(。*)', line) if m: line = 'INSERT INTO %s%s\n' % m。groups() line = line。
replace('"', r'\"') line = line。replace('"', "'") line = re。sub(r"([^'])'t'(。)", "\1THIS_IS_TRUE\2", line) line = line。replace('THIS_IS_TRUE', '1') line = re。
![]()
sub(r"([^'])'f'(。)", "\1THIS_IS_FALSE\2", line) line = line。replace('THIS_IS_FALSE', '') # Add auto_increment if it is not there since sqlite auto_increments ALL # primary keys if searching_for_end: if re。
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-119390-1.html
维持在中东的强大军事存在
600万
就喝