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# 11from rdkit import RDConfig 12 13if hasattr(RDConfig, "usePgSQL") and RDConfig.usePgSQL: 14 from pyPgSQL import PgSQL 15 # as of this writing (March 2004), this results in a speedup in 16 # getting results back from the wrapper: 17 PgSQL.fetchReturnsList = 1 18 19 from pyPgSQL.PgSQL import * 20 sqlTextTypes = [PG_CHAR, PG_BPCHAR, PG_TEXT, PG_VARCHAR, PG_NAME] 21 sqlIntTypes = [PG_INT8, PG_INT2, PG_INT4] 22 sqlFloatTypes = [PG_FLOAT4, PG_FLOAT8] 23 sqlBinTypes = [PG_OID, PG_BLOB, PG_BYTEA] 24 getTablesSql = """select tablename from pg_tables where schemaname='public'""" 25 getTablesAndViewsSql = """SELECT c.relname as "Name" 26 FROM pg_catalog.pg_class c 27 LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner 28 LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace 29 WHERE c.relkind IN ('r','v','S','') 30 AND n.nspname NOT IN ('pg_catalog', 'pg_toast') 31 AND pg_catalog.pg_table_is_visible(c.oid) 32 33 """ 34 getDbSql = """ select datname from pg_database where datallowconn """ 35 fileWildcard = None 36 placeHolder = '%s' 37 binaryTypeName = "bytea" 38 binaryHolder = PgBytea 39 RDTestDatabase = "::RDTests" 40elif hasattr(RDConfig, "useSqlLite") and RDConfig.useSqlLite: 41 try: 42 import sqlite3 as sqlite 43 except ImportError: 44 from pysqlite2 import dbapi2 as sqlite 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 fileWildcard = dbFileWildcard 54 placeHolder = '?' 55 binaryTypeName = "blob" 56 binaryHolder = memoryview 57 58 def connect(x, *args): 59 return sqlite.connect(x) 60else: 61 raise ImportError("Neither sqlite nor PgSQL support found.") 62