示例#1
0
 def test_func_too_many_args(self):
     category = sqlite.SQLITE_LIMIT_FUNCTION_ARG
     msg = "too many arguments on function"
     with cx_limit(self.con, category=category, limit=1):
         self.con.execute("select abs(-1)")
         with self.assertRaisesRegex(sqlite.OperationalError, msg):
             self.con.execute("select max(1, 2)")
示例#2
0
    def test_large_sql(self):
        msg = "query string is too large"
        with memory_database() as cx, cx_limit(cx) as lim:
            cu = cx.cursor()

            cx("select 1".ljust(lim))
            # use a different SQL statement; don't reuse from the LRU cache
            cu.execute("select 2".ljust(lim))

            sql = "select 3".ljust(lim + 1)
            self.assertRaisesRegex(sqlite.DataError, msg, cx, sql)
            self.assertRaisesRegex(sqlite.DataError, msg, cu.execute, sql)
示例#3
0
    def test_trace_too_much_expanded_sql(self):
        # If the expanded string is too large, we'll fall back to the
        # unexpanded SQL statement (for SQLite 3.14.0 and newer).
        # The resulting string length is limited by the runtime limit
        # SQLITE_LIMIT_LENGTH.
        template = "select 1 as a where a="
        category = sqlite.SQLITE_LIMIT_LENGTH
        with memory_database() as cx, cx_limit(cx, category=category) as lim:
            ok_param = "a"
            bad_param = "a" * lim

            unexpanded_query = template + "?"
            expected = [unexpanded_query]
            if sqlite.sqlite_version_info < (3, 14, 0):
                expected = []
            with self.check_stmt_trace(cx, expected):
                cx.execute(unexpanded_query, (bad_param, ))

            expanded_query = f"{template}'{ok_param}'"
            with self.check_stmt_trace(cx, [expanded_query]):
                cx.execute(unexpanded_query, (ok_param, ))