diff SMART/Java/Python/mySql/MySqlTable.py @ 18:94ab73e8a190

Uploaded
author m-zytnicki
date Mon, 29 Apr 2013 03:20:15 -0400
parents 769e306b7933
children
line wrap: on
line diff
--- a/SMART/Java/Python/mySql/MySqlTable.py	Mon Apr 22 11:11:10 2013 -0400
+++ b/SMART/Java/Python/mySql/MySqlTable.py	Mon Apr 29 03:20:15 2013 -0400
@@ -116,6 +116,18 @@
         self.mySqlConnection.executeManyQueries(commands)
         
         
+    def insertManyFormatted(self, lines):
+        """
+        Insert many lines
+        @param lines: the list of values
+        @type  lines: list of lists
+        """
+        replacer = ["?"] * len(self.variables)
+        command = "INSERT INTO '%s' (%s) VALUES (%s)" % (self.name, ", ".join(self.variables), ", ".join(replacer))
+        values  = [[line[variable] for variable in self.variables] for line in lines]
+        self.mySqlConnection.executeManyFormattedQueries(command, values)
+        
+        
     def rename(self, name):
         """
         Rename the table
@@ -217,6 +229,10 @@
         @type  values: dict
         @return:       the id of the added row
         """
+        sqlValues = [values[variable] for variable in self.variables]
+        command = "INSERT INTO '%s' (%%s) VALUES (%s)" % (self.name, ", ".join(self.variables))
+        id = self.mySqlConnection.executeFormattedQueryQuery(command, sqlValues, True)
+        return id
         sqlValues = []
         for variable in self.variables:
             sqlValues.append(self.formatSql(values[variable], self.types[variable], self.sizes[variable]))
@@ -331,4 +347,3 @@
         query = self.mySqlConnection.executeQuery("SELECT * FROM '%s'" % (self.name))
         print query.getLines()
 
-