Skip to content

Commit

Permalink
callproc skelton
Browse files Browse the repository at this point in the history
  • Loading branch information
nakagami committed Nov 26, 2011
1 parent 01f5d60 commit bef4eb5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
26 changes: 23 additions & 3 deletions firebirdsql/fbcore.py
Expand Up @@ -424,9 +424,6 @@ def __init__(self, trans):
def transaction(self):
return self._transaction

def callproc(self, procname, *params):
raise NotSupportedError()

def _convert_params(self, params):
cooked_params = []
for param in params: # Convert str/bytes parameter to blob id
Expand Down Expand Up @@ -475,6 +472,22 @@ def _execute(self, query, params):
raise IntegrityError(e.message, e.gds_codes, e.sql_code)
return stmt_type, stmt_handle

def _callproc(self, query, params):
raise NotSupportedError()

cooked_params = self._convert_params(params)

self.transaction.connection._op_execute2(stmt_handle,
self.transaction.trans_handle, cooked_params)
try:
(h, oid, buf) = self.transaction.connection._op_response()
except OperationalError:
e = sys.exc_info()[1]
if 335544665 in e.gds_codes:
raise IntegrityError(e.message, e.gds_codes, e.sql_code)
return stmt_type, stmt_handle


def prep(self, query):
prepared_statement = PreparedStatement(self, query)
return prepared_statement
Expand All @@ -484,6 +497,13 @@ def execute(self, query, params = []):
if stmt_type == isc_info_sql_stmt_select:
self._fetch_records = self._fetch_generator(stmt_handle)

def callproc(self, procname, params = []):
query = 'EXECUTE PROCEDURE ' + procname + ' ' + ','.join('?'*len(params))
stmt_type, stmt_handle = self._callproc(query, params)
if stmt_type == isc_info_sql_stmt_select:
self._fetch_records = self._fetch_generator(stmt_handle)


def executemany(self, query, seq_of_params):
for params in seq_of_params:
self.execute(query, params)
Expand Down
20 changes: 20 additions & 0 deletions firebirdsql/wireprotocol.py
Expand Up @@ -135,6 +135,7 @@ class WireProtocol:
op_free_statement = 67
op_prepare_statement = 68
op_info_sql = 70
op_execute2 = 76
op_drop_database = 81
op_service_attach = 82
op_service_detach = 83
Expand Down Expand Up @@ -442,6 +443,25 @@ def _op_execute(self, stmt_handle, trans_handle, params):
p.pack_int(1)
send_channel(self.sock, p.get_buffer() + values)

@wire_operation
def _op_execute2(self, stmt_handle, trans_handle, params):
p = xdrlib.Packer()
p.pack_int(self.op_execute2)
p.pack_int(stmt_handle)
p.pack_int(trans_handle)

if len(params) == 0:
p.pack_bytes(bytes([]))
p.pack_int(0)
p.pack_int(0)
send_channel(self.sock, p.get_buffer())
else:
(blr, values) = self.params_to_blr(params)
p.pack_bytes(blr)
p.pack_int(0)
p.pack_int(1)
send_channel(self.sock, p.get_buffer() + values)

@wire_operation
def _op_execute_immediate(self, trans_handle, db_handle, sql='', params=[],
in_msg='', out_msg='', possible_requests=0):
Expand Down

0 comments on commit bef4eb5

Please sign in to comment.