def exec_threaded(statement, start_line): if self.app.config.get("sqlparse.enabled", True): stmts = sqlparse.split(statement) else: stmts = [statement] for stmt in stmts: add_offset = len(stmt.splitlines()) if not stmt.strip(): start_line += add_offset continue query = Query(stmt, self.connection) # query.coding_hint = self.connection.coding_hint gtk.gdk.threads_enter() query.set_data('editor_start_line', start_line) query.connect("started", self.on_query_started) query.connect("finished", self.on_query_finished, tag_notice) gtk.gdk.threads_leave() query.execute(True) start_line += add_offset if query.failed: # hmpf, doesn't work that way... so just return here... return
def execute_query(self, statement_at_cursor=False): # TODO(andi): This method needs some refactoring: # - the actual execution code is doubled # - that affects offset counting too self.results.assure_visible() def exec_threaded(statement, start_line): if self.app.config.get("sqlparse.enabled", True): stmts = sqlparse.split(statement) else: stmts = [statement] for stmt in stmts: add_offset = len(stmt.splitlines()) if not stmt.strip(): start_line += add_offset continue query = Query(stmt, self.connection) # query.coding_hint = self.connection.coding_hint gtk.gdk.threads_enter() query.set_data('editor_start_line', start_line) query.connect("started", self.on_query_started) query.connect("finished", self.on_query_finished, tag_notice) gtk.gdk.threads_leave() query.execute(True) start_line += add_offset if query.failed: # hmpf, doesn't work that way... so just return here... return # gtk.gdk.threads_enter() # dlg = gtk.MessageDialog(None, # gtk.DIALOG_MODAL| # gtk.DIALOG_DESTROY_WITH_PARENT, # gtk.MESSAGE_ERROR, # gtk.BUTTONS_YES_NO, # _(u"An error occurred. Continue?")) # if dlg.run() == gtk.RESPONSE_NO: # leave = True # else: # leave = False # dlg.destroy() # gtk.gdk.threads_leave() # if leave: # return buffer = self.textview.get_buffer() self.results.reset() if not statement_at_cursor: bounds = buffer.get_selection_bounds() if not bounds: bounds = buffer.get_bounds() else: bounds = self.textview.get_current_statement() if bounds is None: return buffer.remove_tag_by_name('error', *bounds) statement = buffer.get_text(*bounds) if self.app.config.get("editor.replace_variables"): tpl = string.Template(statement) tpl_search = tpl.pattern.search(tpl.template) if tpl_search and tpl_search.groupdict().get("named"): dlg = StatementVariablesDialog(tpl) if dlg.run() == gtk.RESPONSE_OK: statement = dlg.get_statement() else: statement = None dlg.destroy() if not statement: return def foo(connection, msg): self.results.add_message(msg) tag_notice = self.connection.connect("notice", foo) if self.connection.threadsafety >= 2: start_line = bounds[0].get_line()+1 thread.start_new_thread(exec_threaded, (statement, start_line)) else: start_line = bounds[0].get_line()+1 line_offset = start_line if self.app.config.get("sqlparse.enabled", True): stmts = sqlparse.split(statement) else: stmts = [statement] for stmt in stmts: add_offset = len(stmt.splitlines()) if not stmt.strip(): line_offset += add_offset continue query = Query(stmt, self.connection) query.set_data('editor_start_line', line_offset) # query.coding_hint = self.connection.coding_hint query.connect("started", self.on_query_started) query.connect("finished", self.on_query_finished, tag_notice) query.execute() line_offset += add_offset
def execute_query(self, statement_at_cursor=False): # TODO(andi): This method needs some refactoring: # - the actual execution code is doubled # - that affects offset counting too self.results.assure_visible() def exec_threaded(statement, start_line): if self.app.config.get("sqlparse.enabled", True): stmts = sqlparse.split(statement) else: stmts = [statement] for stmt in stmts: add_offset = len(stmt.splitlines()) if not stmt.strip(): start_line += add_offset continue query = Query(stmt, self.connection) # query.coding_hint = self.connection.coding_hint gtk.gdk.threads_enter() query.set_data('editor_start_line', start_line) query.connect("started", self.on_query_started) query.connect("finished", self.on_query_finished, tag_notice) gtk.gdk.threads_leave() query.execute(True) start_line += add_offset if query.failed: # hmpf, doesn't work that way... so just return here... return # gtk.gdk.threads_enter() # dlg = gtk.MessageDialog(None, # gtk.DIALOG_MODAL| # gtk.DIALOG_DESTROY_WITH_PARENT, # gtk.MESSAGE_ERROR, # gtk.BUTTONS_YES_NO, # _(u"An error occurred. Continue?")) # if dlg.run() == gtk.RESPONSE_NO: # leave = True # else: # leave = False # dlg.destroy() # gtk.gdk.threads_leave() # if leave: # return buffer = self.textview.get_buffer() self.results.reset() if not statement_at_cursor: bounds = buffer.get_selection_bounds() if not bounds: bounds = buffer.get_bounds() else: bounds = self.textview.get_current_statement() if bounds is None: return buffer.remove_tag_by_name('error', *bounds) statement = buffer.get_text(*bounds) if self.app.config.get("editor.replace_variables"): tpl = string.Template(statement) tpl_search = tpl.pattern.search(tpl.template) if tpl_search and tpl_search.groupdict().get("named"): dlg = StatementVariablesDialog(tpl) if dlg.run() == gtk.RESPONSE_OK: statement = dlg.get_statement() else: statement = None dlg.destroy() if not statement: return def foo(connection, msg): self.results.add_message(msg) tag_notice = self.connection.connect("notice", foo) if self.connection.threadsafety >= 2: start_line = bounds[0].get_line() + 1 thread.start_new_thread(exec_threaded, (statement, start_line)) else: start_line = bounds[0].get_line() + 1 line_offset = start_line if self.app.config.get("sqlparse.enabled", True): stmts = sqlparse.split(statement) else: stmts = [statement] for stmt in stmts: add_offset = len(stmt.splitlines()) if not stmt.strip(): line_offset += add_offset continue query = Query(stmt, self.connection) query.set_data('editor_start_line', line_offset) # query.coding_hint = self.connection.coding_hint query.connect("started", self.on_query_started) query.connect("finished", self.on_query_finished, tag_notice) query.execute() line_offset += add_offset