Package rdkit :: Package Dbase :: Module DbModule
[hide private]
[frames] | no frames]

Source Code for Module rdkit.Dbase.DbModule

 1  # $Id$ 
 2  # 
 3  # Copyright (C) 2003-2006 Rational Discovery LLC 
 4  # 
 5  #   @@ All Rights Reserved @@ 
 6  #  This file is part of the RDKit. 
 7  #  The contents are covered by the terms of the BSD license 
 8  #  which is included in the file license.txt, found at the root 
 9  #  of the RDKit source tree. 
10  # 
11  from rdkit import six 
12  from rdkit import RDConfig 
13   
14  if hasattr(RDConfig, "usePgSQL") and RDConfig.usePgSQL: 
15    from pyPgSQL import PgSQL 
16    # as of this writing (March 2004), this results in a speedup in 
17    # getting results back from the wrapper: 
18    PgSQL.fetchReturnsList = 1 
19   
20    from pyPgSQL.PgSQL import * 
21    sqlTextTypes = [PG_CHAR, PG_BPCHAR, PG_TEXT, PG_VARCHAR, PG_NAME] 
22    sqlIntTypes = [PG_INT8, PG_INT2, PG_INT4] 
23    sqlFloatTypes = [PG_FLOAT4, PG_FLOAT8] 
24    sqlBinTypes = [PG_OID, PG_BLOB, PG_BYTEA] 
25    getTablesSql = """select tablename from pg_tables where schemaname='public'""" 
26    getTablesAndViewsSql = """SELECT c.relname as "Name" 
27    FROM pg_catalog.pg_class c 
28    LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner 
29    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace 
30    WHERE c.relkind IN ('r','v','S','') 
31    AND n.nspname NOT IN ('pg_catalog', 'pg_toast') 
32    AND pg_catalog.pg_table_is_visible(c.oid) 
33   
34    """ 
35    getDbSql = """ select datname from pg_database where datallowconn """ 
36    fileWildcard = None 
37    placeHolder = '%s' 
38    binaryTypeName = "bytea" 
39    binaryHolder = PgBytea 
40    RDTestDatabase = "::RDTests" 
41  elif hasattr(RDConfig, "useSqlLite") and RDConfig.useSqlLite: 
42    try: 
43      import sqlite3 as sqlite 
44    except ImportError: 
45      from pysqlite2 import dbapi2 as sqlite 
46    sqlTextTypes = [] 
47    sqlIntTypes = [] 
48    sqlFloatTypes = [] 
49    sqlBinTypes = [] 
50    getTablesSql = """select name from SQLite_Master where type='table'""" 
51    getTablesAndViewsSql = """select name from SQLite_Master where type in ('table','view')""" 
52    getDbSql = None 
53    dbFileWildcard = '*.sqlt' 
54    fileWildcard = dbFileWildcard 
55    placeHolder = '?' 
56    binaryTypeName = "blob" 
57    binaryHolder = memoryview if six.PY3 else buffer 
58   
59 - def connect(x, *args):
60 return sqlite.connect(x)
61 else: 62 raise ImportError("Neither sqlite nor PgSQL support found.") 63