PianaDB
index
../../../../piana/code/PianaDB/PianaDB.py

 File       : PianaDB.py
 Author     : R. Aragues & D. Jaeggi
 Creation   : 2003
 Contents   : class for establishing conexions to pianaDB and handling inserts and selects
 Called from: PianaDBaccess.py
 
=======================================================================================================
 
This a generalization of mysql commands
 
To see how this class is used, look at any method in PianaDBaccess.py

 
Modules
       
MySQLdb
PianaGlobals
sys

 
Classes
       
__builtin__.object
PianaDB

 
class PianaDB(__builtin__.object)
    Class for establishing conexions to pianaDB and handling inserts and selects
 
  Methods defined here:
__getnewargs__(self)
__getstate__(self)
__init__(self, dbname=None, dbhost=None, dbuser=None, dbpassword=None, dbport=None)
"dbname" is the database name to which you want to connect to (required)
 
"dbhost" is the machine with the mysql server that holds the piana database (required)
 
"dbuser" is the mysql user (not required in most systems)
 
"dbpassword" is the mysql password (not required in most systems)
 
"dbport" is the mysql port (not required in most systems)
__setstate__(self, dict)
close(self)
Closes the connection with the database
insert_db_content(self, sql_query, answer_mode=None, buffer=None)
Inserts values into a piana database (connection was established in self.db)
 
Depending on argument "answer_mode", different things are returned.
 
This method is called by PianaDBaccess to then process the results and return them to the user
 
"slq_query" is normally obtained through classes implemented in PianaInsertSQL.py, which have a method get_sqlquery
that creates the sql query needed to retrieve the searched value.
 
"answer_mode" can be one of the following:
 
- None: nothing is returned
- 'last_id' : last id inserted is returned
- 'num_updated' : number of rows that were updated (used by UPDATE statements...)
 
  --> 'last_id' mode only works for those tables that have an auto_increment ID!!!!!!! Will not work with primary keys that are not
      auto_increment. Currently, following tables have auto_increment ids: protein (ID=proteinPiana) and interaction (ID=interactionPiana)
 
"buffer" indicates if this sql_query has to be inserted or not. It can be:
- None: sql_query will be treated as a sql_query and it will be executed (if possible)
- dictionary: the insert has been inserted into the dictionary buffer. So, the sql_query will not be executed. (So, sql_query can be None too. It will be ignored.
select_db_content(self, sql_query=None, answer_mode='single', remove_duplicates='yes', number_of_selected_elems=1)
:        Returns content from a piana database (connection was established in self.db)
        
        "slq_query" is normally obtained through classes implemented in PianaSelectSQL.py, which have a method get_sqlquery
        that creates the sql query needed to retrieve the searched value
        
        "answer_mode" is used to let the user choose what kind of answer he is expecting from the sql query
        answer_mode can take values (default is "single"):
        - "single": just one element (if nothing is found, returns None)
        - "list": a list of single elements (if nothing is found, returns empty list [])
        - "raw":  the raw result from the sql query (a matrix)
        
        "remove_duplicates" is used to let the user decide if the returning list can contain duplicates or not
        (only used when answer_mode="list")
        (this is useful to remove similar entries from one query, for example same uniprot accession numbers returned
        that are actually the same under different swissAccession source DB )
        
        - "yes" will return a list where all elements are unique
        - "no" will return the complete list returned by the sql query
        
        "number_of_selected_elems" sets the number of elements being selected in the sql query.
        - If 1, only the string of the element is returned. 
        - If >1, each group of elements is represented by a tuple (elem1, elem2, ...)
        - if you want to use a number_of_selected_elems higher than 3, you have to modify the code below
        to create keys of the number of elements you wish to select

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'PianaDB' objects>
list of weak references to the object (if defined)

 
Data
        verbose = 0