def execute(self, query, params=None): if params is None: params = [] DEBUG_OUTPUT("Cursor::execute()", query, params) self.transaction.check_trans_handle() stmt = self._get_stmt(query) cooked_params = self._convert_params(params) if stmt.stmt_type == isc_info_sql_stmt_exec_procedure: self.transaction.connection._op_execute2( stmt.handle, self.transaction.trans_handle, cooked_params, calc_blr(stmt.xsqlda)) self._callproc_result = self.transaction.connection._op_sql_response( stmt.xsqlda) self.transaction.connection._op_response() self._fetch_records = None else: DEBUG_OUTPUT("Cursor::execute() _op_execute()", stmt.handle, self.transaction.trans_handle) self.transaction.connection._op_execute( stmt.handle, self.transaction.trans_handle, cooked_params) (h, oid, buf) = self.transaction.connection._op_response() if stmt.stmt_type == isc_info_sql_stmt_select: self._fetch_records = _fetch_generator(stmt) else: self._fetch_records = None self._callproc_result = None self.transaction.is_dirty = True return self
def execute(self, query, params=[]): DEBUG_OUTPUT("Cursor::execute()", query, params) stmt = self._get_stmt(query) cooked_params = self._convert_params(params) if stmt.stmt_type == isc_info_sql_stmt_exec_procedure: self.transaction.connection._op_execute2( stmt.handle, self.transaction.trans_handle, cooked_params, calc_blr(stmt.xsqlda) ) self._callproc_result = self.transaction.connection._op_sql_response(stmt.xsqlda) self.transaction.connection._op_response() self._fetch_records = None else: DEBUG_OUTPUT("Cursor::execute() _op_execute()", stmt.handle, self.transaction.trans_handle) self.transaction.connection._op_execute(stmt.handle, self.transaction.trans_handle, cooked_params) try: (h, oid, buf) = self.transaction.connection._op_response() except OperationalError as e: self._fetch_records = None self._callproc_result = None if e.gds_codes.intersection([335544665, 335544466, 335544838, 335544347]): raise IntegrityError(e._message, e.gds_codes, e.sql_code) if e.sql_code == -303: warnings.warn(e._message) return else: raise OperationalError(e._message, e.gds_codes, e.sql_code) if stmt.stmt_type == isc_info_sql_stmt_select: self._fetch_records = _fetch_generator(stmt) stmt.open() else: self._fetch_records = None self._callproc_result = None self.transaction.is_dirty = True
def execute(self, query, params=None): if params is None: params = [] DEBUG_OUTPUT("Cursor::execute()", query, params) self.transaction.check_trans_handle() stmt = self._get_stmt(query) cooked_params = self._convert_params(params) if stmt.stmt_type == isc_info_sql_stmt_exec_procedure: self.transaction.connection._op_execute2( stmt.handle, self.transaction.trans_handle, cooked_params, calc_blr(stmt.xsqlda)) self._callproc_result = self.transaction.connection._op_sql_response(stmt.xsqlda) self.transaction.connection._op_response() self._fetch_records = None else: DEBUG_OUTPUT( "Cursor::execute() _op_execute()", stmt.handle, self.transaction.trans_handle) self.transaction.connection._op_execute( stmt.handle, self.transaction.trans_handle, cooked_params) (h, oid, buf) = self.transaction.connection._op_response() if stmt.stmt_type == isc_info_sql_stmt_select: self._fetch_records = _fetch_generator(stmt) else: self._fetch_records = None self._callproc_result = None self.transaction.is_dirty = True return self
def _fetch_generator(stmt): DEBUG_OUTPUT("_fetch_generator()", stmt.handle, stmt.trans._trans_handle) connection = stmt.trans.connection more_data = True while more_data: if not stmt.is_opened: return connection._op_fetch(stmt.handle, calc_blr(stmt.xsqlda)) (rows, more_data) = connection._op_fetch_response(stmt.handle, stmt.xsqlda) for r in rows: # Convert BLOB handle to data for i in range(len(stmt.xsqlda)): x = stmt.xsqlda[i] if x.sqltype == SQL_TYPE_BLOB: if not r[i]: continue connection._op_open_blob(r[i], stmt.trans.trans_handle) (h, oid, buf) = connection._op_response() v = bs([]) n = 1 # 0,1:mora data 2:no more data while n != 2: connection._op_get_segment(h) (n, oid, buf) = connection._op_response() while buf: ln = bytes_to_int(buf[:2]) v += buf[2:ln + 2] buf = buf[ln + 2:] connection._op_close_blob(h) if connection.accept_type == ptype_lazy_send: connection.lazy_response_count += 1 else: (h, oid, buf) = connection._op_response() r[i] = v if x.sqlsubtype == 1: # TEXT if connection.use_unicode: r[i] = connection.bytes_to_ustr(r[i]) else: r[i] = connection.bytes_to_str(r[i]) yield tuple(r) return
def execute(self, query, params=[]): DEBUG_OUTPUT("Cursor::execute()", query, params) self.transaction.check_trans_handle() stmt = self._get_stmt(query) cooked_params = self._convert_params(params) if stmt.stmt_type == isc_info_sql_stmt_exec_procedure: self.transaction.connection._op_execute2( stmt.handle, self.transaction.trans_handle, cooked_params, calc_blr(stmt.xsqlda)) self._callproc_result = self.transaction.connection._op_sql_response(stmt.xsqlda) self.transaction.connection._op_response() self._fetch_records = None else: DEBUG_OUTPUT( "Cursor::execute() _op_execute()", stmt.handle, self.transaction.trans_handle) self.transaction.connection._op_execute( stmt.handle, self.transaction.trans_handle, cooked_params) try: (h, oid, buf) = self.transaction.connection._op_response() except OperationalError as e: self._fetch_records = None self._callproc_result = None if e.gds_codes.intersection([335544665, 335544466, 335544838, 335544347]): raise IntegrityError(e._message, e.gds_codes, e.sql_code) if e.sql_code == -303: warnings.warn(e._message) return self else: raise OperationalError(e._message, e.gds_codes, e.sql_code) if stmt.stmt_type == isc_info_sql_stmt_select: self._fetch_records = _fetch_generator(stmt) stmt.open() else: self._fetch_records = None self._callproc_result = None self.transaction.is_dirty = True return self
def _fetch_generator(stmt): DEBUG_OUTPUT("_fetch_generator()", stmt.handle, stmt.trans._trans_handle) connection = stmt.trans.connection more_data = True while more_data: if not stmt.is_opened: raise StopIteration() connection._op_fetch(stmt.handle, calc_blr(stmt.xsqlda)) (rows, more_data) = connection._op_fetch_response(stmt.handle, stmt.xsqlda) for r in rows: # Convert BLOB handle to data for i in range(len(stmt.xsqlda)): x = stmt.xsqlda[i] if x.sqltype == SQL_TYPE_BLOB: if not r[i]: continue connection._op_open_blob(r[i], stmt.trans.trans_handle) (h, oid, buf) = connection._op_response() v = bs([]) n = 1 # 0,1:mora data 2:no more data while n != 2: connection._op_get_segment(h) (n, oid, buf) = connection._op_response() while buf: ln = bytes_to_int(buf[:2]) v += buf[2:ln+2] buf = buf[ln+2:] connection._op_close_blob(h) if connection.accept_type == ptype_lazy_send: connection.lazy_response_count += 1 else: (h, oid, buf) = connection._op_response() r[i] = v if x.sqlsubtype == 1: # TEXT if connection.use_unicode: r[i] = connection.bytes_to_ustr(r[i]) else: r[i] = connection.bytes_to_str(r[i]) yield tuple(r) DEBUG_OUTPUT("_fetch_generator() StopIteration()") raise StopIteration()