Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursor: executemany(operation, seq_of_parameters) does PREPARE of <operation> for each parameter from <seq_of_parameters> [PYFB60] #77

Closed
firebird-automations opened this issue Jan 5, 2016 · 3 comments

Comments

@firebird-automations
Copy link

Submitted by: @pavel-zotov

/*
Preparing DDL for test:

SQL> recreate table test_uuid (
CON> uuid char(16) character set octets collate octets,
CON> datavalue integer,
CON> constraint test_uuid_pk primary key(uuid) using index test_uuid_pk
CON> );
SQL> commit;
*/

Test:
#⁠#⁠#⁠#⁠#⁠

import fdb

print fdb.__version__

conn = fdb.connect(dsn='localhost/3309:e30', user='SYSDBA', password='masterke', charset='utf8')

tx=conn.trans()
xcur=tx.cursor()

p_list = [
('57F2B8C7-E1D8-4B61-9086-C66D1794F2D9', 111),
('77F2B8C7-E1D8-4B61-9086-C66D1794F2D9', 222),
]

xcur.executemany("insert into test_uuid(uuid, datavalue) values( char_to_uuid(?), ?)", p_list)

xcur.close()
tx.rollback()
conn.close()

Then launch TRACE and do: python <this_script.py>.
Output in trace will be:

2016-01-05T23:41:22.7180 (876:00C33418) PREPARE_STATEMENT ---------------------------------------------- #⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠ [ 1 ] #⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠
e30 (ATT_318, SYSDBA:NONE, UTF8, TCPv4:127.0.0.1)
C:\Python27\python.exe:3760
(TRA_346, READ_COMMITTED | REC_VERSION | WAIT | READ_WRITE)

Statement 28:
-------------------------------------------------------------------------------
insert into test_uuid(uuid, datavalue) values( char_to_uuid(?), ?)
6 ms

2016-01-05T23:41:22.7180 (876:00C33418) EXECUTE_STATEMENT_START
. . .

2016-01-05T23:41:22.7180 (876:00C33418) EXECUTE_STATEMENT_FINISH
. . .
Table Natural Index Update Insert Delete Backout Purge Expunge
***************************************************************************************************************
TEST_UUID 1

2016-01-05T23:41:22.7180 (876:00C33418) PREPARE_STATEMENT ---------------------------------------------- #⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠ [ 2 ] #⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠
e30 (ATT_318, SYSDBA:NONE, UTF8, TCPv4:127.0.0.1)
C:\Python27\python.exe:3760
(TRA_346, READ_COMMITTED | REC_VERSION | WAIT | READ_WRITE)

Statement 29:
-------------------------------------------------------------------------------
insert into test_uuid(uuid, datavalue) values( char_to_uuid(?), ?)
0 ms

2016-01-05T23:41:22.7180 (876:00C33418) EXECUTE_STATEMENT_START
. . .

2016-01-05T23:41:22.7180 (876:00C33418) EXECUTE_STATEMENT_FINISH
. . .
Table Natural Index Update Insert Delete Backout Purge Expunge
***************************************************************************************************************
TEST_UUID 1

One may see that PREPARE was made two times which is equal to the number of parameter tuples.
But documentation ( http://www.firebirdsql.org/file/documentation/drivers_documentation/python/fdb/reference.html#cursor ) issues:

This function simply calls execute() in a loop, feeding it with parameters from seq_of_parameters. Because execute caches PreparedStatements, calling executemany is equally efective as direct use of prepared statement and calling execute in a loop directly in application.

Commits: a0a5f38 FirebirdSQL/fbt-repository@f394b02

@firebird-automations
Copy link
Author

Commented by: @pcisar

This was a side effect of change in 1.4.2 that dropped support for PreparedStatement cache in Cursor.

@firebird-automations
Copy link
Author

Modified by: @pcisar

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: 1.5 [ 10642 ]

@firebird-automations
Copy link
Author

Modified by: @pcisar

status: Resolved [ 5 ] => Closed [ 6 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants