当我尝试利用我在这里创建的 SQLite 数据库时,Android 崩溃了

发布于 2024-11-01 00:20:46 字数 1546 浏览 6 评论 0原文

当我尝试创建动态列时出现以下错误。我认为这是合法的,但显然 Android 和 SQLite 不喜欢这样。我确信我错过了一些简单的事情,但我就是想不起来。

错误消息是:没有这样的列:sundayResult:,编译时:

CREATE TABLE DAYSUSED(
                _id INTEGER PRIMARY KEY autoincrement, 
                sunday INTEGER NOT NULL,
                monday INTEGER NOT NULL, 
                tuesday INTEGER NOT NULL, 
                wednesday INTEGER NOT NULL, 
                thursday INTEGER NOT NULL, 
                friday INTEGER NOT NULL, 
                saturday INTEGER NOT NULL);
SELECT _id
           , volume_level
           , vibrate
           , CASE WHEN sunday = 1 THEN 'Sun' ELSE ' ' END AS sundayResult
           , CASE WHEN monday = 1 THEN 'Mon' ELSE ' ' END AS mondayResult
           , CASE WHEN tuesday = 1 THEN 'Tues' ELSE ' ' END AS tuesdayResult
           , CASE WHEN wednesday = 1 THEN 'Wed' ELSE ' ' END AS wednesdayResult
           , CASE WHEN thursday = 1 THEN 'Thur' ELSE ' ' END AS thursdayResult
           , CASE WHEN friday = 1 THEN 'Fri' ELSE ' ' END AS fridayResult
           , CASE WHEN saturday = 1 THEN 'Sat' ELSE ' ' END AS saturdayResult
           , sundayResult || ' ' || mondayResult || ' ' || tuesdayResult || ' ' || wednesdayResult || ' ' || thursdayResult || ' ' || fridayResult || ' ' || saturdayResult || ' ' AS days_of_week
 FROM DAYSUSED

如果我直接调用实际列,则最后一行将起作用,例如:

, sunday || ' ' ||

而不是我当前拥有的列:

, sundayResult || ' ' ||

我已经查看了所有内容,但没有知道还可以尝试什么,因为我真的很想更改光标的数据。

谢谢, 凯莉

I get the following error when I attempt to create dynamic columns. I thought this was legit, but apparently Android and SQLite don't like this. I'm sure I'm missing something simple, but I just can't recall.

Error message is: no such column: sundayResult: , while compiling:

CREATE TABLE DAYSUSED(
                _id INTEGER PRIMARY KEY autoincrement, 
                sunday INTEGER NOT NULL,
                monday INTEGER NOT NULL, 
                tuesday INTEGER NOT NULL, 
                wednesday INTEGER NOT NULL, 
                thursday INTEGER NOT NULL, 
                friday INTEGER NOT NULL, 
                saturday INTEGER NOT NULL);
SELECT _id
           , volume_level
           , vibrate
           , CASE WHEN sunday = 1 THEN 'Sun' ELSE ' ' END AS sundayResult
           , CASE WHEN monday = 1 THEN 'Mon' ELSE ' ' END AS mondayResult
           , CASE WHEN tuesday = 1 THEN 'Tues' ELSE ' ' END AS tuesdayResult
           , CASE WHEN wednesday = 1 THEN 'Wed' ELSE ' ' END AS wednesdayResult
           , CASE WHEN thursday = 1 THEN 'Thur' ELSE ' ' END AS thursdayResult
           , CASE WHEN friday = 1 THEN 'Fri' ELSE ' ' END AS fridayResult
           , CASE WHEN saturday = 1 THEN 'Sat' ELSE ' ' END AS saturdayResult
           , sundayResult || ' ' || mondayResult || ' ' || tuesdayResult || ' ' || wednesdayResult || ' ' || thursdayResult || ' ' || fridayResult || ' ' || saturdayResult || ' ' AS days_of_week
 FROM DAYSUSED

The last line will work if I do a direct call to the actual columns like:

, sunday || ' ' ||

instead of what I have currently which is:

, sundayResult || ' ' ||

I've looked all over and don't know what else to try, as I'd really like to alter the data for the cursor.

Thanks,
Kelly

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

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

发布评论

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

评论(1

输什么也不输骨气 2024-11-08 00:20:46

sundayResult 只是一个别名,您不能在同一查询中使用它。你需要这样的东西。如果volume_level和vibrate来自不同的表,则将其与子查询“days”连接

SELECT _id
           , volume_level
           , vibrate
           , days.sundayResult || ' ' || days.mondayResult || ' ' || days.tuesdayResult || ' ' || days.wednesdayResult || ' ' || days.thursdayResult || ' ' || days.fridayResult || ' ' || days.saturdayResult || ' ' AS days_of_week
from
(          select
           CASE WHEN sunday = 1 THEN 'Sun' ELSE ' ' END AS sundayResult
           , CASE WHEN monday = 1 THEN 'Mon' ELSE ' ' END AS mondayResult
           , CASE WHEN tuesday = 1 THEN 'Tues' ELSE ' ' END AS tuesdayResult
           , CASE WHEN wednesday = 1 THEN 'Wed' ELSE ' ' END AS wednesdayResult
           , CASE WHEN thursday = 1 THEN 'Thur' ELSE ' ' END AS thursdayResult
           , CASE WHEN friday = 1 THEN 'Fri' ELSE ' ' END AS fridayResult
           , CASE WHEN saturday = 1 THEN 'Sat' ELSE ' ' END AS saturdayResult
           FROM DAYSUSED
) days

sundayResult is just an alias and you cannot use it into the same query. You need something like this. If volume_level and vibrate are coming from different table, then join it with subquery "days"

SELECT _id
           , volume_level
           , vibrate
           , days.sundayResult || ' ' || days.mondayResult || ' ' || days.tuesdayResult || ' ' || days.wednesdayResult || ' ' || days.thursdayResult || ' ' || days.fridayResult || ' ' || days.saturdayResult || ' ' AS days_of_week
from
(          select
           CASE WHEN sunday = 1 THEN 'Sun' ELSE ' ' END AS sundayResult
           , CASE WHEN monday = 1 THEN 'Mon' ELSE ' ' END AS mondayResult
           , CASE WHEN tuesday = 1 THEN 'Tues' ELSE ' ' END AS tuesdayResult
           , CASE WHEN wednesday = 1 THEN 'Wed' ELSE ' ' END AS wednesdayResult
           , CASE WHEN thursday = 1 THEN 'Thur' ELSE ' ' END AS thursdayResult
           , CASE WHEN friday = 1 THEN 'Fri' ELSE ' ' END AS fridayResult
           , CASE WHEN saturday = 1 THEN 'Sat' ELSE ' ' END AS saturdayResult
           FROM DAYSUSED
) days
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文