Exemplo n.º 1
0
    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)")
Exemplo n.º 2
0
    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)")
Exemplo n.º 3
0
    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)")
Exemplo n.º 4
0
    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)")
Exemplo n.º 5
0
    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)")
Exemplo n.º 6
0
    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"
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
 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")
Exemplo n.º 9
0
 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", ))
Exemplo n.º 10
0
 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()
Exemplo n.º 11
0
 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")
Exemplo n.º 12
0
 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)
Exemplo n.º 13
0
 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")
Exemplo n.º 14
0
 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")
Exemplo n.º 15
0
    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"
Exemplo n.º 16
0
 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")
Exemplo n.º 17
0
 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")
Exemplo n.º 18
0
    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"
Exemplo n.º 19
0
    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
Exemplo n.º 20
0
 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)
Exemplo n.º 21
0
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
Exemplo n.º 22
0
 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)
Exemplo n.º 23
0
    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
Exemplo n.º 24
0
    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")
Exemplo n.º 25
0
    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")
Exemplo n.º 26
0
    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")
Exemplo n.º 27
0
    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
Exemplo n.º 28
0
    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")
Exemplo n.º 29
0
 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")
Exemplo n.º 30
0
 def setUpClass(cls):
     cls.con = sqlite.connect(":memory:")
     cls.cur = cls.con.cursor()
     cls.cur.close()
Exemplo n.º 31
0
 def setUpClass(cls):
     cls.con = sqlite.connect(":memory:")
Exemplo n.º 32
0
 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")
Exemplo n.º 33
0
 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)
Exemplo n.º 34
0
 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")