On 7/06/2009 11:38 AM, P Kishor wrote:
> On Sat, Jun 6, 2009 at 8:28 PM, Kelly Jones<kelly.terry.jo...@gmail.com> 
> wrote:
>> On 6/6/09, P Kishor <punk.k...@gmail.com> wrote:
>>> On Sat, Jun 6, 2009 at 1:43 PM, Kelly Jones<kelly.terry.jo...@gmail.com>
>>> wrote:
>>>> I have a text file onenum.txt with just "1234\n" in it, and a db w/
>>>> this schema:
>>>>
>>>> sqlite> .schema
>>>> CREATE TABLE test (foo INTEGER PRIMARY KEY);
>>>>
>>>> When I import, it fails as follows:
>>>>
>>>> sqlite> .import onenum.txt test
>>>> Error: datatype mismatch
>>>>
>>>> Is sqlite3 treating "1234" as a string or something? Short of doing
>>>> "INSERT INTO test VALUES (1234);", how do I import numbers into
>>>> sqlite3's rowid column? [1]
>>> Remove the "\n"
>> Er, by "\n", I just meant that the file ended in a newline. I didn't
>> literally type a backslash and an 'n' into the file.
> 
> 
> Yes, I understand what you meant. If there is a newline, sqlite tries
> to import it, and that doesn't fit into the INTEGER PRIMARY KEY
> categorization, hence the datatype mismatch error.

If there is a newline?? There should be a newline at the end of each 
line of the file; with luck the reader will not complain if the final 
newline is missing.

Expected behaviour for various raw file contents:

1234 => one row, ok (with luck)
1234\n => one row, ok
1234\n\n => first row ok, 2nd is empty, expect error message
1234\n5678 => two rows, ok (with luck)
1234\n5678\n => two rows, ok

> So, the following
> fails (I am typing bogus lines to indicate the newline
> ------
> 1234
> 
> ------
> 
> while the following imports just fine
> ------
> 1234
> ------

Simply: avoid having empty or blank lines in the .import file, 
especially at the end, where they're not obvious.

IMHO that error message is carrying "Lite" a little too far; some prefix of:
     data mismatch in line 2, column 1 (foo): expected integer, found ''
might save some wear and tear on the help desk :-)

Cheers,
John


_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to