简体   繁体   English

带ORDER BY的Sqlite3和PDO问题

[英]Sqlite3 and PDO issue with ORDER BY

I try to use the SQL statement 我尝试使用SQL语句

SELECT * FROM table ORDER BY column

via an PDO-Object in PHP. 通过PHP中的PDO对象。 Problem is, that I always get an error (Call to a member function fetchall() on a non-object - that means, the query did not return a PDO-object) when using the names of all columnname EXCEPT for ID. 问题是,当使用所有列名EXCEPT的名称作为ID时,总是出现错误(在非对象上调用成员函数fetchall()-这意味着查询未返回PDO对象)。 When I query 当我查询

SELECT * FROM table ORDER BY ID

it works. 有用。 ID is the PRIMARY INTEGER KEY, all other columns are TEXT or NUMERIC, neither of them would works with the ORDER BY clause. ID是PRIMARY INTEGER KEY,其他所有列都是TEXT或NUMERIC,它们都不适用于ORDER BY子句。

Any ideas? 有任何想法吗?

It could be an issue with temporary files as you've suggested in your comment to Frank Heikens's answer. 正如您在对弗兰克·海肯斯(Frank Heikens)的回答的评论中所建议的那样,这可能与临时文件有关。

http://www.sqlite.org/tempfiles.html says: http://www.sqlite.org/tempfiles.html说:

2.6 Transient Indices 2.6瞬态指数

SQLite may make use of transient indices to implement SQL language features such as: SQLite可以利用瞬态索引来实现SQL语言功能,例如:

* An ORDER BY or GROUP BY clause * ORDER BY或GROUP BY子句
* The DISTINCT keyword in an aggregate query *聚合查询中的DISTINCT关键字
* Compound SELECT statements joined by UNION, EXCEPT, or INTERSECT *复合SELECT语句,由UNION,EXCEPT或INTERSECT连接

Each transient index is stored in its own temporary file. 每个临时索引都存储在其自己的临时文件中。

If and where files are created is controlled by SQLITE_TEMP_STORE , PRAGMA temp_store and PRAGMA temp_store_directory , see http://www.sqlite.org/pragma.html 如果创建文件的位置由SQLITE_TEMP_STOREPRAGMA temp_storePRAGMA temp_store_directory ,请参见http://www.sqlite.org/pragma.html

Replace your ORDER BY statement with ORDER BY CAST(COLUMN AS REAL) . ORDER BY CAST(COLUMN AS REAL)替换您的ORDER BY语句。 It can sort REAL values. 它可以对REAL值进行排序。

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

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