diff SMART/Java/Python/mySql/MySqlConnection.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/MySqlConnection.py	Mon Apr 22 11:11:10 2013 -0400
+++ b/SMART/Java/Python/mySql/MySqlConnection.py	Mon Apr 29 03:20:15 2013 -0400
@@ -39,7 +39,7 @@
 
     def __init__(self, verbosity = 0):
         self.verbosity = verbosity
-        self.databaseName = "%s%ssmartdb%d" % (os.environ.get("SMARTTMPPATH", "."), os.sep, random.randint(0, 100000))
+        self.databaseName = os.path.join(os.environ.get("SMARTTMPPATH", "."), "smartdb%d" % random.randint(0, 100000))
         self.connection = sqlite3.connect(self.databaseName)
         self.executeQuery("PRAGMA journal_mode = OFF")
         self.executeQuery("PRAGMA synchronous = 0")
@@ -88,6 +88,18 @@
             self.connection.commit()
 
 
+    def executeManyFormattedQueries(self, command, lines, insertion = False):
+        cursor = self.connection.cursor()
+        query = MySqlQuery(cursor, self.verbosity)
+        for line in lines:
+            result = query.executeFormat(command, line)
+        self.connection.commit()
+        if insertion:
+            return result
+        else:
+            return query
+
+
     def executeManyQueriesIterator(self, table):
         cursor = self.connection.cursor()
         query = MySqlQuery(cursor, self.verbosity)
@@ -101,9 +113,25 @@
             self.connection.commit()
 
 
-    def executeFormattedQuery(self, command, *parameters):
+    def executeManyFormattedQueriesIterator(self, table):
         cursor = self.connection.cursor()
         query = MySqlQuery(cursor, self.verbosity)
-        query.executeFormat(command, parameters)
+        try:
+            for command, values in table.getIterator():
+                query.executeFormat(command, values)
+            self.connection.commit()
+        except:
+            for command, values in table.getIterator():
+                query.execute(command, values)
+            self.connection.commit()
+
+
+    def executeFormattedQuery(self, command, parameters, insertion = False):
+        cursor = self.connection.cursor()
+        query = MySqlQuery(cursor, self.verbosity)
+        result = query.executeFormat(command, parameters)
         self.connection.commit()
-        return query
+        if insertion:
+            return result
+        else:
+            return query
\ No newline at end of file