Вопрос

I'm attempting to pull a record from an SQLite database based on a UNIX timestamp, which is selected by a scroller. Each record has a timestamp and a duration so when the selected timestamp is after the start time and after the start time plus the duration it's to be selected.

I've wrote a query, which not only do I believe should work but also works in an SQLite client I have but not using the SQLite, which is shipped with XCode.

SELECT * FROM `booking` WHERE '1304168400' BETWEEN `stamp` AND (`stamp`+(`duration`*60))

This is my query. The timestamp being the selected timestamp, the stamp field being the records timestamp and duration being the length of the booking in minutes.

The only reason I can see for this to work using the client I have, is that the version of SQLite is different and either the BETWEEN command isn't supported or isn't supported in the same way.

Any advice or help would be appreciated. Thanks!

Это было полезно?

Решение

This is what a SQLite query should look like when it gets to SQLite. (No quotation marks around the literal timestamp, no backticks.) If you can open your database with SQLite and run this query, this syntax should work.

sqlite> SELECT *
        FROM booking
        WHERE 1304168400 BETWEEN stamp and (stamp + (duration * 60));

Guard identifiers with double quotes, not backticks.

sqlite> SELECT *
        FROM "booking"
        WHERE 1304168400 BETWEEN "stamp" and ("stamp" + ("duration" * 60));

You can determine which version of SQLite is running by this query.

sqlite> select sqlite_version();
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top