Skip to content

Commit

Permalink
fixed SQLITE_TRACE_CLOSE processing, thanks to @snaiperis
Browse files Browse the repository at this point in the history
  • Loading branch information
tuffnatty committed Nov 16, 2023
1 parent 10a7474 commit f624bf1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
13 changes: 10 additions & 3 deletions contrib/hbsqlit3/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1832,19 +1832,26 @@ static int trace_handler( unsigned uType, void *cbTraceHandler, void * p, void *
hb_vmSend( 3 );
break;
case SQLITE_TRACE_ROW:
{
HB_SYMBOL_UNUSED( x );
hb_vmPushPointer( p );
hb_vmSend( 2 );
break;
}
case SQLITE_TRACE_CLOSE:
{
PHB_ITEM pItem = hb_itemNew( NULL );
hb_sqlite3_itemPut( pItem, p, HB_SQLITE3_DB );
HB_SQLITE3 * hbsqlite3 = ( HB_SQLITE3 * ) hb_xgrabz( sizeof( HB_SQLITE3 ) );
HB_SYMBOL_UNUSED( x );

hbsqlite3->db = p;
hb_sqlite3_itemPut( pItem, hbsqlite3, HB_SQLITE3_DB );
hb_vmPush( pItem );
hb_vmSend( 2 );

/* We don't want sqlite3_close() called recursively
* and don't want to implement a weak reference engine yet
* so we just clear the pointer before hb_itemRelease(). */
hbsqlite3->db = NULL;
hb_itemRelease( pItem );
break;
}
}
Expand Down
19 changes: 11 additions & 8 deletions contrib/hbsqlit3/tests/backup.prg
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,22 @@
#include "fileio.ch"


PROCEDURE init_trace( pDbDest, cPrefix )
PROCEDURE init_trace( pDb, cPrefix )
LOCAL hFile
IF sqlite3_libversion_number() < 3014000
sqlite3_trace( pDbDest, .T., cPrefix + ".log" )
sqlite3_trace( pDb, .T., cPrefix + ".log" )
ELSE
hFile := FOpen( cPrefix + ".log", FO_READWRITE + HB_FO_CREAT )
FSeek( hFile, 0, FS_END )
sqlite3_trace_v2( pDbDest, SQLITE_TRACE_STMT, {| nMask, pPreparedStatement, cOriginalSql |
HB_SYMBOL_UNUSED( nMask )
IF hb_LeftEq( cOriginalSql, "--" )
FWrite( hFile, cOriginalSql + hb_eol() )
ELSE
FWrite( hFile, sqlite3_expanded_sql( pPreparedStatement ) + hb_eol() )
sqlite3_trace_v2( pDb, SQLITE_TRACE_STMT + SQLITE_TRACE_CLOSE, {| nMask, p, x |
IF nMask == SQLITE_TRACE_STMT /* p is pPreparedStatement, x is cOriginalSql */
IF hb_LeftEq( x, "--" )
FWrite( hFile, x + hb_eol() )
ELSE
FWrite( hFile, sqlite3_expanded_sql( p ) + hb_eol() )
ENDIF
ELSEIF nMask == SQLITE_TRACE_CLOSE /* p is the database connection */
FWrite( hFile, "Closing the database connection" + hb_eol() )
ENDIF
RETURN 0
} )
Expand Down

0 comments on commit f624bf1

Please sign in to comment.