开发者

SQLite where clause acting strange with TEXT fields

开发者 https://www.devze.com 2023-04-10 04:07 出处:网络
I\'ve searched up and down sqlite.org and can\'t figure this one out. I\'m used to MySQL so I think maybe I am overlooking something.

I've searched up and down sqlite.org and can't figure this one out. I'm used to MySQL so I think maybe I am overlooking something.

See the following code:

sqlite> select id,event_number,must_say from events where id=28;
28|'28'|'AFK'
sqlite> select id,event_number,must_say from events where must_say='AFK';
sqlite> select id,event_number,must_say from events where must_say like 'AFK';
sqlite> select id,event_number,must_say from events where must_say like 'A%';
sqlite> select id,event_number,must_say from events where must_say=='AFK';
sqlite>

Needless to say, I really was expecting the following to be returned for ALL of the above queries, not just the first one:

28|'28'|'AFK'

I'm getting this behavior on all TEXT fields. It seems I can't search at all.

Here is the schema of my events table, with the irrelevant fields omitted:

CREATE TABLE even开发者_JAVA百科ts (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    EVENT_NUMBER INTEGER,
    MUST_SAY TEXT
);

Any ideas? I just want to be able to search by arbitrary text fields in the table.

Edit: I'm using SQLite3.


You may also have whitespace in your columns.

You can see spaces with

select '|' || must_say || '|' from events

You can see unprintables with

select hex(must_say) from events
0

精彩评论

暂无评论...
验证码 换一张
取 消