当前位置: 首页>>代码示例>>Python>>正文


Python pgdb.connect方法代码示例

本文整理汇总了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 
开发者ID:wang502,项目名称:slack-sql,代码行数:16,代码来源:test_tutorial.py

示例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) 
开发者ID:tdda,项目名称:tdda,代码行数:22,代码来源:constraints.py

示例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) 
开发者ID:tdda,项目名称:tdda,代码行数:23,代码来源:drivers.py

示例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) 
开发者ID:tdda,项目名称:tdda,代码行数:11,代码来源:drivers.py

示例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) 
开发者ID:tdda,项目名称:tdda,代码行数:10,代码来源:drivers.py

示例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() 
开发者ID:hhstore,项目名称:annotated-py-webpy,代码行数:16,代码来源:web.py


注:本文中的pgdb.connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。