1
0
Fork 0
mirror of https://github.com/DBD-SQLite/DBD-SQLite synced 2025-06-07 14:19:10 -04:00
This commit is contained in:
Björn Höhrmann 2024-11-25 22:53:00 +00:00 committed by GitHub
commit 6d7f69423e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 58 additions and 0 deletions

View file

@ -175,6 +175,20 @@ _sqlite_exec(pTHX_ SV *h, sqlite3 *db, const char *sql)
return rc;
}
static void
_sqlite_log_callback(void *unused, int error_code, const char *message)
{
dTHX;
SV* drh = get_sv("DBD::SQLite::drh", 0);
if (drh && SvOK(drh)) {
D_imp_drh(drh);
sqlite_trace(NULL, imp_drh, 3, form("sqlite3_log %d, %s", error_code, message));
}
}
int
_sqlite_open(pTHX_ SV *dbh, const char *dbname, sqlite3 **db, int flags, int extended)
{
@ -430,6 +444,27 @@ sqlite_init(dbistate_t *dbistate)
{
dTHX;
DBISTATE_INIT; /* Initialize the DBI macros */
#if SQLITE_VERSION_NUMBER >= 3006023
/*
* "The sqlite3_config() interface may only be
* invoked prior to library initialization using
* sqlite3_initialize() or after shutdown by
* sqlite3_shutdown()."
* -- https://sqlite.org/c3ref/config.html
*/
sqlite3_config(SQLITE_CONFIG_LOG, _sqlite_log_callback, NULL);
#endif
/*
* "For maximum portability, it is recommended that
* applications always invoke sqlite3_initialize()
* directly prior to using any other SQLite interface.
* Future releases of SQLite may require this."
* -- https://sqlite.org/c3ref/initialize.html
*/
sqlite3_initialize();
}
int

23
t/68_sqlite3_log.t Normal file
View file

@ -0,0 +1,23 @@
use strict;
use warnings;
use lib "t/lib";
use SQLiteTest qw/connect_ok requires_sqlite/;
use Test::More;
use if -d ".git", "Test::FailWarnings";
BEGIN { requires_sqlite('3.6.23') }
open my $trace_fh, '>', \my $trace_string;
DBI->trace(3, $trace_fh);
my $dbh = connect_ok(PrintError => 0, RaiseError => 1);
eval {
$dbh->selectrow_array(q{ SELECT FROM FROM });
};
like $trace_string, qr/sqlite3_log/,
'sqlite3_log messages forwarded to DBI tracing mechanism';
done_testing;