MCPcopy Create free account
hub / github.com/OpenBMB/BMTools / execute_sql

Method execute_sql

bmtools/tools/db_diag/utils/database.py:102–135  ·  view source on GitHub ↗
(self, sql)

Source from the content-addressed store, hash-verified

100 '''
101
102 def execute_sql(self, sql):
103 fail = 1
104 self.conn = self.resetConn(timeout=2)
105 cur = self.conn.cursor()
106 i = 0
107 cnt = 5 # retry times
108 while fail == 1 and i < cnt:
109 try:
110 fail = 0
111 print("========== start execution time:", time.time())
112 cur.execute(sql)
113 except BaseException:
114 fail = 1
115 time.sleep(1)
116 res = []
117 if fail == 0:
118 res = cur.fetchall()
119 i = i + 1
120 logging.debug('database {}, return flag {}, execute sql {}\n'.format(self.args.dbname, 1 - fail, sql))
121
122 cur.close()
123 self.conn.close()
124
125 print("========== finish time:", time.time())
126
127 if fail == 1:
128 # raise RuntimeError("Database query failed")
129 print("SQL Execution Fatal!!")
130
131 return 0, ''
132 elif fail == 0:
133 # print("SQL Execution Succeed!!")
134
135 return 1, res
136
137 def pgsql_results(self, sql):
138 try:

Callers 8

pgsql_resultsMethod · 0.95
pgsql_query_planMethod · 0.95
pgsql_cost_estimationMethod · 0.95
pgsql_actual_timeMethod · 0.95
mysql_cost_estimationMethod · 0.95
compute_table_schemaMethod · 0.95
simulate_indexMethod · 0.95
drop_simulated_indexMethod · 0.95

Calls 1

resetConnMethod · 0.95

Tested by

no test coverage detected