• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python dbapi2.connect函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pysqlcipher3.dbapi2.connect函数的典型用法代码示例。如果您正苦于以下问题:Python connect函数的具体用法?Python connect怎么用?Python connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了connect函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: setUp

    def setUp(self):
        try:
            os.remove(get_db_path())
        except OSError:
            pass

        self.con1 = sqlite.connect(get_db_path(), timeout=0.1)
        self.cur1 = self.con1.cursor()

        self.con2 = sqlite.connect(get_db_path(), timeout=0.1)
        self.cur2 = self.con2.cursor()
开发者ID:bodaay,项目名称:pysqlcipher3,代码行数:11,代码来源:transactions.py


示例2: CheckConnectionExecutemany

 def CheckConnectionExecutemany(self):
     con = sqlite.connect(":memory:")
     con.execute("create table test(foo)")
     con.executemany("insert into test(foo) values (?)", [(3,), (4,)])
     result = con.execute("select foo from test order by foo").fetchall()
     self.assertEqual(result[0][0], 3, "Basic test of Connection.executemany")
     self.assertEqual(result[1][0], 4, "Basic test of Connection.executemany")
开发者ID:bodaay,项目名称:pysqlcipher3,代码行数:7,代码来源:dbapi.py


示例3: CheckCollationIsUsed

    def CheckCollationIsUsed(self):
        if sqlite.version_info < (3, 2, 1):  # old SQLite versions crash on this test
            return
        def mycoll(x, y):
            # reverse order
            return -cmp(x, y)

        con = sqlite.connect(":memory:")
        con.create_collation("mycoll", mycoll)
        sql = """
            select x from (
            select 'a' as x
            union
            select 'b' as x
            union
            select 'c' as x
            ) order by x collate mycoll
            """
        result = con.execute(sql).fetchall()
        if result[0][0] != "c" or result[1][0] != "b" or result[2][0] != "a":
            self.fail("the expected order was not returned")

        con.create_collation("mycoll", None)
        try:
            result = con.execute(sql).fetchall()
            self.fail("should have raised an OperationalError")
        except sqlite.OperationalError, e:
            self.assertEqual(e.args[0].lower(), "no such collation sequence: mycoll")
开发者ID:bodaay,项目名称:pysqlcipher3,代码行数:28,代码来源:hooks.py


示例4: CheckSetIsolationLevel

 def CheckSetIsolationLevel(self):
     """
     See issue 3312.
     """
     con = sqlite.connect(":memory:")
     self.assertRaises(UnicodeEncodeError, setattr, con,
                       "isolation_level", u"\xe9")
开发者ID:bodaay,项目名称:pysqlcipher3,代码行数:7,代码来源:regression.py


示例5: CheckFailedOpen

 def CheckFailedOpen(self):
     YOU_CANNOT_OPEN_THIS = "/foo/bar/bla/23534/mydb.db"
     try:
         con = sqlite.connect(YOU_CANNOT_OPEN_THIS)
     except sqlite.OperationalError:
         return
     self.fail("should have raised an OperationalError")
开发者ID:bodaay,项目名称:pysqlcipher3,代码行数:7,代码来源:dbapi.py


示例6: CheckConvertTimestampMicrosecondPadding

    def CheckConvertTimestampMicrosecondPadding(self):
        """
        http://bugs.python.org/issue14720

        The microsecond parsing of convert_timestamp() should pad with zeros,
        since the microsecond string "456" actually represents "456000".
        """

        con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES)
        cur = con.cursor()
        cur.execute("CREATE TABLE t (x TIMESTAMP)")

        # Microseconds should be 456000
        cur.execute("INSERT INTO t (x) VALUES ('2012-04-04 15:06:00.456')")

        # Microseconds should be truncated to 123456
        cur.execute("INSERT INTO t (x) VALUES ('2012-04-04 15:06:00.123456789')")

        cur.execute("SELECT * FROM t")
        values = [x[0] for x in cur.fetchall()]

        self.assertEqual(values, [
            datetime.datetime(2012, 4, 4, 15, 6, 0, 456000),
            datetime.datetime(2012, 4, 4, 15, 6, 0, 123456),
        ])
开发者ID:bodaay,项目名称:pysqlcipher3,代码行数:25,代码来源:regression.py


示例7: CheckCreateCollationNotAscii

 def CheckCreateCollationNotAscii(self):
     con = sqlite.connect(":memory:")
     try:
         con.create_collation("collä", cmp)
         self.fail("should have raised a ProgrammingError")
     except sqlite.ProgrammingError, e:
         pass
开发者ID:bodaay,项目名称:pysqlcipher3,代码行数:7,代码来源:hooks.py


示例8: CheckCreateCollationNotCallable

 def CheckCreateCollationNotCallable(self):
     con = sqlite.connect(":memory:")
     try:
         con.create_collation("X", 42)
         self.fail("should have raised a TypeError")
     except TypeError, e:
         self.assertEqual(e.args[0], "parameter must be callable")
开发者ID:bodaay,项目名称:pysqlcipher3,代码行数:7,代码来源:hooks.py


示例9: CheckNullCharacter

 def CheckNullCharacter(self):
     # Issue #21147
     con = sqlite.connect(":memory:")
     self.assertRaises(ValueError, con, "\0select 1")
     self.assertRaises(ValueError, con, "select 1\0")
     cur = con.cursor()
     self.assertRaises(ValueError, cur.execute, " \0select 2")
     self.assertRaises(ValueError, cur.execute, "select 2\0")
