On 7/06/2009 11:28 AM, Kelly Jones 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.
> 
> Note there's only line in the entire file, so there are no duplicates
> or misformatted entries.

I can't reproduce your problem. If you can reproduce it, show us a 
verbatim transcript of your session, preferably obtained by copy/paste 
and including an *unambiguous* dump of the file contents, together with 
platform details.

E.g.
[Windows XP SP2, SQLite version 3.6.14]

| C:\junk>copy con onenum.txt
| 1234
| ^Z
|         1 file(s) copied.
|
| C:\junk>type onenum.txt
| 1234
|
| C:\junk>python -c "print repr(open('onenum.txt', 'rb').read())"
| '1234\r\n'
|
| C:\junk>sqlite3 test.db
| SQLite version 3.6.14
| Enter ".help" for instructions
| Enter SQL statements terminated with a ";"
| sqlite> CREATE TABLE test (foo INTEGER PRIMARY KEY);
| sqlite> .schema
| CREATE TABLE test (foo INTEGER PRIMARY KEY);
| sqlite> .import onenum.txt test
| sqlite> select rowid, foo, typeof(foo) from test;
| 1234|1234|integer
| sqlite> ^Z
|
| C:\junk>

Did I hear a mutter about the '\r' above?

| C:\junk>python -c "open('onenum2.txt', 'wb').write('1234\n')"
|
| C:\junk>python -c "print repr(open('onenum2.txt', 'rb').read())"
| '1234\n'
|
| C:\junk>sqlite3 test2.db
| SQLite version 3.6.14
| Enter ".help" for instructions
| Enter SQL statements terminated with a ";"
| sqlite> CREATE TABLE test (foo INTEGER PRIMARY KEY);
| sqlite> .schema
| CREATE TABLE test (foo INTEGER PRIMARY KEY);
| sqlite> .import onenum2.txt test
| sqlite> select rowid, foo, typeof(foo) from test;
| 1234|1234|integer
| sqlite> ^Z
|
| C:\junk>

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

Reply via email to