简体   繁体   中英

weird results using sqlite3 from c++ and console

Why could be the cause be for this behavior ? I'm missing something?

I'm not pretty sure why this is happening, i guess is kind of a bug in SQLite3

I had exported a CSV file from a result of SQL2008 the file looks like this ( "time" is the first column) :

1,1000,1000,1000,1000,0
1069545600,1000,1000,1000,1000,0
1070150400,1000,1000,1000,1000,0
1070755200,1000,1000,1000,1000,0
1071360000,1000,1000,1000,1000,0
1071964800,1000,1000,1000,1000,0
1072569600,1000,1000,1000,1000,0
1072915200,1000,1000,1000,1000,0
1073174400,1000,1000,1000,1000,0
1073779200,1000,1000,1000,1000,0
....

I imported then to a sqlite3 table using ".separator ," and then ".import file.csv data"

then i issue the following SQL statement from a C++ program :

SELECT time, open, high, low, close, volume FROM data ORDER BY time DESC

but the result shows me the first row with "time == 1" and it should be the last to show.

sqlite> SELECT time, open, high, low, close, volume FROM data ORDER BY time DESC LIMIT 50;
1|1000.0|1000.0|1000.0|1000.0|0
1353196800|801.3253|810.5765|801.3253|810.5765|0
1352592000|810.1836|816.1449|800.1838|801.3998|0
1351987200|827.2505|835.2409|810.2589|810.2589|0
1351382400|826.5157|829.271|825.9134|827.3272|0
1350777600|833.4383|833.4383|825.2886|826.5936|0
....

and this is more weird :

sqlite> SELECT * FROM data where time > 1353196800;
1|1000.0|1000.0|1000.0|1000.0|0

other databases are working fine as expected and they have the same structure but this is the only one imported from a CSV originated from SQLServer2008, I think for some reason the first row is interpreted as a char not an INT, the first row of the CSV is always wrong, is this one considered a header or something?

table schema:

sqlite> .schema data
CREATE TABLE data ( time INTEGER PRIMARY KEY DESC, open REAL, high REAL, low REAL, close REAL, volume INTEGER );

I found that SQL Manager Studio exports CSV files with a "header" with invisible for vim and other editors and SQLite takes the header as part of the value of the first column.

alter-mac:data$ hexdump exportedresult.csv 
0000000 ef bb bf 31 32 32 38 31 37 36 30 30 30 2c 31 30
0000010 30 30 2c 31 30 30 30 2c 31 30 30 30 2c 31 30 30
...

ef bb bf

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM