Package install :: Package MoSTBioDat :: Package DataBase :: Package ForgetSQL2 :: Module PythonicSQL
[hide private]
[frames] | no frames]

Source Code for Module install.MoSTBioDat.DataBase.ForgetSQL2.PythonicSQL

  1  #!/usr/bin/env python 
  2  ############################ 
  3  # PythonicSQL.py:          # 
  4  # Pythonic Query module    # 
  5  ############################ 
  6   
  7  ###################################################### 
  8  # Copyright (c) 2007-2008 Andrzej Bak                # 
  9  # ARC Seibersdorf & University of Silesia            # 
 10  # Author: Andrzej Bak <Andrzej.Bak@us.edu.pl>        # 
 11  # License: GNU General Public License, version: 3    # 
 12  # URL: http://chemoinformatyka.us.edu.pl/mostbiodat/ # 
 13  # Version: 1, 06.01.2010                             # 
 14  ###################################################### 
 15   
 16  try: 
 17      from forgetsql2 import * 
 18      import MySQLdb 
 19      from MoSTBioDat.DataBase.Connect.MoSTBioDatDB import MoSTBioDatDB,filterKeys 
 20  except ImportError,e: 
 21      print 'Error: %s' %e 
 22      sys.exit(1) 
 23   
 24  ############### PythonicSQL class #################### 
25 -class PythonicSQL(MoSTBioDatDB):
26 """ 27 INPUT: 28 host - string, host to connect 29 user - string, user to connect as 30 passwd - string, password to use 31 db - string, database to use 32 port - integer, TCP/IP port to connect to 33 unix_socket - string, location of unix_socket to use 34 conv - conversion dictionary, see MySQLdb.converters 35 connect_timeout - number of seconds to wait before the connection attempt fails. 36 compress - if set, compression is enabled 37 named_pipe - if set, a named pipe is used to connect (Windows only) 38 init_command - command which is run once the connection is created 39 read_default_file - file from which default client values are read 40 read_default_group - configuration group to use from the default file 41 cursorclass - class object, used to create cursors (keyword only) 42 use_unicode - if True, text-like columns are returned as unicode objects 43 using the connection's character set. Otherwise, text-like 44 columns are returned as strings. columns are returned as 45 normal strings. Unicode objects will always be encoded to 46 the connection's character set regardless of this setting. 47 charset - if supplied, the connection character set will be changed 48 to this character set (MySQL-4.1 and newer). This implies 49 use_unicode=True. 50 sql_mode - if supplied, the session SQL mode will be changed to this 51 setting (MySQL-4.1 and newer). For more details and legal 52 values, see the MySQL documentation. 53 client_flag - integer, flags to use or 0 54 (see MySQL docs or constants/CLIENTS.py) 55 ssl - dictionary or mapping, contains SSL connection parameters; 56 see the MySQL documentation for more details 57 (mysql_ssl_set()). If this is set, and the client does not 58 support SSL, NotSupportedError will be raised. 59 local_infile - integer, non-zero enables LOAD LOCAL INFILE; zero disables 60 format - string format for log handler 61 filter - filter object from logger object 62 datefmt - data/time format 63 path - directory path to log file 64 filename - log file name, default log 65 filemode - mode to open log file, default='a' 66 level - set root logger level to specified level 67 logfilelevel- set level to log file 68 cache - create cache for query, default=True 69 OUTPUT: 70 class object 71 """
72 - def __init__(self,host='localhost',db='Ligand',user=None,passwd=None,port=3306,**kwargs):
73 MoSTBioDatDB.__init__(self,host,db,user,passwd,port,cache=False,**kwargs) 74 keys=("conv","quote_conv","cursorclass", 75 "connect_timeout","compress", 76 "named_pipe","init_command", 77 "read_default_file", "read_default_group", 78 "unix_socket", "use_unicode","client_flag", 79 "sql_mode","ssl","local_infile","passwd","db","host","user","port") 80 filter(lambda key: filterKeys(self.kwargs,keys,key),self.kwargs.keys())
81 ###filter input keys
82 - def genTable(self):
83 """ 84 generate table object from database 85 INPUT: 86 class object 87 OUTPUT: 88 funtion result forgetsql2.generate 89 """ 90 return generate(db_module=MySQLdb,connect_info=self.kwargs,log=self.log)
91 ################################ End of class ################################### 92 ################## MAIN ######################################################### 93 ######## Example of usage ################################################################ 94 if __name__=='__main__': 95 pass 96 # A=PythonicSQL(host='',user='',passwd='', 97 # db='',path='/tmp/Log',filename='PySQL') 98 # db=A.genTable() 99 # ## REMARK: Changes table name: Capital letter+rest lower case letters 100 # for compound in db.Chemcomp: 101 # print compound.Id, compound.IsoSmi 102 ### TABLE INSERTION 103 # compound=db.Chemcomp(Id=2) 104 # user.user_name="user nr:10" 105 # user.save() 106