【发布时间】:2019-12-20 10:19:52
【问题描述】:
我正在开发一个 android 应用程序,我有两个 sqlite 表。
projects
id projectname projectstatus
1 TestProj1 1
2 TestProj2 1
outlets
id pid outletname status
1 1 testoutlet1 1
2 1 testoutlet2 1
3 2 testoutlet1 1
在每个项目下,我可能有一个单一出口或多个出口。期望用户在每个插座中执行某些操作。只有状态为 1 的项目和出口对用户可见。
outlet 表中的pid 指的是projects 表的id。在用户完成任务时的出口级别,我将状态更新为 2。将项目中每个出口的状态更新为 2 后,我正在尝试将项目的状态更新为 2。
例如,前 2 个 outlet 在 TestProj1 中,我们可以看到 pid 为 1。以下代码将 outlet 的状态设置为 2。
private void updateOutletStatus() {
String query = "select OutletName from projectparams where projectName= '"+projectName+"' and OutletName= '"+outletName+"' group by projStatus";
if (sqLiteHelper.getData(query).getCount()==1) {
Toast.makeText( getApplicationContext(), "No more tasks in this outlet!", Toast.LENGTH_SHORT ).show();
SQLiteDatabase db = sqLiteHelper.getWritableDatabase();
String outletUpdate = "update outlets set status=2 where OutletName='"+outletName+"' and pid = (select id from projects where projectName = '"+projectName+"' ) ";
db.execSQL(outletUpdate);
}
}
上面的代码可以正常工作。当一个项目中所有插座的插座状态变为 2 我想将 projectstatus 设置为 2。我尝试了以下代码:
private void updateProjectStatus() {
String query = "select Status from outlets where pid = (select id from projects where ProjectName = '"+projectName+"' ) group by Status";
if (sqLiteHelper.getData(query).getCount()==1) {
Toast.makeText( getApplicationContext(), "No more outlets in this project!", Toast.LENGTH_SHORT ).show();
SQLiteDatabase db = sqLiteHelper.getWritableDatabase();
String projectUpdate = "update projects set projectStatus=2 where pid = (select id from projects where ProjectName = '"+projectName+"' ) ";
db.execSQL(projectUpdate);
}
}
以上内容不适用于项目更新。我尝试了各种组合,但仍然不起作用
【问题讨论】:
-
不工作是什么意思?表没有更新?你有错误吗?
标签: android sqlite sql-update