我遇到的SELECT查询问题没有返回任何值,但如果我输入一个真正的字符串而不是一个变量就可以了
db.returnArray("您好&#34); //这个有用吗
db.returnArray(ChecklistName); //这不起作用
这是代码。
private void shareChecklist(String CheckListName) {
// TODO Auto-generated method stub
/** sharing code is working but the problem with how to get the item =) */
//Build the Share Content
String shareBody=sCheckList+ " item/s: \n";
db = new SQLiteDB(this.getApplicationContext());
String[] printItem =db.returnArray(CheckListName);
for(int j=0;j<printItem.length;j++){
shareBody+=printItem[j]+" \n";
}
//Create a Send Intent
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
//Set the Sharing Type
sharingIntent.setType("text/plain");
//Pass Content to the Intent
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, sCheckList+" Check list,I am sharing one of my Check list On Voz App");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
//Create a Chooser
startActivity(Intent.createChooser(sharingIntent, "Share via"));
}
SQLiteDataBase代码:
/*** Table ****/
private static final String TABLE_ITEMS = "items";
private static final String ITEM_ID = "id";
private static final String ITEM_CHECKLISTIDX = "checklistName";
private static final String ITEM_NAME = "itemname";
private static final String ITEM_FLAG = "flag";
private static final String ITEM_DATETIME = "esttime";
private static final String[] ITEMCOLUMNS = { ITEM_ID, ITEM_CHECKLISTIDX,
ITEM_NAME, ITEM_FLAG, ITEM_DATETIME };
/*************************************************************/
/** return an array with items from items table ***/
public String[] returnArray(String checkName){
String[] items;
SQLiteDatabase db = this.getWritableDatabase();
String query="SELECT * FROM items WHERE checklistName='"+ checkName + "'";
Cursor cursor = db.rawQuery(query, null);
items=new String[cursor.getCount()];
int counter=0;
if (cursor.moveToFirst()) {
do {
items[counter++]+= cursor.getString(2);
} while (cursor.moveToNext());
db.close();
}
return items;
}
创建表格为:
String CREATE_ITEM_TABLE = "CREATE TABLE items ( "+ "id INTEGER PRIMARY KEY AUTOINCREMENT , " + "checklistName TEXT, "+ "itemname TEXT, " + "flag INTEGER, " + "esttime TEXT )";
db.execSQL(CREATE_ITEM_TABLE);
答案 0 :(得分:1)
您在SELECT中定位了错误的字段 由于您要创建此字段:
checklistidx
在你的:
String CREATE_ITEM_TABLE = "CREATE TABLE items ( "+ "id INTEGER PRIMARY KEY AUTOINCREMENT , " + "checklistidx TEXT, "+ "itemname TEXT, " + "flag INTEGER, " + "esttime TEXT )";
您选择的WHERE应该定位该字段:
String query="SELECT * FROM items WHERE checklistidx = '"+ checkName + "'";
而不是
String query="SELECT * FROM items WHERE checklistName = '"+ checkName + "'";