Skip to content

Commit

Permalink
get PLAN optionally
Browse files Browse the repository at this point in the history
  • Loading branch information
nakagami committed Dec 13, 2011
1 parent fa3d4c4 commit 558d6df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions firebirdsql/fbcore.py
Expand Up @@ -360,7 +360,7 @@ def parse_xsqlda(buf, connection, stmt_handle):
return xsqlda

class PreparedStatement:
def __init__(self, cur, sql):
def __init__(self, cur, sql, get_plan=False):
self.cur = cur
self.sql = sql
transaction = self.cur.transaction
Expand All @@ -370,9 +370,15 @@ def __init__(self, cur, sql):
(h, oid, buf) = connection._op_response()
self.stmt_handle = h

connection._op_prepare_statement(
if get_plan:
connection._op_prepare_statement(
self.stmt_handle, transaction.trans_handle, sql,
option_items=bytes([isc_info_sql_get_plan]))
else:
connection._op_prepare_statement(
self.stmt_handle, transaction.trans_handle, sql)
self.plan = None

(h, oid, buf) = connection._op_response()

i = 0
Expand Down Expand Up @@ -400,7 +406,7 @@ def __getattr__(self, attrname):
raise AttributeError

class Cursor:
def __init__(self, trans):
def __init__(self, trans, get_plan=False):
self._transaction = trans
self.transaction.connection._op_allocate_statement(self.transaction)
(h, oid, buf) = self.transaction.connection._op_response()
Expand Down Expand Up @@ -475,8 +481,8 @@ def _callproc(self, query, params):
calc_blr(self._xsqlda))
return self.transaction.connection._op_sql_response(self._xsqlda)

def prep(self, query):
prepared_statement = PreparedStatement(self, query)
def prep(self, query, get_plan=False):
prepared_statement = PreparedStatement(self, query, get_plan=get_plan)
return prepared_statement

def execute(self, query, params = []):
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_prep.py
Expand Up @@ -49,7 +49,7 @@
port=TEST_PORT, user=TEST_USER, password=TEST_PASS)
cur = conn.cursor()

prep = cur.prep("select * from foo where c=?")
prep = cur.prep("select * from foo where c=?", get_plan=True)
print('sql=', prep.sql)
print('statement_type=', prep.statement_type)
print('n_output_params=', prep.n_output_params)
Expand Down

0 comments on commit 558d6df

Please sign in to comment.