<p>呼叫:</p>
<pre><code>PRAGMA table_info(table1);
</code></pre>
<p>将转储表信息,例如</p>
<pre><code>cid|name |type |notnull |dflt_value |pk
0 |id_fields_starring |INTEGER |0 | |1
1 |fields_descriptor_id |INTEGER |1 | |0
2 |starring_id |INTEGER |1 | |0
3 |form_mandatory |INTEGER |1 |1 |0
4 |form_visible |INTEGER |1 |1 |0
</code></pre>
<p>只需在光标中找到带有<code>notnull=1</code>和<code>dflt_value=1</code>的行
</p><hr/>
<b>编辑:</b>
<p>要列出定义为<code>INTEGER NOT NULL DEFAULT 1</code>的所有列,这将起作用(<code>helper</code>是<code>SQLiteOpenHelper</code>的实例):</p>
<pre><code>SQLiteDatabase db = helper.getWritableDatabase();
Cursor cursor = db.rawQuery("PRAGMA table_info(table1)", null);
try {
int nameIdx = cursor.getColumnIndexOrThrow("name");
int typeIdx = cursor.getColumnIndexOrThrow("type");
int notNullIdx = cursor.getColumnIndexOrThrow("notnull");
int dfltValueIdx = cursor.getColumnIndexOrThrow("dflt_value");
ArrayList<String> integerDefault1NotNull = new ArrayList<String>();
while (cursor.moveToNext()) {
String type = cursor.getString(typeIdx);
if ("INTEGER".equals(type)) {
// Integer column
if (cursor.getInt(notNullIdx) == 1) {
// NOT NULL
String defaultValue = cursor.getString(dfltValueIdx);
if ("1".equals(defaultValue)) {
integerDefault1NotNull.add(cursor.getString(nameIdx));
}
}
}
}
System.out.println("integerDefault1NotNull now contains a list of all columns " +
" defined as INTEGER NOT NULL DEFAULT 1, " + integerDefault1NotNull);
} finally {
cursor.close();
}
</code></pre>