@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE);
// providers data
// db.execSQL("insert into "
// + TABLE_PROVIDERS
// + " (_id, provider_id, parent_id, title, image, sh_n, enable, visible, image_bg, type, is_group, hide_in_search, limit_min, limit_max, off_on_line, invoice_search) "
// + "VALUES (1,600,101,'Источники оплаты','',1,1,0,'','',1,1,0,0,0,0)");
ContentValues cv = new ContentValues();
cv.put("_id", 1);
cv.put("provider_id", 600);
cv.put("parent_id", 101);
cv.put("title", "Bla");
cv.put("image", "bla");
cv.put("sh_n", 1);
cv.put("enable", 1);
cv.put("visible", 1);
cv.put("image_bg", "");
cv.put("type", "");
cv.put("is_group", 1);
cv.put("hide_in_search", 1);
cv.put("limit_min", 10);
cv.put("limit_max", 10000);
cv.put("off_on_line", 1);
cv.put("invoice_search", 1);
db.insertOrThrow(TABLE_PROVIDERS, null, cv);
}
今、私は提案されたように、行ごとに挿入しています:
import java.util.*;
import android.content.*;
import android.database.*;
import android.database.sqlite.*;
public class ProviderDataSource {
private SQLiteDatabase database;
private MySQLiteHelper dbHelper;
public ProviderDataSource(Context context) {
dbHelper = new MySQLiteHelper(context);
}
public void open() throws SQLException {
database = dbHelper.getWritableDatabase();
}
public void close() {
dbHelper.close();
}
public List<Provider> getProvidersByParentId(long parentId) {
List<Provider> providersList = new ArrayList<Provider>();
Cursor cursor = database.query(MySQLiteHelper.TABLE_PROVIDERS, new String[] { "provider_id", "title", "image" }, " parent_id=" + parentId,
null, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Provider provider = cursorToProvider(cursor);
providersList.add(provider);
cursor.moveToNext();
}
cursor.close();
System.out.println("getProvidersByParentId");
return providersList;
}
private Provider cursorToProvider(Cursor cursor) {
Provider provider = new Provider();
provider.setId(cursor.getInt(1));
provider.setTitle(cursor.getString(3));
provider.setImg(cursor.getString(4));
return provider;
}
}
動作しません。行が挿入されておらず、getProvidersByParentIdメソッドによって返される配列が空のようです。引数としてのParent_idは101です。