> 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
------------------------------
Thank you!
I have try to bind like this:
sqlite3_bind_blob( stat, 1, pName, strlen(pName), 0 );
binding a blob and specifying a length of *two* and still can not select
the record I want by " select * from tbl1 where name ='aa' ",
I think maybe I should use: sqlite3_bind_text( ),
because this column type is a string. I will try last week!
yoky
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users