Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to build a request with OFFSET but no LIMIT causes SQL error #53

Closed
mtfelian opened this issue Sep 16, 2021 · 1 comment
Closed
Assignees

Comments

@mtfelian
Copy link
Contributor

mtfelian commented Sep 16, 2021

SQLite does not understand OFFSET without a LIMIT clause.

Look onto the following code:

[0.000ms] [rows:0] SELECT `queue_records`.`queue_id`,`queue_records`.`id`,`queue_records`.`journal_id` FROM `queue_records` WHERE (status = "put" AND queue_id = "a08a10b7-16ee-11ec-a4bb-482ae31ffe87") AND `queue
_records`.`deleted_at` IS NULL ORDER BY rec_time DESC OFFSET 1
?[1mSTEP?[0m: creating 2 queues
?[1mSTEP?[0m: creating queue 1
?[1mSTEP?[0m: creating queue 2
?[1mSTEP?[0m: inserting a bulk of queue records
?[1mSTEP?[0m: updating queue
+ Failure [0.004 seconds]
queues tests
qservice/mcstorage/sqlite/queues_test.go:19
  Queue Records
  qservice/mcstorage/sqlite/queues_test.go:338
    various delete funcs
    qservice/mcstorage/sqlite/queues_test.go:711
      QueueDeletePutRecords
      qservice/mcstorage/sqlite/queues_test.go:727
        checks if queue.Max = 1 [It]
        qservice/mcstorage/sqlite/queues_test.go:742

        Unexpected error:
            <sqlite3.Error>: {
                Code: 1,
                ExtendedCode: 1,
                SystemErrno: 0x0,
                err: "near \"OFFSET\": syntax error",
            }
            near "OFFSET": syntax error
        occurred

        qservice/mcstorage/sqlite/queues_test.go:751

Consider also looking the diagrams: https://www.sqlite.org/syntaxdiagrams.html

Workaround is to rewrite ClauseBuilders["LIMIT"] with valid implementation inside *gorm.DB entity.

@jinzhu
Copy link
Member

jinzhu commented Nov 1, 2021

thank you for your PR.

@jinzhu jinzhu closed this as completed Nov 1, 2021
samuelncui pushed a commit to samuelncui/gorm-sqlite that referenced this issue Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants