Issue Details (XML | Word | Printable)

Key: PYFB-60
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Pavel Cisar
Reporter: Pavel Zotov
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Firebird driver for Python

Cursor: executemany(operation, seq_of_parameters) does PREPARE of <operation> for each parameter from <seq_of_parameters>

Created: 05/Jan/16 08:56 PM   Updated: 15/Feb/17 12:02 PM
Component/s: None
Affects Version/s: 1.4.3
Fix Version/s: 1.5


 Description  « Hide
/*
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.
===

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Pavel Cisar added a comment - 06/Jan/16 10:21 AM
This was a side effect of change in 1.4.2 that dropped support for PreparedStatement cache in Cursor.