-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
35 lines (27 loc) · 1.04 KB
/
utils.py
File metadata and controls
35 lines (27 loc) · 1.04 KB
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
from http.server import BaseHTTPRequestHandler, HTTPServer
import json
def column_discovery(collectionId, cursor):
sqlString = f"SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS where table_name = '{collectionId}';"
cursor.execute(sqlString)
rs = cursor.fetchall()
return rs
def column_discovery2(collectionId, cursor):
sqlString = f"SELECT column_name, data_type FROM INFORMATION_SCHEMA.COLUMNS where table_name = '{collectionId}';"
cursor.execute(sqlString)
rs = cursor.fetchall()
return rs
def send_json_response(handler, status_code, data):
handler.send_response(status_code)
handler.send_header("Content-type", "application/json")
handler.end_headers()
# if data is dict,!!> json
if isinstance(data, dict):
data = json.dumps(data)
# encode data utf8
handler.wfile.write(data.encode('utf-8'))
def handle_error(handler, code, message):
error_response = {
"code": str(code),
"description": message
}
send_json_response(handler, code, error_response)