From 3535dc1b027d0991646be588bec2de518bca437d Mon Sep 17 00:00:00 2001 From: Charlie Duso Date: Tue, 28 Jun 2016 23:46:54 -0700 Subject: [PATCH] Added function to merge tables --- mergeScript.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/mergeScript.py b/mergeScript.py index 17a05af..47063fa 100644 --- a/mergeScript.py +++ b/mergeScript.py @@ -55,7 +55,8 @@ def getColumnNames( tableName ): temp = curs.fetchall() columns = [] for i in range(0, len(temp)): - if ((("id" in temp[i][1]) | ("ID" in temp[i][1])) & ("INTEGER" in temp[i][2])): + if ((("id" in temp[i][1]) | ("ID" in temp[i][1])) & ( \ + "INTEGER" in temp[i][2])): continue else: columns.append(temp[i][1]) @@ -65,7 +66,7 @@ def getColumnNames( tableName ): # # @param list1 the first list parameter for comparison # @param list2 the second list parameter for comparison -# @return will return a boolean (0 if lists are not the same, 1 if lists are the same) +# @return will return a boolean (0 lists !=, 1 lists ==) def compareLists(list1, list2): if len(list1) != len(list2): return 0 @@ -75,6 +76,19 @@ def compareLists(list1, list2): return 0 return 1 +# Merges a table from an attached database to the source table +# +# @param tableName the name of the table to merge +# @param columnNames the names of the columns to include in the merge +# @param dbNameTableName the name of the attached database and the table +# i.e. "databaseName.tableName" +# @return none +def mergeTable(tableName, columnNames, dbNameTableName): + curs.execute("INSERT INTO %s (%s) SELECT %s FROM %s;" % + (tableName, columnNames, columnNames, dbNameTableName)) + conn.commit() + + ############################## Merge Script #################################### ################################################################################