Created
July 4, 2014 20:56
-
-
Save chintanop/d0c189c2eebd34ce6b68 to your computer and use it in GitHub Desktop.
Revisions
-
chintanop revised this gist
Jul 4, 2014 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -15,8 +15,6 @@ def copy_table(self, table_name, source_conn, target_conn): "INSERT into "+table_name+"( "+columns+" ) " "values ("+values_q+")" ) qdict = {} for indx, row_val in enumerate(row): qdict["key"+str(indx)] = row_val -
chintanop created this gist
Jul 4, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ def copy_table(self, table_name, source_conn, target_conn): """ copies all records from table_name from source to target db """ scursor = source_conn.cursor() tcursor = target_conn.cursor() scursor.execute("SELECT * from "+table_name) desc = scursor.description columns = ",".join([col[0] for col in desc]) values_q = ",".join(["%(key"+str(indx)+")s" for indx, col in enumerate(desc)]) for row in scursor.fetchall(): insrt_sql = ( "INSERT into "+table_name+"( "+columns+" ) " "values ("+values_q+")" ) print insrt_sql print row qdict = {} for indx, row_val in enumerate(row): qdict["key"+str(indx)] = row_val tcursor.execute(insrt_sql, qdict)