开发者ID:bodaay,项目名称:pysqlcipher3,代码行数:8,代码来源:regression.py


示例10: setUp

 def setUp(self):
     self.con = sqlite.connect(":memory:")
     try:
         del sqlite.adapters[int]
     except:
         pass
     sqlite.register_adapter(int, ObjectAdaptationTests.cast)
     self.cur = self.con.cursor()
开发者ID:bodaay,项目名称:pysqlcipher3,代码行数:8,代码来源:types.py


示例11: createDatabase

 def createDatabase(self, encrypt=True):
     conn = sqlite.connect(self.db)
     if encrypt:
         self.setPassword(conn, self.password)
     conn.execute('create table tbl(col text)')
     conn.execute("insert into tbl values('data')")
     conn.commit()
     conn.close()
开发者ID:bodaay,项目名称:pysqlcipher3,代码行数:8,代码来源:sqlcipher.py


示例12: CheckScriptSyntaxError

 def CheckScriptSyntaxError(self):
     con = sqlite.connect(":memory:")
     cur = con.cursor()
     raised = False
     try:
         cur.executescript("create table test(x); asdf; create table test2(x)")
     except sqlite.OperationalError:
         raised = True
     self.assertEqual(raised, True, "should have raised an exception")
开发者ID:bodaay,项目名称:pysqlcipher3,代码行数:9,代码来源:dbapi.py


示例13: CheckPragmaSchemaVersion

 def CheckPragmaSchemaVersion(self):
     # This still crashed pysqlite <= 2.2.1
     con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES)
     try:
         cur = self.con.cursor()
         cur.execute("pragma schema_version")
     finally:
         cur.close()
         con.close()
开发者ID:bodaay,项目名称:pysqlcipher3,代码行数:9,代码来源:regression.py


示例14: CheckScriptErrorNormal

 def CheckScriptErrorNormal(self):
     con = sqlite.connect(":memory:")
     cur = con.cursor()
     raised = False
     try:
         cur.executescript("create table test(sadfsadfdsa); select foo from hurz;")
     except sqlite.OperationalError:
         raised = True
     self.assertEqual(raised, True, "should have raised an exception")
开发者ID:bodaay,项目名称:pysqlcipher3,代码行数:9,代码来源:dbapi.py


示例15: assertDatabaseError

 def assertDatabaseError(self, password):
     conn = sqlite.connect(self.db)
     self.setPassword(conn, password)
     try:
         col_value = self.queryData(conn)
         self.assertIsNone(col_value)
     except sqlite.DatabaseError as ex:
         self.assertEqual('file is encrypted or is not a database', str(ex))
     finally:
         conn.close()
开发者ID:bodaay,项目名称:pysqlcipher3,代码行数:10,代码来源:sqlcipher.py


示例16: CheckClosedCall

 def CheckClosedCall(self):
     con = sqlite.connect(":memory:")
     con.close()
     try:
         con()
         self.fail("Should have raised a ProgrammingError")
     except sqlite.ProgrammingError:
         pass
     except:
         self.fail("Should have raised a ProgrammingError")
开发者ID:bodaay,项目名称:pysqlcipher3,代码行数:10,代码来源:dbapi.py


示例17: CheckClosedCurExecute

 def CheckClosedCurExecute(self):
     con = sqlite.connect(":memory:")
     cur = con.cursor()
     con.close()
     try:
         cur.execute("select 4")
         self.fail("Should have raised a ProgrammingError")
     except sqlite.ProgrammingError:
         pass
     except:
         self.fail("Should have raised a ProgrammingError")
开发者ID:bodaay,项目名称:pysqlcipher3,代码行数:11,代码来源:dbapi.py


示例18: CheckClosedSetProgressCallback

 def CheckClosedSetProgressCallback(self):
     con = sqlite.connect(":memory:")
     con.close()
     def progress(): pass
     try:
         con.set_progress_handler(progress, 100)
         self.fail("Should have raised a ProgrammingError")
     except sqlite.ProgrammingError:
         pass
     except:
         self.fail("Should have raised a ProgrammingError")
开发者ID:bodaay,项目名称:pysqlcipher3,代码行数:11,代码来源:dbapi.py


示例19: CheckClosedCreateFunction

 def CheckClosedCreateFunction(self):
     con = sqlite.connect(":memory:")
     con.close()
     def f(x): return 17
     try:
         con.create_function("foo", 1, f)
         self.fail("Should have raised a ProgrammingError")
     except sqlite.ProgrammingError:
         pass
     except:
         self.fail("Should have raised a ProgrammingError")
开发者ID:bodaay,项目名称:pysqlcipher3,代码行数:11,代码来源:dbapi.py


示例20: CheckUnicodeConnect

    def CheckUnicodeConnect(self):
        """
        With pysqlite 2.4.0 you needed to use a string or a APSW connection
        object for opening database connections.

        Formerly, both bytestrings and unicode strings used to work.

        Let's make sure unicode strings work in the future.
        """
        con = sqlite.connect(u":memory:")
        con.close()
开发者ID:bodaay,项目名称:pysqlcipher3,代码行数:11,代码来源:regression.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python dbapi2.connect函数代码示例发布时间:2022-05-27
下一篇:
Python dbapi2.connect函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap