Parcourir la source

SQLite to MySQL 도구 추가

잉여개발기 (SPDV) il y a 2 ans
Parent
commit
497bd9ff01
2 fichiers modifiés avec 27 ajouts et 3 suppressions
  1. 24 1
      emergency_tool.py
  2. 3 2
      route/tool/func.py

+ 24 - 1
emergency_tool.py

@@ -52,6 +52,7 @@ print('20. Change domain')
 print('21. Change TLS')
 print('22. Delete body top')
 print('23. Delete body bottom')
+print('24. SQLite to MySQL')
 
 print('----')
 what_i_do = input('Select : ')
@@ -256,11 +257,33 @@ elif what_i_do == '22':
     curs.execute(db_change('delete from other where name = "body"'))
 elif what_i_do == '23':
     curs.execute(db_change('delete from other where name = "bottom_body"'))
+elif what_i_do == '24':
+    load_db = get_db_connect('mysql')
+    mysql_conn = load_db.__enter__()
+    mysql_curs = mysql_conn.cursor()
+    
+    load_db = get_db_connect('sqlite')
+    sqlite_conn = load_db.__enter__()
+    sqlite_curs = sqlite_conn.cursor()
+
+    create_data = get_db_table_list()
+    for create_table in create_data:
+        create = ['test'] + create_data[create_table]
+        create_r = ', '.join(['?' for _ in create])
+        create = ', '.join(create)
+        
+        print('select ' + create + ' from ' + create_table)
+        sqlite_curs.execute(db_change('select ' + create + ' from ' + create_table))
+        db_data = sqlite_curs.fetchall()
+        mysql_curs.executemany(db_change("insert into " + create_table + " (" + create + ") values (" + create_r + ")"), db_data)
 else:
     raise ValueError(what_i_do)
 
 if data_db_load == 'Y':
-    conn.commit()
+    try:
+        conn.commit()
+    except:
+        pass
 
 print('----')
 print('OK')

+ 3 - 2
route/tool/func.py

@@ -137,10 +137,11 @@ def get_init_set_list(need = 'all'):
         return init_set_list[need]
 
 class get_db_connect:
-    def __init__(self):
+    def __init__(self, db_type = ''):
         global global_db_set
-
         self.db_set = global_db_set
+        if db_type != '':
+           self.db_set['type'] = db_type 
         
     def __enter__(self):
         if self.db_set['type'] == 'sqlite':