sql: sqlite: 服务器端分页

发布于 2024-09-29 16:12:42 字数 443 浏览 1 评论 0原文

我有一个客户端与需要支持分页的服务器程序(使用sqlite3作为存储)进行通信。我正在考虑如何实施。一种方法:

1) user request page 1
  a. execute query from sqlite3
  b. return the first page range items to client

2) user request page N
  a. execute query from sqlite3
  b. return the N page range itmes to client

因此,在我的方法中,每次用户请求数据时,我都会重新发出查询并获取指定的元素,这似乎浪费时间......(与一次缓存所有项目并仅给出用户请求的部分相比,但是这种方法更复杂,因为我需要使缓存超时 - 用户正在使用浏览器我不知道用户何时注销并且缓存无用)

有更好的想法吗?

I have a client talking with server program(using sqlite3 as the storage) which needs to support paging. I am thinking about how to implement that. One approach:

1) user request page 1
  a. execute query from sqlite3
  b. return the first page range items to client

2) user request page N
  a. execute query from sqlite3
  b. return the N page range itmes to client

So in my approach every time user requests data I will re issue the query and get the specified elements, which seems waste of time...(comparing with caching all the items one time and just give the portion user asks, but this approach is more complex, as I need to timeout the cache - user is using browser I don't know when the user is loggout and the cache is useless)

Any better ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那些过往 2024-10-06 16:12:42

也许您可以使用 LIMIT…OFFET… 功能SQLite 的。

摘自select 语法文档

LIMIT 子句可以指定两个用逗号分隔的标量表达式,而不是单独的 OFFSET 子句。在本例中,第一个表达式用作 OFFSET 表达式,第二个表达式用作 LIMIT 表达式。这是违反直觉的,因为当使用 OFFSET 子句时,两个表达式中的第二个是 OFFSET,第一个是 LIMIT。这是有意为之的——它最大限度地提高了与其他 SQL 数据库系统的兼容性。

Maybe you could use the LIMIT… OFFET… capability of SQLite.

Taken from the select syntax documentation:

Instead of a separate OFFSET clause, the LIMIT clause may specify two scalar expressions separated by a comma. In this case, the first expression is used as the OFFSET expression and the second as the LIMIT expression. This is counter-intuitive, as when using the OFFSET clause the second of the two expressions is the OFFSET and the first the LIMIT. This is intentional - it maximizes compatibility with other SQL database systems.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文