Spaces:
Running
Running
File size: 1,004 Bytes
b3eb06a 1d0f3f8 b3eb06a 1d0f3f8 b3eb06a 8a8e4f3 b3eb06a 8a8e4f3 b3eb06a 8a8e4f3 1d0f3f8 8a8e4f3 b3eb06a 8a8e4f3 1d0f3f8 b3eb06a 1d0f3f8 b3eb06a 1d0f3f8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import sys
import duckdb
from duckdb import ParserException, SyntaxException, BinderException, CatalogException
def validate_query(query, schemas):
try:
print("Running query: ", query)
with duckdb.connect(
":memory:", config={"enable_external_access": False}
) as duckdb_conn:
# register schemas
for schema in schemas.split(";"):
duckdb_conn.execute(schema)
cursor = duckdb_conn.cursor()
cursor.execute(query)
except ParserException as e:
raise e
except SyntaxException as e:
raise e
except BinderException as e:
raise e
except CatalogException as e:
if not ("but it exists" in str(e) and "extension" in str(e)):
raise e
except Exception as e:
return True
return True
if __name__ == "__main__":
if len(sys.argv) > 2:
validate_query(sys.argv[1], sys.argv[2])
else:
print("No query provided.")
|