Jakub,

the "official" sqlite version isn't broken, it's the WinCE port that is.

I decided to announce that in the SQLite-WinCE page so people wouldn't
expect it to just work. There are other issues with the WinCE port (like
the Unicode handling, and that is also in the official version), but
this is serious enough because it crashes (with a stack overflow
exception) after inserting just 113 rows (and always 113 rows).

My guess is that the official version allocated too much stack space,
resulting in that exception.

-------

I now have tested the same program with SQLite v3.0.5 (inserted 50000
rows) and the problem disappeared. So something was corrected in the source code that makes it use less stack.


I would advise you to wait until I
commit those changes to CVS and make a new release so you can try by
yourself.

I annexed your test program (with your bugs corrected), so you can check it works now.

Regards,
~Nuno Lucas

/***** BUG: the right header to include is "sqlite3.h".
       "sqliteint.h" is an internal header and can't be used safelly */
/*****/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <sqlite3.h>


bool TestExecuter( sqlite3 *db_hnd, char *query, ... )
{
//      char **_result_set;
//      int _n_row=0;
//      int _n_col=0;
//      char *_error_msg;

        va_list tmp_args;
        va_start( tmp_args, query );
        char *tmp_query = sqlite3_vmprintf( query, tmp_args );

        sqlite3_stmt * stmt = 0;
        const char* tail;

//      int tmp_ec = sqlite3_get_table( db_hnd, tmp_query, &_result_set, &_n_row, 
&_n_col, &_error_msg );

        if ( sqlite3_prepare( db_hnd, tmp_query, strlen(tmp_query), &stmt, &tail ) )
        {
                OutputDebugString( _T("sqlite3_prepare: error\n") );
                return false;
        }

        int rc = sqlite3_step( stmt );
        switch ( rc )
        {
        case SQLITE_ROW :       // First row ready
                                                break;
        case SQLITE_DONE:       // Ok, simply no results for this command
                                                break;
        default                 :       // Some error
                                                OutputDebugString( 
(LPCWSTR)sqlite3_errmsg16(db_hnd) );
        }

        rc = sqlite3_finalize( stmt );
        if ( rc != SQLITE_OK )
                OutputDebugString( (LPCWSTR)sqlite3_errmsg16(db_hnd) );

        // Libero la query.
        sqlite3_free(tmp_query);

        /****** BUG: no release of result set */
//      sqlite3_free_table( _result_set );
        /******/

//      if ( (_n_row == -1) || (_error_msg != NULL) )
//      {
//              TCHAR buf[512];
//              _stprintf( buf, _T("Query Failed! - errmsg: %hs\n"), _error_msg );
//              OutputDebugString( buf );
//              /****** BUG: no release of error message */
//              sqlite3_free( _error_msg );
//              /******/
//      }
// speedup things while testing
//      else
//              OutputDebugString( "Query Ok!\n" );

        /****** BUG: no va_end(tmp_args) */
        va_end( tmp_args );
        /******/

//      return (_n_row == -1) || (_error_msg != NULL);
        return rc == SQLITE_OK;
}

int Test_Insert2(sqlite3 *db_hnd)
{
        // Create some tables with data that we can select against
        TestExecuter( db_hnd, "CREATE TABLE d1(n int, log int)" );
        TestExecuter( db_hnd, "BEGIN" );
        char tmp_str[256];
        for (int i=1;i<=50000;i++)
        {
//              for ( int j=0; (1 << j) < i; j++ )
                {
                        sprintf(tmp_str,"INSERT INTO d1 VALUES(%d,%d)",i,i);
                        TestExecuter( db_hnd, tmp_str );
                }
        }
        TestExecuter( db_hnd, "END" );
        TestExecuter( db_hnd, "SELECT * FROM d1 ORDER BY n" );

        // finish_test
        return 0;
}


#define DB_TEST         "\\Test.db"


int WINAPI WinMain( HINSTANCE,HINSTANCE,LPTSTR,int )
{
        sqlite3 * db;
        int err = sqlite3_open( DB_TEST, &db );
        if ( err )
                return -1;
        Test_Insert2( db );

        /**** BUG: no sqlite3_close can eventually corrupt the database */
        sqlite3_close( db );
        /****/
        return 0;
}

Reply via email to