【问题标题】:Query "disjointed" Android sqlite database查询“脱节”的 Android sqlite 数据库
【发布时间】:2013-10-02 03:56:21
【问题描述】:

我正在使用 android 中的 sqlite 数据库,其实体关系图如下:

我要做的是在游标中查询并返回 vehicle_implement 表中的所有列及其左侧的所有表,通过图中所示的外键连接。在vehicle_implement 中有一些空的implement_ids,我仍然想要那些行。没有也不会有任何空的vehicle_ids。我认为当implement_id 为null 时,可能无法从implement 表左侧的表中返回任何内容,这会阻止我获取我想要的所有列和行。

我认为使用临时表来做到这一点并不难,但我正在尝试使用 queryBuilder 来做到这一点。如果我仍然可以在游标中将结果从查询返回到数据库前面的内容提供者,我愿意在没有 queryBuilder 的情况下执行此操作。

提前致谢。

【问题讨论】:

  • 查找outer joins。
  • 我熟悉外连接。我认为 QuerbyBuilder 在可接受查询的格式方面比实际情况更受限制。一位同事想出了一个解决方案,我会发布它。吸取的一个教训是尝试在不假设约束的情况下获得解决方案,尝试它,并让结果表明是否存在约束以及存在哪些约束。

标签: android sqlite


【解决方案1】:

vehicle_implement
LEFT JOIN vehicle ON vehicle_implement.vehicle_id = vehicle._id
LEFT JOIN implement ON vehicle_implement.implement_id = implement._id
LEFT JOIN vehicle_model ON vehicle.vehicle_model_id = vehicle_model._id
LEFT JOIN vehicle_type ON vehicle_model.vehicle_type_id = vehicle_type._id
LEFT JOIN implement_model ON implement.implement_model_id = implement_model._id
LEFT JOIN implement_type ON implement_model.implement_type_id = implement_type._id
LEFT JOIN operation_implement_type ON implement_type._id = operation_implement_type.implement_type_id
LEFT JOIN operation ON operation_implement_type.operation_id = operation._id

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-24
    • 1970-01-01
    相关资源
    最近更新 更多