本文整理匯總了Python中sqlite3.ProgrammingError方法的典型用法代碼示例。如果您正苦於以下問題:Python sqlite3.ProgrammingError方法的具體用法?Python sqlite3.ProgrammingError怎麽用?Python sqlite3.ProgrammingError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlite3
的用法示例。
在下文中一共展示了sqlite3.ProgrammingError方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: CheckConCursor
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import ProgrammingError [as 別名]
def CheckConCursor(self):
def run(con, errors):
try:
cur = con.cursor()
errors.append("did not raise ProgrammingError")
return
except sqlite.ProgrammingError:
return
except:
errors.append("raised wrong exception")
errors = []
t = threading.Thread(target=run, kwargs={"con": self.con, "errors": errors})
t.start()
t.join()
if len(errors) > 0:
self.fail("\n".join(errors))
示例2: CheckConCommit
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import ProgrammingError [as 別名]
def CheckConCommit(self):
def run(con, errors):
try:
con.commit()
errors.append("did not raise ProgrammingError")
return
except sqlite.ProgrammingError:
return
except:
errors.append("raised wrong exception")
errors = []
t = threading.Thread(target=run, kwargs={"con": self.con, "errors": errors})
t.start()
t.join()
if len(errors) > 0:
self.fail("\n".join(errors))
示例3: CheckConClose
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import ProgrammingError [as 別名]
def CheckConClose(self):
def run(con, errors):
try:
con.close()
errors.append("did not raise ProgrammingError")
return
except sqlite.ProgrammingError:
return
except:
errors.append("raised wrong exception")
errors = []
t = threading.Thread(target=run, kwargs={"con": self.con, "errors": errors})
t.start()
t.join()
if len(errors) > 0:
self.fail("\n".join(errors))
示例4: CheckCurImplicitBegin
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import ProgrammingError [as 別名]
def CheckCurImplicitBegin(self):
def run(cur, errors):
try:
cur.execute("insert into test(name) values ('a')")
errors.append("did not raise ProgrammingError")
return
except sqlite.ProgrammingError:
return
except:
errors.append("raised wrong exception")
errors = []
t = threading.Thread(target=run, kwargs={"cur": self.cur, "errors": errors})
t.start()
t.join()
if len(errors) > 0:
self.fail("\n".join(errors))
示例5: CheckCurClose
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import ProgrammingError [as 別名]
def CheckCurClose(self):
def run(cur, errors):
try:
cur.close()
errors.append("did not raise ProgrammingError")
return
except sqlite.ProgrammingError:
return
except:
errors.append("raised wrong exception")
errors = []
t = threading.Thread(target=run, kwargs={"cur": self.cur, "errors": errors})
t.start()
t.join()
if len(errors) > 0:
self.fail("\n".join(errors))
示例6: CheckCurExecute
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import ProgrammingError [as 別名]
def CheckCurExecute(self):
def run(cur, errors):
try:
cur.execute("select name from test")
errors.append("did not raise ProgrammingError")
return
except sqlite.ProgrammingError:
return
except:
errors.append("raised wrong exception")
errors = []
self.cur.execute("insert into test(name) values ('a')")
t = threading.Thread(target=run, kwargs={"cur": self.cur, "errors": errors})
t.start()
t.join()
if len(errors) > 0:
self.fail("\n".join(errors))
示例7: CheckCurIterNext
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import ProgrammingError [as 別名]
def CheckCurIterNext(self):
def run(cur, errors):
try:
row = cur.fetchone()
errors.append("did not raise ProgrammingError")
return
except sqlite.ProgrammingError:
return
except:
errors.append("raised wrong exception")
errors = []
self.cur.execute("insert into test(name) values ('a')")
self.cur.execute("select name from test")
t = threading.Thread(target=run, kwargs={"cur": self.cur, "errors": errors})
t.start()
t.join()
if len(errors) > 0:
self.fail("\n".join(errors))
示例8: CheckClosedCreateAggregate
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import ProgrammingError [as 別名]
def CheckClosedCreateAggregate(self):
con = sqlite.connect(":memory:")
con.close()
class Agg:
def __init__(self):
pass
def step(self, x):
pass
def finalize(self):
return 17
try:
con.create_aggregate("foo", 1, Agg)
self.fail("Should have raised a ProgrammingError")
except sqlite.ProgrammingError:
pass
except:
self.fail("Should have raised a ProgrammingError")
示例9: CheckClosed
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import ProgrammingError [as 別名]
def CheckClosed(self):
con = sqlite.connect(":memory:")
cur = con.cursor()
cur.close()
for method_name in ("execute", "executemany", "executescript", "fetchall", "fetchmany", "fetchone"):
if method_name in ("execute", "executescript"):
params = ("select 4 union select 5",)
elif method_name == "executemany":
params = ("insert into foo(bar) values (?)", [(3,), (4,)])
else:
params = []
try:
method = getattr(cur, method_name)
method(*params)
self.fail("Should have raised a ProgrammingError: method " + method_name)
except sqlite.ProgrammingError:
pass
except:
self.fail("Should have raised a ProgrammingError: " + method_name)
示例10: CheckCursorConstructorCallCheck
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import ProgrammingError [as 別名]
def CheckCursorConstructorCallCheck(self):
"""
Verifies that cursor methods check whether base class __init__ was
called.
"""
class Cursor(sqlite.Cursor):
def __init__(self, con):
pass
con = sqlite.connect(":memory:")
cur = Cursor(con)
try:
cur.execute("select 4+5").fetchall()
self.fail("should have raised ProgrammingError")
except sqlite.ProgrammingError:
pass
except:
self.fail("should have raised ProgrammingError")
示例11: CheckRecursiveCursorUse
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import ProgrammingError [as 別名]
def CheckRecursiveCursorUse(self):
"""
http://bugs.python.org/issue10811
Recursively using a cursor, such as when reusing it from a generator led to segfaults.
Now we catch recursive cursor usage and raise a ProgrammingError.
"""
con = sqlite.connect(":memory:")
cur = con.cursor()
cur.execute("create table a (bar)")
cur.execute("create table b (baz)")
def foo():
cur.execute("insert into a (bar) values (?)", (1,))
yield 1
with self.assertRaises(sqlite.ProgrammingError):
cur.executemany("insert into b (baz) values (?)",
((i,) for i in foo()))
示例12: CheckCursorConstructorCallCheck
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import ProgrammingError [as 別名]
def CheckCursorConstructorCallCheck(self):
"""
Verifies that cursor methods check whether base class __init__ was
called.
"""
class Cursor(sqlite.Cursor):
def __init__(self, con):
pass
con = sqlite.connect(":memory:")
cur = Cursor(con)
try:
cur.execute("select 4+5").fetchall()
self.fail("should have raised ProgrammingError")
except sqlite.ProgrammingError:
pass
except:
self.fail("should have raised ProgrammingError")
with self.assertRaisesRegexp(sqlite.ProgrammingError,
r'^Base Cursor\.__init__ not called\.$'):
cur.close()