Bug 20591 - DBI->last_insert_id does not work as expected
Summary: DBI->last_insert_id does not work as expected
Status: NEW
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low normal (vote)
Assignee: Bugs List
QA Contact: Testopia
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-04-16 16:41 UTC by Jonathan Druart
Modified: 2018-04-16 18:27 UTC (History)
3 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Bot Control: ---
When did the bot last check this:
Who signed the patch off:
Text to go in the release notes:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Druart 2018-04-16 16:41:34 UTC
Try the following code:

use Koha::Database;
use Koha::Cities;
use Koha::AuthorisedValues;
my $schema = Koha::Database->schema;
$schema->storage->txn_begin;
my $dbh = C4::Context->dbh;

my $city = Koha::City->new({ city_name => 'name' })->store;
say $city->cityid;
say $dbh->last_insert_id( undef, undef, 'cities', undef );
say $dbh->last_insert_id( undef, undef, 'not_exist', undef );

say "===";
my $av = Koha::AuthorisedValue->new({category => 'LOC', authorised_value => 'just_a_test'})->store;
say $av->id;
say $dbh->last_insert_id( undef, undef, 'authorised_values', undef );
say $dbh->last_insert_id( undef, undef, 'cities', undef );
say $dbh->last_insert_id( undef, undef, 'not_exist', undef );

It will display:
12
12
12
===
401
401
401
401
Comment 1 Jonathan Druart 2018-04-16 16:42:54 UTC
I do not have time to investigate this right now, but there is something scary. It could lead to very bad side-effects.
Comment 2 Jonathan Druart 2018-04-16 18:26:29 UTC
Sounds like the only place it is buggy is t/db_dependent/Circulation/issue.t
No problematic occurrences found in controllers or modules.
Comment 3 Jonathan Druart 2018-04-16 18:27:05 UTC
From DBI POD:

"""
* For some drivers the $catalog, $schema, $table, and $field parameters are required, for others they are ignored (e.g., mysql).
"""