On Fri, Oct 31, 2008 at 9:06 AM, yoky <[EMAIL PROTECTED]> wrote:

> Hi all,
>        I create a table like this "create table tbl1 (ID integer primary
> key, name, addr)" ,
>        then insert a record:
>           "insert into tbl1 values(1, 'aa', 'bb')",
>       select the record:
>           "select * from tbl1 where name ='aa' "   ,can get this  record :
> (1, 'aa', 'bb')
>       I change insert way like this:
>           char *pName = "aa";
>           sqlite3_prepare(db," insert into tbl1(1,?,'bb')",-1, &stat, 0);
>           sqlite3_bind_blob( stat, 1, pName,  strlen(pName)+1, 0 );
>           sqlite3_step(stat);
>       Then select the record:
>           sqlite3_prepare(db,  "select * from tbl1 where name ='aa' ", -1,
> &stat, 0);
>            sqlite3_step(stat);
>       By this way, I can not get the record I want : (1, 'aa', 'bb').
>       Change the SQL statement by  "like":
>           sqlite3_prepare(db,  "select * from tbl1 where name  like  'aa'
> ", -1, &stat, 0);            sqlite3_step(stat);
>      I can get the record.
>      Why? and How can I select record by "=" condition to a string?


You are binding a blob and specifying a length of *three*.  strlen(pName)
returns 2 which is the proper length, but you're adding 1 to that.
Therefore the column contains three characters, 'a', 'a', '\0' which does
not equal "aa" but does begin with "aa".

So you want to either use the correct length for the blob (assuming you
really need blobs) or bind a type other than blob.

Derrell
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to