按查询分组在 android 2.1 中不起作用

发布于 2024-12-04 17:43:24 字数 1118 浏览 0 评论 0原文

我在本地数据库表“会话”中保存日期时间(以毫秒为单位) 我的问题是这段代码可以在 android 2.2 及以上版本中运行,但喜欢 android 2.2 版本 它不起作用意味着它给了我表中的所有行 但是我在 android 2.2 中运行相同的代码吗?它工作得很好,并给了我不同的值

当我在 Sqlite Manager 中运行下面的查询时,它给了我正确的不同值

创建表语法

"CREATE TABLE  session  ( " +
        "recid  INTEGER PRIMARY KEY NOT NULL ,  " +
        "starttime  TEXT)";

查询以获取数据来自数据库

Cursor c = mDb.rawQuery("select distinct (starttime / (24 * 60 * 60 * 1000)) ,
starttime from session group by (starttime / (24 * 60 * 60 * 1000))", null);

数据库表会话中的值::

1   1319084700198
4   1319084100642
5   1319092500940
6   1319092500769
7   1319100300864
8   1319107500002
9   1319107500673
10  1319168700236
11  1319169000223
12  1319178000717
13  1319178000902
14  1319185800738
15  1319192100137
16  1319256000842
17  1319256000985
18  1319192100156
19  1319084700210
20  1319085000660
21  1319086500972
22  1319088000927
23  1319092500687
24  1319092500027
25  1319092500178
26  1319092500702
27  1319092500878
28  1319092500114

I am saving datetime in milliseconds in my local database table "session"
My problem is this code is working in android 2.2 and above but belove version of android 2.2
it is not working means it is giving me all the rows from table
But is I run same code in android 2.2 it is working perfactly and giving me distinct values

When I run below query in Sqlite Manager it is giving me proper distinct value

Create table syntax

"CREATE TABLE  session  ( " +
        "recid  INTEGER PRIMARY KEY NOT NULL ,  " +
        "starttime  TEXT)";

Query to fetch data from database

Cursor c = mDb.rawQuery("select distinct (starttime / (24 * 60 * 60 * 1000)) ,
starttime from session group by (starttime / (24 * 60 * 60 * 1000))", null);

Values in database table session ::

1   1319084700198
4   1319084100642
5   1319092500940
6   1319092500769
7   1319100300864
8   1319107500002
9   1319107500673
10  1319168700236
11  1319169000223
12  1319178000717
13  1319178000902
14  1319185800738
15  1319192100137
16  1319256000842
17  1319256000985
18  1319192100156
19  1319084700210
20  1319085000660
21  1319086500972
22  1319088000927
23  1319092500687
24  1319092500027
25  1319092500178
26  1319092500702
27  1319092500878
28  1319092500114

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

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

发布评论

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

评论(2

忆梦 2024-12-11 17:43:24

我认为问题的根源在于 SQL 中混合字符串和算术。
考虑将数据库类型从 TEXT 更改为 INTEGER。

I think the root to you problems lies in mixing strings and arithmetic's in the SQL.
Consider changing the database type from TEXT to INTEGER.

梦旅人picnic 2024-12-11 17:43:24

如果由于某种原因必须使用文本,我会尝试计算 SQL 之外的值并提供计算值。这样你就可以捕获 NumberFormatException 等。

distinctTime = Double.parseDouble(starttime) / (24 * 60 * 60 * 1000);
Cursor c = mDb.rawQuery("select distinct " + distinctTime, 
"starttime from session group by " +distinctTime, null);

If you must use text for some reason, I would try calculating the values outside the SQL and provide the calculated values instead. This way you could catch NumberFormatException and the like.

distinctTime = Double.parseDouble(starttime) / (24 * 60 * 60 * 1000);
Cursor c = mDb.rawQuery("select distinct " + distinctTime, 
"starttime from session group by " +distinctTime, null);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文