Try instead of "SELECT * FROM table WHERE name LIKE ?" as your sql query,
"SELECT * FROM table WHERE name LIKE :comparison"


Thomas Zangl wrote:
Vitali Lovich schrieb:
Regarding your code snippet:

// SQL Statement is: "SELECT * FROM table WHERE name LIKE ?"
search = '%test%';
sqlite3_bind_text(prepared_statement, 0,search , search , SQLITE_STATIC);

First I'm not sure what language you're using - it seems Perl-like.

Anyways, the documentation for http://www.sqlite.org/capi3ref.html#sqlite3_bind_text gives the 4th param as the number of bytes (not chars) while you're passing the original string. Since I'm assuming it's Perl, it won't generate an error on the type mismatch. You generally want to pass -1 for the fourth parameter (from what I understand, -1 is always safe for sqlite3_bind_text). Also, take care in using SQLITE_STATIC and make sure that the string you pass remains on the heap (i.e. delete isn't called, not sure if this is possible in Perl) or the stack (i.e. local variable in scope) when you execute the statement.
Its C :-)

Anyway, I tried your suggestion and free the char* after sqlite3_finalize. Does not help.
  char* sql_parameter_search = '%test%'
rc = sqlite3_bind_text(prepared_statement, 1,
sql_parameter_search, strlen(sql_parameter_search), SQLITE_STATIC);
sql_check_result(rc);
logDebug("Added search = %s", sql_parameter_search);

the result is:

Added search = %test%
my_sqlite_logger-SQLITE said: (0) SELECT * FROM table WHERE name LIKE ?


So - no variable substitution done?

Somebody with a working LIKE example?

TIA,

Thomas

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------



-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to