tdoehmen commited on
Commit
dcec0ff
1 Parent(s): 4bcd55d

updated validation

Browse files
Files changed (2) hide show
  1. app.py +6 -2
  2. validate_sql.py +9 -7
app.py CHANGED
@@ -66,8 +66,12 @@ def validate_sql(query, schema):
66
  )
67
  # Get output and potential parser, and binder error message
68
  stdout, stderr = process.communicate(timeout=0.5)
69
- if stdout != "":
70
- return False, stdout.decode('utf8')
 
 
 
 
71
  return True, ""
72
  except subprocess.TimeoutExpired:
73
  process.kill()
 
66
  )
67
  # Get output and potential parser, and binder error message
68
  stdout, stderr = process.communicate(timeout=0.5)
69
+ if stderr:
70
+ error_message = stderr.decode('utf8').split("\n")
71
+ # skip traceback
72
+ if len(error_message) > 3:
73
+ error_message = "\n".join(error_message[3:])
74
+ return False, error_message
75
  return True, ""
76
  except subprocess.TimeoutExpired:
77
  process.kill()
validate_sql.py CHANGED
@@ -14,21 +14,23 @@ def validate_query(query, schemas):
14
  cursor = duckdb_conn.cursor()
15
  cursor.execute(query)
16
  except ParserException as e:
17
- print(str(e))
18
  except SyntaxException as e:
19
- print(str(e))
20
  except BinderException as e:
21
- print(str(e))
22
  except CatalogException as e:
23
  if not ("but it exists" in str(e) and "extension" in str(e)):
24
- print(str(e))
25
  except Exception as e:
26
- return True
27
- return True
28
 
29
 
30
  if __name__ == "__main__":
31
  if len(sys.argv) > 2:
32
- validate_query(sys.argv[1], sys.argv[2])
 
 
33
  else:
34
  print("No query provided.")
 
14
  cursor = duckdb_conn.cursor()
15
  cursor.execute(query)
16
  except ParserException as e:
17
+ return str(e)
18
  except SyntaxException as e:
19
+ return str(e)
20
  except BinderException as e:
21
+ return str(e)
22
  except CatalogException as e:
23
  if not ("but it exists" in str(e) and "extension" in str(e)):
24
+ return str(e)
25
  except Exception as e:
26
+ return None
27
+ return None
28
 
29
 
30
  if __name__ == "__main__":
31
  if len(sys.argv) > 2:
32
+ error = validate_query(sys.argv[1], sys.argv[2])
33
+ if error:
34
+ raise Exception(error)
35
  else:
36
  print("No query provided.")