On Wed, Jan 04, 2006 at 03:54:49PM -0500, Mark Wyszomierski wrote:
> Hi all,
> 
> I switched to sqlite from mysql awhile ago, I maintained the field types
> in my sqlite implementation such as:
> 
>     create table students (first_name TEXT, age INTEGER);
> 
> I'm just wondering if there is any point to specifying the field type as if
> I try adding a string type into the age field, it seems to be accepted ok:
> 
>     insert into students values('hello');
> 
> Does sqlite have any problem regarding setting a field defined as INTEGER
> from a text string (any limits etc?), are there any performance gains to be
> had with specifying the field type?

Well, what's actually happening is that since you didn't supply a value
for age, it's being set to NULL. While that's fine for testing and
what-not, in your code you should really provide a list of fields that
you're inserting into, so there's no ambiguity. IE:

INSERT INTO students(first_name) VALUES('John');

As for inserting text into an int, presumably it will cast it if it can.
So 

INSERT INTO students(age) VALUES('John');

would fail, but

INSERT INTO students(age) VALUES('18');

should work. Of course, you're ultimately just making the database do
more work; you should really just insert the int as an int and be done
with it...

INSERT INTO students(age) VALUES(18);
-- 
Jim C. Nasby, Sr. Engineering Consultant      [EMAIL PROTECTED]
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

Reply via email to