rdkit.Dbase.DbModule

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

# Source Code for Module rdkit.Dbase.DbModule

     1  # $Id: DbModule.py 997 2009-02-25 06:12:43Z glandrum $
     2  #
     3  # Copyright (C) 2003-2006 Rational Discovery LLC
     4  #
     5  #   @@ All Rights Reserved  @@
     6  #
     7  from rdkit import RDConfig
     8
     9  if hasattr(RDConfig,"usePgSQL") and RDConfig.usePgSQL:
    10    useGvib=0
    11    from pyPgSQL import PgSQL
    12    # as of this writing (March 2004), this results in a speedup in
    13    # getting results back from the wrapper:
    14    PgSQL.fetchReturnsList=1
    15
    16    from pyPgSQL.PgSQL import *
    17    sqlTextTypes = [PG_CHAR,PG_BPCHAR,PG_TEXT,PG_VARCHAR,PG_NAME]
    18    sqlIntTypes = [PG_INT8,PG_INT2,PG_INT4]
    19    sqlFloatTypes = [PG_FLOAT4,PG_FLOAT8]
    20    sqlBinTypes = [PG_OID,PG_BLOB,PG_BYTEA]
    21    getTablesSql = """select tablename from pg_tables where schemaname='public'"""
    22    getTablesAndViewsSql = """SELECT c.relname as "Name"
    23    FROM pg_catalog.pg_class c
    24    LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner
    25    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
    26    WHERE c.relkind IN ('r','v','S','')
    27    AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
    28    AND pg_catalog.pg_table_is_visible(c.oid)
    29
    30    """
    31    getDbSql = """ select datname from pg_database where datallowconn """
    32    fileWildcard=None
    33    placeHolder='%s'
    34    binaryTypeName="bytea"
    35    binaryHolder = PgBytea
    36    RDTestDatabase="::RDTests"
    37  elif hasattr(RDConfig,"useSqlLite") and RDConfig.useSqlLite:
    38    useGvib=0
    39    try:
    40      import sqlite3 as sqlite
    41      #from sqlite3 import *
    42    except ImportError:
    43      from pysqlite2 import dbapi2 as sqlite
    44      #from pysqlite2 import *
    45    sqlTextTypes = []
    46    sqlIntTypes = []
    47    sqlFloatTypes = []
    48    sqlBinTypes = []
    49    getTablesSql = """select name from SQLite_Master where type='table'"""
    50    getTablesAndViewsSql = """select name from SQLite_Master where type in ('table','view')"""
    51    getDbSql = None
    52    dbFileWildcard='*.sqlt'
    53    placeHolder='?'
    54    binaryTypeName="blob"
    55    binaryHolder = buffer
    56
    57    connect = lambda x,*args:sqlite.connect(x)
    58  else:
    59    useGvib=1
    60    from gvib import *
    61    sqlTextTypes = [gvibTypes.SQL_TEXT,gvibTypes.SQL_VARYING]
    62    sqlIntTypes = [gvibTypes.SQL_SHORT,gvibTypes.SQL_LONG,
    63                   gvibTypes.SQL_INT64]
    64    sqlFloatTypes = [gvibTypes.SQL_FLOAT,gvibTypes.SQL_DOUBLE,
    65                     gvibTypes.SQL_D_FLOAT]
    66    sqlBinTypes = [gvibTypes.SQL_BLOB,gvibTypes.SQL_ARRAY]
    67    getTablesSql = """SELECT RDB$RELATION_NAME
    68      FROM RDB$RELATIONS
    69      WHERE ((RDB$SYSTEM_FLAG = 0) OR
    70      (RDB$SYSTEM_FLAG IS NULL)) AND
    71      (RDB$VIEW_SOURCE IS NULL)
    72      ORDER BY RDB$RELATION_NAME"""
    73    getTablesAndViewsSql="""SELECT RDB$RELATION_NAME
    74        FROM RDB$RELATIONS
    75        WHERE ((RDB$SYSTEM_FLAG = 0) OR
    76        (RDB$SYSTEM_FLAG IS NULL))
    77        ORDER BY RDB$RELATION_NAME"""
    78    getDbSql = None
    79    dbFileWildcard='*.gdb'
    80    placeHolder='?'
    81    binaryTypeName="blob"
    82    binaryHolder = lambda x:x
    83