本文整理匯總了Python中pgdb.connect方法的典型用法代碼示例。如果您正苦於以下問題:Python pgdb.connect方法的具體用法?Python pgdb.connect怎麽用?Python pgdb.connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pgdb
的用法示例。
在下文中一共展示了pgdb.connect方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setUp
# 需要導入模塊: import pgdb [as 別名]
# 或者: from pgdb import connect [as 別名]
def setUp(self):
"""Setup test tables or empty them if they already exist."""
database = dbname
host = '%s:%d' % (dbhost or '', dbport or -1)
con = connect(database=database, host=host)
cur = con.cursor()
cur.execute("set datestyle to 'iso'")
cur.execute("set default_with_oids=false")
cur.execute("set standard_conforming_strings=false")
cur.execute("set client_min_messages=warning")
cur.execute("drop table if exists fruits cascade")
cur.execute("create table fruits(id serial primary key, name varchar)")
cur.close()
self.con = con
示例2: __init__
# 需要導入模塊: import pgdb [as 別名]
# 或者: from pgdb import connect [as 別名]
def __init__(self, dbtype, db, tablename, epsilon=None,
type_checking='strict', testing=False):
"""
Inputs:
*dbtype*:
Type of database.
*db*:
A DB-API database connection object (for example, as
obtained from a call to pgdb.connect() for PostGreSQL
or as a call to MySQLdb.connect() for MySQL).
*tablename*:
A table name, referring to a table that exists in the
database and is accessible. It can either be a simple
name, or a schema-qualified name of the form `schema.name`.
"""
DatabaseConstraintCalculator.__init__(self, tablename, testing)
BaseConstraintVerifier.__init__(self, epsilon=epsilon,
type_checking=type_checking)
DatabaseHandler.__init__(self, dbtype, db)
示例3: database_connection_mysql
# 需要導入模塊: import pgdb [as 別名]
# 或者: from pgdb import connect [as 別名]
def database_connection_mysql(host, port, db, user, password):
if MySQLdb:
# TODO: should provide support for MySQL 'option-files' too.
if host is None:
host = 'localhost'
if port is None:
port = 3306
if user is None:
user = getpass.getuser()
if password:
try:
return MySQLdb.connect(host=host, port=port, db=db,
user=user, password=password)
except:
# some versions of the MySQL driver use different names
return MySQLdb.connect(host=host, port=port, db=db,
username=user, passwd=password)
else:
return MySQLdb.connect(host=host, port=port, db=db, user=user)
else:
print('MySQL driver not available', file=sys.stderr)
示例4: database_connection_postgres
# 需要導入模塊: import pgdb [as 別名]
# 或者: from pgdb import connect [as 別名]
def database_connection_postgres(host, port, db, user, password):
if pgdb:
if port is not None:
host = host + ':' + str(port)
return pgdb.connect(host=host, database=db,
user=user, password=password)
else:
print('PostgreSQL driver not available', file=sys.stderr)
sys.exit(1)
示例5: database_connection_sqlite
# 需要導入模塊: import pgdb [as 別名]
# 或者: from pgdb import connect [as 別名]
def database_connection_sqlite(host, port, db, user, password):
if sqlite3:
conn = sqlite3.connect(db)
conn.create_function('regexp', 2, regex_matcher)
return conn
else:
print('sqlite driver not available', file=sys.stderr)
sys.exit(1)
示例6: load
# 需要導入模塊: import pgdb [as 別名]
# 或者: from pgdb import connect [as 別名]
def load():
"""
Loads a new context for the thread.
You can ask for a function to be run at loadtime by
adding it to the dictionary `loadhooks`.
"""
_context[currentThread()] = Storage()
ctx.status = '200 OK'
ctx.headers = []
if 'db_parameters' in globals():
connect(**db_parameters)
for x in loadhooks.values(): x()