本文整理匯總了Python中sqlite3.InterfaceError方法的典型用法代碼示例。如果您正苦於以下問題:Python sqlite3.InterfaceError方法的具體用法?Python sqlite3.InterfaceError怎麽用?Python sqlite3.InterfaceError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlite3
的用法示例。
在下文中一共展示了sqlite3.InterfaceError方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: CheckRollbackCursorConsistency
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import InterfaceError [as 別名]
def CheckRollbackCursorConsistency(self):
"""
Checks if cursors on the connection are set into a "reset" state
when a rollback is done on the connection.
"""
con = sqlite.connect(":memory:")
cur = con.cursor()
cur.execute("create table test(x)")
cur.execute("insert into test(x) values (5)")
cur.execute("select 1 union select 2 union select 3")
con.rollback()
try:
cur.fetchall()
self.fail("InterfaceError should have been raised")
except sqlite.InterfaceError, e:
pass
示例2: CheckRollbackCursorConsistency
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import InterfaceError [as 別名]
def CheckRollbackCursorConsistency(self):
"""
Checks if cursors on the connection are set into a "reset" state
when a rollback is done on the connection.
"""
con = sqlite.connect(":memory:")
cur = con.cursor()
cur.execute("create table test(x)")
cur.execute("insert into test(x) values (5)")
cur.execute("select 1 union select 2 union select 3")
con.rollback()
try:
cur.fetchall()
self.fail("InterfaceError should have been raised")
except sqlite.InterfaceError as e:
pass
except:
self.fail("InterfaceError should have been raised")
示例3: CheckCursorRegistration
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import InterfaceError [as 別名]
def CheckCursorRegistration(self):
"""
Verifies that subclassed cursor classes are correctly registered with
the connection object, too. (fetch-across-rollback problem)
"""
class Connection(sqlite.Connection):
def cursor(self):
return Cursor(self)
class Cursor(sqlite.Cursor):
def __init__(self, con):
sqlite.Cursor.__init__(self, con)
con = Connection(":memory:")
cur = con.cursor()
cur.execute("create table foo(x)")
cur.executemany("insert into foo(x) values (?)", [(3,), (4,), (5,)])
cur.execute("select x from foo")
con.rollback()
with self.assertRaises(sqlite.InterfaceError):
cur.fetchall()
示例4: test_binding_param_0_error
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import InterfaceError [as 別名]
def test_binding_param_0_error(self):
# test real param 0 binding errors
for supported_type in [str, int, bytes]:
await self.loop.run_in_executor(
self.executor, self.db.executemany, "insert into test2 values (?, NULL)",
[(supported_type(1), ), (supported_type(2), )]
)
await self.loop.run_in_executor(
self.executor, self.db.execute, "delete from test2 where id in (1, 2)"
)
for unsupported_type in [lambda x: (x, ), lambda x: [x], lambda x: {x}]:
try:
await self.loop.run_in_executor(
self.executor, self.db.executemany, "insert into test2 (id, val) values (?, NULL)",
[(unsupported_type(1), ), (unsupported_type(2), )]
)
self.assertTrue(False)
except sqlite3.InterfaceError as err:
self.assertEqual(str(err), "Error binding parameter 0 - probably unsupported type.")
示例5: do_full_login
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import InterfaceError [as 別名]
def do_full_login(account):
lock_network.acquire()
time.sleep(locktime)
lock_network.release()
if account['type'] == 'ptc':
login_ptc(account)
elif account['type'] == 'google':
login_google(account)
new_session(account)
else:
lprint('[{}] Error: Login type should be either ptc or google.'.format(account['num']))
sys.exit()
cursor_accs = db_accs.cursor()
while True:
try:
cursor_accs.execute("INSERT OR REPLACE INTO accounts VALUES(?,?,?,?,?,?,?)", [account['user'], account['access_token'], account['access_expire_timestamp'], account['api_url'], 0, '0', '0'])
db_accs.commit()
return
except sqlite3.OperationalError as e:
lprint('[-] Sqlite operational error: {}, account: {} Retrying...'.format(e, account['user']))
except sqlite3.InterfaceError as e:
lprint('[-] Sqlite interface error: {}, account: {} Retrying...'.format(e, account['user']))
示例6: CheckInterfaceError
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import InterfaceError [as 別名]
def CheckInterfaceError(self):
self.assertTrue(issubclass(sqlite.InterfaceError, sqlite.Error),
"InterfaceError is not a subclass of Error")
示例7: CheckExceptions
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import InterfaceError [as 別名]
def CheckExceptions(self):
# Optional DB-API extension.
self.assertEqual(self.cx.Warning, sqlite.Warning)
self.assertEqual(self.cx.Error, sqlite.Error)
self.assertEqual(self.cx.InterfaceError, sqlite.InterfaceError)
self.assertEqual(self.cx.DatabaseError, sqlite.DatabaseError)
self.assertEqual(self.cx.DataError, sqlite.DataError)
self.assertEqual(self.cx.OperationalError, sqlite.OperationalError)
self.assertEqual(self.cx.IntegrityError, sqlite.IntegrityError)
self.assertEqual(self.cx.InternalError, sqlite.InternalError)
self.assertEqual(self.cx.ProgrammingError, sqlite.ProgrammingError)
self.assertEqual(self.cx.NotSupportedError, sqlite.NotSupportedError)
示例8: CheckCursorRegistration
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import InterfaceError [as 別名]
def CheckCursorRegistration(self):
"""
Verifies that subclassed cursor classes are correctly registered with
the connection object, too. (fetch-across-rollback problem)
"""
class Connection(sqlite.Connection):
def cursor(self):
return Cursor(self)
class Cursor(sqlite.Cursor):
def __init__(self, con):
sqlite.Cursor.__init__(self, con)
con = Connection(":memory:")
cur = con.cursor()
cur.execute("create table foo(x)")
cur.executemany("insert into foo(x) values (?)", [(3,), (4,), (5,)])
cur.execute("select x from foo")
con.rollback()
try:
cur.fetchall()
self.fail("should have raised InterfaceError")
except sqlite.InterfaceError:
pass
except:
self.fail("should have raised InterfaceError")
示例9: CheckUnsupportedSeq
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import InterfaceError [as 別名]
def CheckUnsupportedSeq(self):
class Bar: pass
val = Bar()
try:
self.cur.execute("insert into test(f) values (?)", (val,))
self.fail("should have raised an InterfaceError")
except sqlite.InterfaceError:
pass
except:
self.fail("should have raised an InterfaceError")