MCPcopy Create free account
hub / github.com/Snowflake-Labs/ReFoRCE / exec_sql_sqlite

Method exec_sql_sqlite

methods/ReFoRCE/sql.py:59–83  ·  view source on GitHub ↗
(self, sql_query, save_path=None, max_len=30000, sqlite_path=None)

Source from the content-addressed store, hash-verified

57
58 def exec_sql_sqlite(self, sql_query, save_path=None, max_len=30000, sqlite_path=None):
59 cursor = self.conns[sqlite_path].cursor()
60 try:
61 cursor.execute(sql_query)
62 column_info = cursor.description
63 rows = self.get_rows(cursor, max_len)
64 columns = [desc[0] for desc in column_info]
65 except Exception as e:
66 return e
67 finally:
68 try:
69 cursor.close()
70 except Exception as e:
71 print("Failed to close cursor:", e)
72
73 if not rows:
74 return "No data found for the specified query.\n"
75 else:
76 csv_content = self.get_csv(columns, rows)
77 if save_path:
78 with open(save_path, 'w', newline='') as f:
79 f.write(csv_content)
80 return 0
81 else:
82 return hard_cut(csv_content, max_len)
83
84 def exec_sql_sf(self, sql_query, save_path, max_len, ex_id):
85 with self.conns[ex_id].cursor() as cursor:
86 try:

Callers

nothing calls this directly

Calls 5

get_rowsMethod · 0.95
get_csvMethod · 0.95
hard_cutFunction · 0.90
closeMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected