Spaces:
Running
Running
simplified connection
Browse files- validate_sql.py +2 -25
validate_sql.py
CHANGED
|
@@ -1,31 +1,10 @@
|
|
| 1 |
import sys
|
| 2 |
-
import shutil
|
| 3 |
-
import os
|
| 4 |
-
import uuid
|
| 5 |
import duckdb
|
| 6 |
-
from duckdb import ParserException, SyntaxException, BinderException
|
| 7 |
-
|
| 8 |
-
TMP_DIR = "tmp"
|
| 9 |
-
class WithDuckDBConnectionInTmpDir(object):
|
| 10 |
-
def __init__(self):
|
| 11 |
-
self.tmp_dir = TMP_DIR + str(uuid.uuid1())
|
| 12 |
-
os.makedirs(self.tmp_dir)
|
| 13 |
-
self.original_wd = os.getcwd()
|
| 14 |
-
|
| 15 |
-
def __enter__(self):
|
| 16 |
-
os.chdir(self.tmp_dir)
|
| 17 |
-
self.con = duckdb.connect()
|
| 18 |
-
self.con.execute("SET enable_external_access=False")
|
| 19 |
-
return self.con
|
| 20 |
-
|
| 21 |
-
def __exit__(self, *args):
|
| 22 |
-
self.con.close()
|
| 23 |
-
os.chdir(self.original_wd)
|
| 24 |
-
shutil.rmtree(self.tmp_dir)
|
| 25 |
|
| 26 |
def validate_query(query, schemas):
|
| 27 |
try:
|
| 28 |
-
with
|
| 29 |
# register schemas
|
| 30 |
for schema in schemas.split(";"):
|
| 31 |
duckdb_conn.execute(schema)
|
|
@@ -47,8 +26,6 @@ def validate_query(query, schemas):
|
|
| 47 |
raise e
|
| 48 |
elif "Catalog Error: Copy Function" in message:
|
| 49 |
raise e
|
| 50 |
-
else:
|
| 51 |
-
print(message)
|
| 52 |
|
| 53 |
if __name__ == '__main__':
|
| 54 |
if len(sys.argv) > 2:
|
|
|
|
| 1 |
import sys
|
|
|
|
|
|
|
|
|
|
| 2 |
import duckdb
|
| 3 |
+
from duckdb import ParserException, SyntaxException, BinderException
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def validate_query(query, schemas):
|
| 6 |
try:
|
| 7 |
+
with duckdb.connect(":memory:", config={"enable_external_access": False}) as duckdb_conn:
|
| 8 |
# register schemas
|
| 9 |
for schema in schemas.split(";"):
|
| 10 |
duckdb_conn.execute(schema)
|
|
|
|
| 26 |
raise e
|
| 27 |
elif "Catalog Error: Copy Function" in message:
|
| 28 |
raise e
|
|
|
|
|
|
|
| 29 |
|
| 30 |
if __name__ == '__main__':
|
| 31 |
if len(sys.argv) > 2:
|