perl5-dbi / dbi

DBI - The Perl 5 Database Interface
Other
83 stars 58 forks source link

Driver 'do' versus dbi_profile #68

Open hoehrmann opened 6 years ago

hoehrmann commented 6 years ago

dbi_profile does not capture the current statement when drivers do not funnel do through a separate statement object. For instance, this is broken:

DBI_TRACE=4 \
  DBI_PROFILE='!Statement:!MethodName:!Caller/DBI::Profile' \
  perl -MDBI -e '
    my $dbh = DBI->connect("dbi:SQLite:dbname=:memory:");
    local $dbh->{sqlite_allow_multiple_statements} = 0;
    $dbh->do("CREATE TABLE IF NOT EXISTS X(Y INT);");
    $dbh->do("DELETE FROM X");'

This profiles the second do with the empty string as statement. For the first one the behavior is as expected because DBD::SQLite routes that through prepare et al. With DBD::Pg instead, you get an empty string for both statements (I suspect for similar reasons, but haven't checked).

If drivers are not supposed to skip prepare/execute on specialised do implementations, could this be noted in the DBI::DBD documentation?

hoehrmann commented 3 years ago

Not sure if anything has changed here since, but running into this again I noticed that DBD::SQLite would not take the shortcut if the second argument to do is defined, but passing {} did not actually help because dbi_profile returns early when it notices the DBI calls are not from application code. So it is not clear to me that drivers actually have a chance to make this work properly. Removing the caller-logic from dbi_profile then did the trick.