I assume then that the constraint you're trying to satisfy is "don't insert a
non-integer string into an integer field", right?
Then do this:
sqlite> create table t2(n integer check(round(n) = n));
sqlite> insert into t2 values('-5');
sqlite> insert into t2 values('q');
Error: constraint failed
sqlite> insert into t2 values('5 with more stuff');
Error: constraint failed
Michael D. Black
Senior Scientist
Northrop Grumman Mission Systems
________________________________
From: [email protected] on behalf of Alexey Pechnikov
Sent: Thu 4/29/2010 8:59 AM
To: General Discussion of SQLite Database
Subject: Re: [sqlite] CHECK constraints and type affinity
Do you want produce SQL-injections security holes? When database
engine can convert datatypes on demand we may quoting all values from
web forms and all other external sources. Note: variable binding is
impossible for dynamically created views, triggers, etc. And modern
languages can use string representation of variables in SQLite
bindings.
2010/4/29 Black, Michael (IS) <[email protected]>:
> Get rid of the quotes in your values.
>
> sqlite> create table t2(n integer check(typeof(n)='integer'));
> sqlite> insert into t2 values('5');
> Error: constraint failed
> sqlite> insert into t2 values(5);
> sqlite> select n from t2;
> 5
--
Best regards, Alexey Pechnikov.
http://pechnikov.tel/
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users