[MOBY-guts] biomoby commit

Yan Wong yanwong at pub.open-bio.org
Fri Apr 22 10:13:49 UTC 2005


yanwong
Fri Apr 22 06:13:49 EDT 2005
Update of /home/repository/moby/moby-live/Python/bioMoby/webservice
In directory pub.open-bio.org:/tmp/cvs-serv4018/bioMoby/webservice

Modified Files:
	Dispatcher.py Invocators.py 
Log Message:
added the two classes, a small commented example in the tutorials section and mofication on the documentation

moby-live/Python/bioMoby/webservice Dispatcher.py,1.5,1.6 Invocators.py,1.5,1.6
===================================================================
RCS file: /home/repository/moby/moby-live/Python/bioMoby/webservice/Dispatcher.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- /home/repository/moby/moby-live/Python/bioMoby/webservice/Dispatcher.py	2005/04/19 15:41:50	1.5
+++ /home/repository/moby/moby-live/Python/bioMoby/webservice/Dispatcher.py	2005/04/22 10:13:49	1.6
@@ -521,7 +521,7 @@
 class SQLDispatcher(AbstractDispatcher):
     """ A dispatcher for SQL queries
     """
-    def __init__(self, mobyContentXML, ConnectionObject, sqlCommand, CommandBuilder, formatter):
+    def __init__(self, mobyContentXML, ConnectionObject, sqlCommand, CommandBuilder, formatter, withoutExecuteMany=False):
         """ To instanciate this object, you need:
             a DB Connection (as parameters vary from a DB to another, you must use a python DB api 2 Connection object here)
             the sqlCommand: the sql command as described in the Python DB api
@@ -532,6 +532,7 @@
            
         AbstractDispatcher.__init__(self, mobyContentXML, SQLInvocator, ConnectionObject, CommandBuilder, formatter)
         self._sqlCommand = sqlCommand
+        self._withoutExecuteMany=withoutExecuteMany
     
     def execute(self):
         """ execute the sql command
@@ -539,7 +540,7 @@
         try:
             for key in self.queryData.keys():
                 query=self.queryData[key]
-                r=self.invocator(key, self._sqlCommand, self.commandBuilder(query), self._invocatorParameters)
+                r=self.invocator(key, self._sqlCommand, self.commandBuilder(query), self._invocatorParameters, withoutExecuteMany=self._withoutExecuteMany)
                 r.execute()
                 self.answers[key]=self.formatter(r.results)
         except:

===================================================================
RCS file: /home/repository/moby/moby-live/Python/bioMoby/webservice/Invocators.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- /home/repository/moby/moby-live/Python/bioMoby/webservice/Invocators.py	2005/04/20 09:39:36	1.5
+++ /home/repository/moby/moby-live/Python/bioMoby/webservice/Invocators.py	2005/04/22 10:13:49	1.6
@@ -173,7 +173,7 @@
     """ Invokes SQL commands, 
         you'll need to setup a connection before using ir
     """
-    def __init__(self, queryKey, sqlCommand, sqlParameters, sqlConnection):
+    def __init__(self, queryKey, sqlCommand, sqlParameters, sqlConnection, withoutExecuteMany=False):
         """ the quey of the query, the sql command and its parameters in a tuple
         """
         GeneralInvocator.__init__(self, queryKey)
@@ -181,6 +181,7 @@
         self._sqlCommand = sqlCommand
         self._sqlParameters = sqlParameters
         self._connection = sqlConnection
+        self._withoutExecuteMany=withoutExecuteMany
         
     def setParameters(self, sqlConnection):
         """ Define a connection for this sql command
@@ -192,8 +193,22 @@
         """
         cursor = self._connection.cursor()
         
-        cursor.execute(self._sqlCommand, self._sqlParameters)
-        self.results=cursor.fetchall()
+        #If it is a a list use executemany
+        #else
+        if isinstance(self._sqlParameters, list):
+            if not self._withoutExecuteMany:
+                cursor.executemany(self._sqlCommand, self._sqlParameters)
+                self.results=cursor.fetchall()
+            else:
+                self.results=[]
+
+                for parameter in self._sqlParameters:
+                    cursor.execute(self._sqlCommand, parameter)
+                    self.results+=cursor.fetchall()
+        else:
+            cursor.execute(self._sqlCommand, self._sqlParameters)
+            self.results=cursor.fetchall()
+        
         cursor.close()
         
 




More information about the MOBY-guts mailing list