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

Method execute_sql

bmtools/tools/database/utils/database.py:102–125  ·  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()
105 cur = self.conn.cursor()
106 i = 0
107 cnt = 3 # retry times
108 while fail == 1 and i < cnt:
109 try:
110 fail = 0
111 cur.execute(sql)
112 except BaseException:
113 fail = 1
114 res = []
115 if fail == 0:
116 res = cur.fetchall()
117 i = i + 1
118 logging.debug('database {}, return flag {}, execute sql {}\n'.format(self.args.dbname, 1 - fail, sql))
119 if fail == 1:
120 # raise RuntimeError("Database query failed")
121 print("SQL Execution Fatal!!")
122 return 0, ''
123 elif fail == 0:
124 # print("SQL Execution Succeed!!")
125 return 1, res
126
127 def pgsql_results(self, sql):
128 try:

Callers 7

pgsql_resultsMethod · 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