💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Reject a semicolon in a SQL query instead of silently cutting the statement (#1388)
PerryLink55fadb4c568e
diff --git a/src/python/txtai/database/sql/base.py b/src/python/txtai/database/sql/base.pyindex 70186539..6a3f30ed 100644--- a/src/python/txtai/database/sql/base.py+++ b/src/python/txtai/database/sql/base.py@@ -5,6 +5,7 @@ SQL modulefrom io import StringIOfrom shlex import shlex+from .error import SQLErrorfrom .expression import Expression@@ -42,8 +43,11 @@ class SQL:clauses = Noneif self.issql(query):- # Ignore multiple statements- query = query.split(";")[0]+ # Multiple statements are not supported+ components = [x for x in query.split(";") if x.strip()]+ if len(components) > 1:+ raise SQLError("Multiple SQL statements are not supported. Pass values that contain a semicolon as a bind parameter.")+ query = components[0]# Tokenize querytokens, positions = self.tokenize(query)diff --git a/test/python/testdatabase/testsql.py b/test/python/testdatabase/testsql.pyindex f9de9163..73bac065 100644--- a/test/python/testdatabase/testsql.py+++ b/test/python/testdatabase/testsql.py@@ -143,6 +143,17 @@ class TestSQL(unittest.TestCase):with self.assertRaises(SQLError):self.db.search("select a b c from txtai where id match id")+ def testMultipleStatements(self):+ """+ Test only the first statement is run+ """++ with self.assertRaises(SQLError):+ self.db.search("select * from txtai ; delete from sections")++ self.assertSql("select", ";select id from txtai", "s.id")+ self.assertSql("select", "select id from txtai;", "s.id")+def testBracket(self):"""Test bracket expressions