SQLite Forum

sqlite3_bind_() problem I do not understand
Login
Hi, I am new to writing code using the amalgamation in c++ builder.

My problem is this, I send this sql "SELECT Name, Composer FROM tracks WHERE Name LIKE :p0 AND AlbumId = :p1" to  

int rc = sqlite3_prepare_v2(_db, UTF8String(sql).c_str(), -1, &stmt, NULL);

this returns SQLITE_OK, after this, without explaining everything, Id o the following  

for(int i = 0; i < c; i++)
  {
  _val = Params[i]->ParamValue;
  dataType = op->GetSQLiteBindTypeValue(Params[i]->ColumnType);
  rc = Bind(dataType /*tText*/, stmt, i+1, UTF8String(_val).c_str());
  _expandedStmt = sqlite3_expanded_sql(stmt);
  }

Ok, this works fine for the number of parameters added to a vector of parameters, column data types are pre determined and works correctly, dataType reflects the column type from the database itself.

the Bind( ... ) method works fine it returns SQLITE_OK as does the actual binding statement used in the Bind ( ... ) method i.e;

rc = sqlite3_bind_text( stmt, valueCount, (char*)value.c_str(), -1, SQLITE_STATIC); 

I acknowledge that this may not be correct and that is why I am here but, my issue is that calling sqlite3_expanded_sql(stmt);

shows something like this;

"SELECT Name, Composer FROM tracks WHERE Name LIKE '98' AND AlbumId = 98"

This is not correct as both parameter markers have been replaced with the same last value,

Stepping through the code at run time, binding the first value is ok and shows

"SELECT Name, Composer FROM tracks WHERE Name LIKE 'p%' AND AlbumId = NULL"

it is on the 2nd bind operation that the first parameter place holder gets the same value as the last, I can't work out why so, HELP, what am I doing wrong??