def setUp(self): con = sqlite.connect() cur = con.cursor() cur.execute("drop table test") cur.close() con.close() self.con = sqlite.connect(detect_types=sqlite.PARSE_DECLTYPES) self.cur = self.con.cursor() self.cur.execute("create table test(d date, ts timestamp)")
def setUp(self): con = sqlite.connect() cur = con.cursor() cur.execute("drop table test") cur.close() con.close() self.con = sqlite.connect() self.cur = self.con.cursor() self.cur.execute("create table test(x foo)")
def setUp(self): con = sqlite.connect() cur = con.cursor() cur.execute("drop table test") cur.close() con.close() self.con = sqlite.connect() self.cur = self.con.cursor() self.cur.execute( "create table test(i integer, s varchar, f number, b blob)")
def setUp(self): con = sqlite.connect() cur = con.cursor() if cur.execute("pragma table_info(test)").fetchall(): cur.execute("drop table test") cur.close() con.close() self.con = sqlite.connect() self.cur = self.con.cursor() self.cur.execute("create table test(x foo)")
def setUp(self): con = sqlite.connect() cur = con.cursor() if cur.execute("pragma table_info(test)").fetchall(): cur.execute("drop table test") cur.close() con.close() self.con = sqlite.connect() self.cur = self.con.cursor() self.cur.execute( "create table test(i integer, s varchar, f number, b blob)")
def setUp(self): con = sqlite.connect() cur = con.cursor() cur.execute("drop table test") cur.close() con.close() self.con = sqlite.connect(detect_types=sqlite.PARSE_COLNAMES) self.cur = self.con.cursor() self.cur.execute("create table test(x foo)") sqlite.converters["FOO"] = lambda x: "[%s]" % x.decode("ascii") sqlite.converters["BAR"] = lambda x: "<%s>" % x.decode("ascii") sqlite.converters["EXC"] = lambda x: 5 / 0 sqlite.converters["B1B1"] = lambda x: "MARKER"
def test_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)
def test_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")
def setUp(self): self.cx = sqlite.connect(":memory:") self.cu = self.cx.cursor() self.cu.execute( "create table test(id integer primary key, name text, income number)" ) self.cu.execute("insert into test(name) values (?)", ("foo", ))
def setUp(self): self.con = sqlite.connect() try: del sqlite.adapters[int] except: pass sqlite.register_adapter(int, ObjectAdaptationTests.cast) self.cur = self.con.cursor()
def test_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")
def setUpClass(cls): cls.con = sqlite.connect(":memory:") cls.cur = cls.con.cursor() if cls.cur.execute("pragma table_info(test)").fetchall(): cls.cur.execute("drop table test") try: del sqlite.adapters[int] except: pass sqlite.register_adapter(int, ObjectAdaptationTests.cast)
def test_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")
def test_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")
def setUpClass(cls): cls.con = sqlite.connect(detect_types=sqlite.PARSE_COLNAMES) cls.cur = cls.con.cursor() if cls.cur.execute("pragma table_info(test)").fetchall(): cls.cur.execute("drop table test") sqlite.converters["FOO"] = lambda x: "[%s]" % x.decode("ascii") sqlite.converters["BAR"] = lambda x: "<%s>" % x.decode("ascii") sqlite.converters["EXC"] = lambda x: 5 / 0 sqlite.converters["B1B1"] = lambda x: "MARKER"
def test_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")
def test_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")
def setUpClass(cls): cls.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES) cls.cur = cls.con.cursor() if cls.cur.execute("pragma table_info(test)").fetchall(): cls.cur.execute("drop table test") sqlite.converters["FOO"] = lambda x: "[%s]" % x.decode("ascii") sqlite.converters["BAR"] = lambda x: "<%s>" % x.decode("ascii") sqlite.converters["EXC"] = lambda x: 5/0 sqlite.converters["B1B1"] = lambda x: "MARKER"
def setUp(self): con = sqlite.connect() cur = con.cursor() cur.execute("drop table test") cur.close() con.close() self.con = sqlite.connect(detect_types=sqlite.PARSE_DECLTYPES) self.cur = self.con.cursor() self.cur.execute( "create table test(i int, s str, f float, b bool, u unicode, foo foo, bin blob, n1 number, n2 number(5))" ) # override float, make them always return the same number sqlite.converters["FLOAT"] = lambda x: 47.2 # and implement two custom ones sqlite.converters["BOOL"] = lambda x: bool(int(x)) sqlite.converters["FOO"] = DeclTypesTests.Foo sqlite.converters["WRONG"] = lambda x: "WRONG" sqlite.converters["NUMBER"] = float
def test_CheckScriptStringSql(self): con = sqlite.connect(":memory:") cur = con.cursor() cur.executescript(""" -- bla bla /* a stupid comment */ create table a(i); insert into a(i) values (5); """) cur.execute("select i from a") res = cur.fetchone()[0] self.assertEqual(res, 5)
def get_connection(conn=None): if conn is not None: return conn # Connect to the database _conn = dbapi2.connect( host=RQLITE_SERVER, port=RQLITE_PORT, ) logger.debug("connection opened") return _conn
def test_CheckScriptStringUnicode(self): con = sqlite.connect(":memory:") cur = con.cursor() cur.executescript(u""" create table a(i); insert into a(i) values (5); select i from a; delete from a; insert into a(i) values (6); """) cur.execute("select i from a") res = cur.fetchone()[0] self.assertEqual(res, 6)
def setUpClass(cls): cls.con = sqlite.connect(detect_types=sqlite.PARSE_DECLTYPES) cls.cur = cls.con.cursor() if cls.cur.execute("pragma table_info(test)").fetchall(): cls.cur.execute("drop table test") # override float, make them always return the same number sqlite.converters["FLOAT"] = lambda x: 47.2 # and implement two custom ones sqlite.converters["BOOL"] = lambda x: bool(int(x)) sqlite.converters["FOO"] = DeclTypesTests.Foo sqlite.converters["WRONG"] = lambda x: "WRONG" sqlite.converters["NUMBER"] = float
def test_CheckClosedSetAuthorizer(self): con = sqlite.connect(":memory:") con.close() def authorizer(*args): return sqlite.DENY try: con.set_authorizer(authorizer) self.fail("Should have raised a ProgrammingError") except sqlite.ProgrammingError: pass except: self.fail("Should have raised a ProgrammingError")
def test_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")
def test_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")
def setUpClass(cls): cls.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES) cls.cur = cls.con.cursor() if cls.cur.execute("pragma table_info(test)").fetchall(): cls.cur.execute("drop table test") # override float, make them always return the same number sqlite.converters["FLOAT"] = lambda x: 47.2 # and implement two custom ones sqlite.converters["BOOL"] = lambda x: bool(int(x)) sqlite.converters["FOO"] = DeclTypesTests.Foo sqlite.converters["WRONG"] = lambda x: "WRONG" sqlite.converters["NUMBER"] = float
def test_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")
def default(self, *args, **kwargs): grant_type = kwargs.get('grant_type') if grant_type == 'password': password_is_valid = False connection = dbapi2.connect(self.hostname, self.port) username = kwargs.get("username") password = kwargs.get("password") try: with connection.cursor() as cursor: cursor.execute( "SELECT password FROM USERS WHERE username='******'". format(username)) result = cursor.fetchone() hashed_password = result['password'] password_is_valid = pbkdf2_sha256.verify( password, hashed_password) finally: connection.close() if password_is_valid is True: return self.generate_token() raise cherrypy.HTTPError(403, message="Access Denied")
def setUpClass(cls): cls.con = sqlite.connect(":memory:") cls.cur = cls.con.cursor() cls.cur.close()
def setUpClass(cls): cls.con = sqlite.connect(":memory:")
def setUpClass(cls): cls.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES) cls.cur = cls.con.cursor() if cls.cur.execute("pragma table_info(test)").fetchall(): cls.cur.execute("drop table test")
def setUpClass(cls): cls.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES) if cls.con.execute("pragma table_info(test)").fetchall(): cls.con.execute("drop table test") sqlite.register_converter("bin", BinaryConverterTests.convert)
def setUpClass(cls): cls.con = sqlite.connect(":memory:") cls.cur = cls.con.cursor() if cls.cur.execute("pragma table_info(test)").fetchall(): cls.cur.execute("drop table test")