On 2015/01/16 18:33, Simon Slavin wrote:
(following description simplified)
I have a text file I wanted to .import into a table. The text file has two
columns separated by a tab: a word and a number. It starts off like this:
! 32874624
" 239874242
# 98235252
$ 438743824
% 324872489
& 39854724
a 23498725
i 1298371287
as 23194874
at 3598725
and continues for another 13588392 (sic.) rows.
I use the SQLite shell tool. I create an appropriate table in my database, set
.separator to "\t" and use .import.
The .import failed because the second line of the file contains a quote
character. I'm okay with the fact that it fails: it's documented, or nearly
documented.
However, the failure message is this:
Error: mytextfile.txt line 13588392: expected 2 columns of data but found 1
Naturally I spent some time looking near the end of the file to figure out what was wrong
where the actual error was in line 2, and should have read something like "still
inside quote when file ends".
Firstly - thanks, this made me chuckle. Secondly - I think the parser does not realize there is an error until it is at the end of
the file nor counts any imports as successful or indeed imported at all, since that first line will very much not be imported after
the transaction was rolled back (I hope), so to report the successful imports number is probably not feasible. Stating that the
error was specifically due to this or that might also be a stretch if one examines the number of possible things that can go wrong.
I do however believe it would be easy to note the line at which the import failed as being the line where parsing started for the
current record (i.e line 2 in Simon's case), but then it may well be the error actually occurs on line 13588392 (such as an invalid
UNICODE character), reporting line 2 in this case will be diabolical.
Last I would offer an idea to simply specifically check for "Unclosed Quote" error. I mean I can't imagine another import like the
one above existing in real life, but certainly an actual unclosed quote might be a common mistake in some new export system (which
maybe one is designing for oneself or as an application extension) or such.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users