Alexey,

I can certainly tell you what is causing this behaviour:

When sqlite does a comparison, it checks the *column* affinity from both 
sides.  In your example, neither sides come from a column, but are 
constants.  Therefore, sqlite uses the NONE affinity on comparison (I 
think, but I haven't checked, therefore doing a binary comparison).  If 
both sides of the comparison are columns, then it will choose a 
"best-match" affinity; if only one side is from a column it will use the 
affinity from that column.  For reference, have a look at the function 
'sqlite3CompareAffinity' in expr.c.

However, you can fool it using...

select cast(1 as integer)='1'

This works because the cast operator assigns an affinity and therefore, 
since one side has an assigned affinity, the comparison does the 
conversion of the second side.  Plus it adds only a single op to the vdbe 
code, which turns out as an almost no-op since it is integer already.

Now, it is probable that the core can be patched as you request by 
assigning affinity to constants during parsing, but I haven't had an 
opportunity to look into it and I would have to check very thoroughly that 
it will not brake something else if I do patch it for you.  At this 
precise moment, I cannot look into it for you, but maybe later in the week 
I will have time.

Kind regards
Will


Alexey Pechnikov <pechni...@mobigroup.ru> wrote on 28/02/2010 19:41:31:

> Alexey Pechnikov <pechni...@mobigroup.ru> 
> 28/02/2010 19:42
> 
> Bitte antworten an
> pechni...@sandy.ru
> 
> An
> 
> wcl...@gfs-hofheim.de
> 
> Kopie
> 
> Thema
> 
> The SQLite datatyping problem
> 
> Hello!
> 
> I did fix the tclsqlite typing as decribed here: http://
> sqlite.mobigroup.ru/src/wiki?name=tclsqlite
> But there is the core SQLite problem:
> 
> In PostgreSQL we get
> offline1=# select 1='1';
>  ?column? 
> ----------
>  t
> 
> And in SQLite it's wrong
> sqlite> select 1='1';
> 0
> 
> May be you know how to fix SQLite core for providing the correct 
behaviour?
> 
> Best regards, Alexey Pechnikov.
> http://pechnikov.tel/
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to