Sha256: c2a2381ee727b968cc2bc63d0cd2af47fc53c45f4dc93146df83b5428f49c5a4
Contents?: true
Size: 1.75 KB
Versions: 6
Compression:
Stored size: 1.75 KB
Contents
#include <stdio.h> #include <stdlib.h> #include "sqlite3.h" /** * gcc -o test_error test_error.c sqlite3.c * ./test_error */ int test_progress_callback( void* data ) { fprintf(stderr, "Progress handler callback\n"); return 1; } void abort_if_error( sqlite3* db, char* msg, int rc ) { if ( SQLITE_OK != rc ) { fprintf( stderr, "%s: [%d] -> %s\n", msg, sqlite3_errcode( db ), sqlite3_errmsg( db ) ); sqlite3_close( db ); exit( 1 ); } } int main( int argc, char **argv ) { sqlite3 *db; sqlite3_stmt *stmt; const char *tail; char *errmsg; int rc; printf("SQLite Version: %s\n", sqlite3_libversion() ); rc = sqlite3_open_v2( ":memory:", &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL ); abort_if_error( db, "Failure opening database", rc ); rc = sqlite3_exec( db, "CREATE TABLE t1( c1, c2 );", NULL, NULL, NULL ); abort_if_error( db, "Failure creating table t1", rc ); sqlite3_progress_handler( db, 5, test_progress_callback, (void*) NULL ); rc = sqlite3_prepare_v2( db, "SELECT * FROM t1", -1, &stmt, &tail ); abort_if_error( db, "Failure preparing statement", rc ); rc = sqlite3_step( stmt ); if ( SQLITE_ROW != rc ) { printf( "Return code from sqlite3_step : %d\n", rc ); printf( "Before finalizing error code is : %d\n", sqlite3_errcode( db )); printf( "Before finalizing error message is : %s\n", sqlite3_errmsg( db )); } rc = sqlite3_finalize( stmt ); if ( SQLITE_OK != rc ) { printf( "Return value from sqlite3_finalize : %d\n", rc ); printf( "After finalizing errcode is : %d\n", sqlite3_errcode( db )); printf( "After finalizing error message is : %s\n", sqlite3_errmsg( db )); } sqlite3_close( db ); return 0; }
Version data entries
6 entries across 6 versions & 1 rubygems