Abshagen, Martin RD-AS41 <[EMAIL PROTECTED]> writes:
>
> Hi,
>
> I wrote the following simple test and wonder why sqlite_bind_parameter_count()
returns the value 2 (as
> expected) while the subsequent four sqlite_bind_parameter_*() functions all
return 0.
> I tried it with sqlite3 versions 3.6.1 and 3.6.6, so I think there is a simple
explanation to be found in my code.
>
> Best regards
> Martin.
>
> int execute( sqlite3* i_db, const char* i_sql )
> {
> char* sErrMsg = 0;
>
> int ret = sqlite3_exec( i_db, i_sql, 0, 0, &sErrMsg );
> if( ret != SQLITE_OK ) {
> printf( sErrMsg );
> sqlite3_free( sErrMsg );
> return( -1 );
> }
> return( 0 );
> }
>
> char sSqlCreate[] = "CREATE TABLE IF NOT EXISTS Table0 (sKey VARCHAR(20) NOT
NULL PRIMARY KEY, sVal VARCHAR(200))";
> char sSqlPrepareWrite[] = "INSERT INTO Table0
";
>
> int TestDirectWritePrepared( )
> {
> sqlite3* hDb;
> sqlite3_stmt* stmt;
> int ret = 0;
> const char* p;
> int i = SQLITE_VERSION_NUMBER;
> // for( i = 0; i < 10; ++i ) {
> ret = sqlite3_open( "MYTEST1", &hDb );
>
> ret = execute( hDb, "BEGIN TRANSACTION CREATE_TABLE" );
> ret = execute( hDb, sSqlCreate );
> ret = execute( hDb, "COMMIT TRANSACTION CREATE_TABLE" );
>
> ret = sqlite3_prepare_v2( hDb, sSqlPrepareWrite, -1, &stmt, 0 );
> ret = sqlite3_bind_parameter_count( stmt );
> ret = sqlite3_bind_parameter_index( stmt, "sKey" );
> ret = sqlite3_bind_parameter_index( stmt, "sVal" );
> p = sqlite3_bind_parameter_name( stmt, 1 );
> p = sqlite3_bind_parameter_name( stmt, 2 );
> return( 0 );
> }
>
Your bind parameters VALUES (?, ?) have not been given names,
see http://www.sqlite.org/c3ref/bind_parameter_name.html
"Parameters of the form "?" without a following integer have no name and are
also referred to as "anonymous parameters"."
RTFM ?!
Cheers,
MikeW
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users