本文整理汇总了Python中sqlobject.dbconnection.DBAPI类的典型用法代码示例。如果您正苦于以下问题:Python DBAPI类的具体用法?Python DBAPI怎么用?Python DBAPI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBAPI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, db, user, password='', host='localhost', port=0, **kw):
global MySQLdb
if MySQLdb is None:
import MySQLdb, MySQLdb.constants.CR, MySQLdb.constants.ER
self.module = MySQLdb
self.host = host
self.port = port
self.db = db
self.user = user
self.password = password
self.kw = {}
for key in ("unix_socket", "init_command",
"read_default_file", "read_default_group", "conv"):
if key in kw:
self.kw[key] = kw.pop(key)
for key in ("connect_timeout", "compress", "named_pipe", "use_unicode",
"client_flag", "local_infile"):
if key in kw:
self.kw[key] = int(kw.pop(key))
for key in ("ssl_key", "ssl_cert", "ssl_ca", "ssl_capath"):
if key in kw:
if "ssl" not in self.kw:
self.kw["ssl"] = {}
self.kw["ssl"][key[4:]] = kw.pop(key)
if "charset" in kw:
self.dbEncoding = self.kw["charset"] = kw.pop("charset")
else:
self.dbEncoding = None
if "sqlobject_encoding" in kw:
del kw["sqlobject_encoding"]
deprecated("sqlobject_encoding is deprecated and no longer used.")
DBAPI.__init__(self, **kw)
示例2: __init__
def __init__(self, host, db, port='3050', user='sysdba',
password='masterkey', autoCommit=1,
dialect=None, role=None, charset=None, **kw):
global kinterbasdb
if kinterbasdb is None:
import kinterbasdb
# See http://kinterbasdb.sourceforge.net/dist_docs/usage.html
# for an explanation; in short: use datetime, decimal and unicode.
kinterbasdb.init(type_conv=200)
self.module = kinterbasdb
self.host = host
self.port = port
self.db = db
self.user = user
self.password = password
if dialect:
self.dialect = int(dialect)
else:
self.dialect = None
self.role = role
if charset:
self.dbEncoding = charset.replace('-', '') # encoding defined by user in the connection string
else:
self.dbEncoding = charset
self.defaultDbEncoding = '' # encoding defined during database creation and stored in the database
DBAPI.__init__(self, **kw)
示例3: __init__
def __init__(self, host, db, user='sysdba',
passwd='masterkey', autoCommit=1,
dialect=None, role=None, charset=None, **kw):
global kinterbasdb
if kinterbasdb is None:
import kinterbasdb
self.module = kinterbasdb
self.limit_re = re.compile('^\s*(select )(.*)', re.IGNORECASE)
if not autoCommit and not kw.has_key('pool'):
# Pooling doesn't work with transactions...
kw['pool'] = 0
self.host = host
self.db = db
self.user = user
self.passwd = passwd
if dialect:
self.dialect = int(dialect)
else:
self.dialect = None
self.role = role
self.charset = charset
DBAPI.__init__(self, **kw)
示例4: __init__
def __init__(self, db, user, password="", host="localhost", port=0, **kw):
import MySQLdb, MySQLdb.constants.CR, MySQLdb.constants.ER
self.module = MySQLdb
self.host = host
self.port = port
self.db = db
self.user = user
self.password = password
self.kw = {}
for key in ("unix_socket", "init_command", "read_default_file", "read_default_group", "conv"):
if key in kw:
self.kw[key] = kw.pop(key)
for key in ("connect_timeout", "compress", "named_pipe", "use_unicode", "client_flag", "local_infile"):
if key in kw:
self.kw[key] = int(kw.pop(key))
for key in ("ssl_key", "ssl_cert", "ssl_ca", "ssl_capath"):
if key in kw:
if "ssl" not in self.kw:
self.kw["ssl"] = {}
self.kw["ssl"][key[4:]] = kw.pop(key)
if "charset" in kw:
self.dbEncoding = self.kw["charset"] = kw.pop("charset")
else:
self.dbEncoding = None
# MySQLdb < 1.2.1: only ascii
# MySQLdb = 1.2.1: only unicode
# MySQLdb > 1.2.1: both ascii and unicode
self.need_unicode = (self.module.version_info[:3] >= (1, 2, 1)) and (self.module.version_info[:3] < (1, 2, 2))
DBAPI.__init__(self, **kw)
示例5: __init__
def __init__(self, db, user, password='', host='localhost', port=0, **kw):
global MySQLdb
if MySQLdb is None:
import MySQLdb, MySQLdb.constants.CR, MySQLdb.constants.ER
self.module = MySQLdb
self.host = host
self.port = port
self.db = db
self.user = user
self.password = password
self.kw = {}
if MySQLdb.version_info[:3] >= (1, 2, 1):
self.need_unicode = True
else:
self.need_unicode = False
for key in ("unix_socket", "init_command",
"read_default_file", "read_default_group", "conv"):
if key in kw:
self.kw[key] = col.popKey(kw, key)
for key in ("connect_timeout", "compress", "named_pipe", "use_unicode",
"client_flag", "local_infile"):
if key in kw:
self.kw[key] = int(col.popKey(kw, key))
if "charset" in kw:
self.dbEncoding = self.kw["charset"] = col.popKey(kw, "charset")
else:
self.dbEncoding = None
if "sqlobject_encoding" in kw:
self.encoding = col.popKey(kw, "sqlobject_encoding")
else:
self.encoding = 'ascii'
DBAPI.__init__(self, **kw)
示例6: __init__
def __init__(self, dsn=None, host=None, db=None,
user=None, passwd=None, usePygresql=False,
**kw):
global psycopg, pgdb
if usePygresql:
if pgdb is None:
import pgdb
self.module = pgdb
else:
if psycopg is None:
import psycopg
self.module = psycopg
# Register a converter for psycopg Binary type.
registerConverter(type(psycopg.Binary('')),
PsycoBinaryConverter)
if dsn is None:
dsn = []
if db:
dsn.append('dbname=%s' % db)
if user:
dsn.append('user=%s' % user)
if passwd:
dsn.append('password=%s' % passwd)
if host:
# @@: right format?
dsn.append('host=%s' % host)
dsn = ' '.join(dsn)
self.dsn = dsn
DBAPI.__init__(self, **kw)
# Server version cache
self._server_version = None # Not yet initialized
示例7: __init__
def __init__(self, db, user, passwd='', host='localhost', **kw):
global MySQLdb
if MySQLdb is None:
import MySQLdb
self.module = MySQLdb
self.host = host
self.db = db
self.user = user
self.password = passwd
DBAPI.__init__(self, **kw)
示例8: releaseConnection
def releaseConnection(self, conn, explicit=False):
if self._memory:
return
threadid = self._threadOrigination.get(id(conn))
DBAPI.releaseConnection(self, conn, explicit=explicit)
if (self._pool is not None and threadid
and threadid not in self._threadPool):
self._threadPool[threadid] = conn
else:
if self._pool and conn in self._pool:
self._pool.remove(conn)
conn.close()
示例9: __init__
def __init__(self, host, db, port='3050', user='sysdba',
password='masterkey', autoCommit=1,
dialect=None, role=None, charset=None, **kw):
drivers = kw.pop('driver', None) or 'fdb,kinterbasdb'
for driver in drivers.split(','):
driver = driver.strip()
if not driver:
continue
try:
if driver == 'fdb':
import fdb
self.module = fdb
elif driver == 'kinterbasdb':
import kinterbasdb
# See
# http://kinterbasdb.sourceforge.net/dist_docs/usage.html
# for an explanation; in short: use datetime, decimal and
# unicode.
kinterbasdb.init(type_conv=200)
self.module = kinterbasdb
elif driver in ('firebirdsql', 'pyfirebirdsql'):
import firebirdsql
self.module = firebirdsql
else:
raise ValueError(
'Unknown FireBird driver "%s", '
'expected fdb, kinterbasdb or firebirdsql' % driver)
except ImportError:
pass
else:
break
else:
raise ImportError(
'Cannot find an FireBird driver, tried %s' % drivers)
self.host = host
self.port = port
self.db = db
self.user = user
self.password = password
if dialect:
self.dialect = int(dialect)
else:
self.dialect = None
self.role = role
if charset:
# Encoding defined by user in the connection string.
self.dbEncoding = charset.replace('-', '')
else:
self.dbEncoding = charset
# Encoding defined during database creation and stored in the database.
self.defaultDbEncoding = ''
DBAPI.__init__(self, **kw)
示例10: __init__
def __init__(self, db, user, password='', host='localhost',
autoCommit=0, **kw):
global sqlmodule
if not sqlmodule:
try:
import adodbapi as sqlmodule
except ImportError:
import pymssql as sqlmodule
if sqlmodule.__name__ == 'adodbapi':
import adodbapi as sqlmodule
self.dbconnection = sqlmodule.connect
# ADO uses unicode only (AFAIK)
self.usingUnicodeStrings = True
# Need to use SQLNCLI provider for SQL Server Express Edition
if kw.get("ncli"):
conn_str = "Provider=SQLNCLI;"
else:
conn_str = "Provider=SQLOLEDB;"
conn_str += "Data Source=%s;Initial Catalog=%s;"
# MSDE does not allow SQL server login
if kw.get("sspi"):
conn_str += "Integrated Security=SSPI;Persist Security Info=False"
self.make_conn_str = lambda keys: [conn_str % (keys.host, keys.db)]
else:
conn_str += "User Id=%s;Password=%s"
self.make_conn_str = lambda keys: [conn_str % (keys.host, keys.db, keys.user, keys.password)]
kw.pop("sspi", None)
kw.pop("ncli", None)
else: # pymssql
self.dbconnection = sqlmodule.connect
sqlmodule.Binary = lambda st: str(st)
# don't know whether pymssql uses unicode
self.usingUnicodeStrings = False
self.make_conn_str = lambda keys: \
["", keys.user, keys.password, keys.host, keys.db]
self.autoCommit=int(autoCommit)
self.host = host
self.db = db
self.user = user
self.password = password
self.limit_re = re.compile('^\s*(select )(.*)', re.IGNORECASE)
self.password = password
self.module = sqlmodule
self._can_use_max_types = None
DBAPI.__init__(self, **kw)
示例11: __init__
def __init__(self, host='', port=None, user=None, password=None,
database=None, autoCommit=1, sqlmode='internal',
isolation=None, timeout=None, **kw):
from sapdb import dbapi
self.module = dbapi
self.host = host
self.port = port
self.user = user
self.password = password
self.db = database
self.autoCommit = autoCommit
self.sqlmode = sqlmode
self.isolation = isolation
self.timeout = timeout
DBAPI.__init__(self, **kw)
示例12: _insertSQL
def _insertSQL(self, table, names, values):
if not names:
assert not values
# INSERT INTO table () VALUES () isn't allowed in
# SQLite (though it is in other databases)
return ("INSERT INTO %s VALUES (NULL)" % table)
else:
return DBAPI._insertSQL(self, table, names, values)
示例13: __init__
def __init__(self, dsn=None, host=None, port=None, db=None,
user=None, password=None, unicodeCols=False, **kw):
from rdbhdb import rdbhdb as rdb
# monkey patch % escaping into Cursor._execute
old_execute = getattr(rdb.Cursor, '_execute')
setattr(rdb.Cursor, '_old_execute', old_execute)
def _execute(self, query, *args):
assert not any([a for a in args])
query = query.replace('%', '%%')
self._old_execute(query, (), (), ())
setattr(rdb.Cursor, '_execute', _execute)
self.module = rdb
self.user = user
self.host = host
self.port = port
self.db = db
self.password = password
self.dsn_dict = dsn_dict = {}
self.use_dsn = dsn is not None
if host:
dsn_dict["host"] = host
if user:
dsn_dict["role"] = user
if password:
dsn_dict["authcode"] = password
if dsn is None:
dsn = []
if db:
dsn.append('dbname=%s' % db)
if user:
dsn.append('user=%s' % user)
if password:
dsn.append('password=%s' % password)
if host:
dsn.append('host=%s' % host)
if port:
dsn.append('port=%d' % port)
dsn = ' '.join(dsn)
self.dsn = dsn
self.unicodeCols = unicodeCols
self.schema = kw.pop('schema', None)
self.dbEncoding = 'utf-8'
DBAPI.__init__(self, **kw)
示例14: __init__
def __init__(
self,
host,
db,
port="3050",
user="sysdba",
password="masterkey",
autoCommit=1,
dialect=None,
role=None,
charset=None,
**kw
):
try:
import fdb
self.module = fdb
except ImportError:
import kinterbasdb
# See http://kinterbasdb.sourceforge.net/dist_docs/usage.html
# for an explanation; in short: use datetime, decimal and
# unicode.
kinterbasdb.init(type_conv=200)
self.module = kinterbasdb
self.host = host
self.port = port
self.db = db
self.user = user
self.password = password
if dialect:
self.dialect = int(dialect)
else:
self.dialect = None
self.role = role
if charset:
# Encoding defined by user in the connection string.
self.dbEncoding = charset.replace("-", "")
else:
self.dbEncoding = charset
# Encoding defined during database creation and stored in the database.
self.defaultDbEncoding = ""
DBAPI.__init__(self, **kw)
示例15: __init__
def __init__(self, host, port, db, user='sysdba',
password='masterkey', autoCommit=1,
dialect=None, role=None, charset=None, **kw):
import kinterbasdb
self.module = kinterbasdb
self.host = host
self.port = port
self.db = db
self.user = user
self.password = password
if dialect:
self.dialect = int(dialect)
else:
self.dialect = None
self.role = role
self.charset = charset
DBAPI.__init__(self, **kw)