简体   繁体   English

从C ++和控制台使用sqlite3产生奇怪的结果

[英]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 我不太确定为什么会这样,我想这是SQLite3中的错误

I had exported a CSV file from a result of SQL2008 the file looks like this ( "time" is the first column) : 我从SQL2008的结果中导出了一个CSV文件,该文件看起来像这样(“时间”是第一列):

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" 然后,我先使用“ .separator”导入sqlite3表,然后再使用“ .import file.csv data”导入。

then i issue the following SQL statement from a C++ program : 然后我从C ++程序发出以下SQL语句:

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. 但结果显示出第一行为“ time == 1”,应该是最后一行。

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? 其他数据库运行正常,并且具有相同的结构,但这是唯一一个从SQLServer2008导出的CSV导入的数据库,我认为由于某些原因,第一行被解释为char而不是INT,CSV的第一行总是错的,这是标题吗?

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. 我发现SQL Manager Studio导出带有“标头”的CSV文件,而vim和其他编辑器不可见该标头,而SQLite将标头作为第一列的值的一部分。

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 ef bb bf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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