0

私はAndroid3.1アプリケーションを開発しています。

私は次のテーブルを持っています:

FormBlock
---------
FormId  (INTEGER) FOREIGN KEY TO Form.id
BlockId (INTEGER) FOREIGN KEY TO Block.id

Block
----------
id          (INTEGER) PRIMARY KEY
name        (TEXT)    NOT NULL
orderInForm (INTEGER) NOT NULL

そして、私は次の選択をしたいと思います:

SELECT block.blockId, block.name, block.orderInForm FROM Block, FormBlock WHERE FormBlock.FormId = 1 AND block.blockId = FormBlock.blockId;

SQLiteDatabase.query(...)またはを使用してそのselectステートメントを実行するにはどうすればよいrawQuery()ですか?

4

2 に答える 2

2
SELECT 
    block.blockId, block.name, block.orderInForm
FROM
    Block, FormBlock 
WHERE
    FormBlock.FormId = 1 AND block.blockId = FormBlock.blockId;

そのままquery_

String table = "Block, FormBlock";
String[] columns = new String[] { "block.blockId", "block.name", "block.orderInForm" };
String where = "FormBlock.FormId = 1 AND block.blockId = FormBlock.blockId";
Cursor result = db.query(table, columns, where, null, null, null, null);

1が動的である場合

int formId = 1;
String table = "Block, FormBlock";
String[] columns = new String[] { "block.blockId", "block.name", "block.orderInForm" };
String where = "FormBlock.FormId = ? AND block.blockId = FormBlock.blockId";
String[] whereArgs = new String[] { String.valueOf(formId) };
Cursor result = db.query(table, columns, where, whereArgs, null, null, null);
于 2012-04-20T10:27:05.480 に答える
1

これを試して:

String query = "SELECT * FROM Block WHERE id IN
                  (SELECT BlockId FROM FormBlock WHERE FormId = 1)";

Cursor c = database.rawQuery(query, null);
于 2012-04-20T10:23:01.817 に答える