Код: Выделить всё
package ru.pks.pizzatime;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class PizzaTimeDatabaseHelper extends SQLiteOpenHelper {
private static final String TAG = "PizzaTimeDatabaseHelper";
private static final String DB_NAME = "pizzatime";
private static final int DB_VERSION = 1;
PizzaTimeDatabaseHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
Log.d(TAG, "PizzaTimeDatabaseHelper");
}
@Override
public void onCreate(SQLiteDatabase db) {
updateMyDatabase(db, 0, DB_VERSION);
Log.d(TAG, "updateMyDatabase onCreate");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
updateMyDatabase(db, oldVersion, newVersion);
}
private static void insertPizza(SQLiteDatabase db, String name, String description, String bonus,
int type, int type_bonus, int orderQuantity) {
ContentValues pizzaValues = new ContentValues();
pizzaValues.put("NAME", name);
pizzaValues.put("DESCRIPTION", description);
pizzaValues.put("BONUS", bonus);
pizzaValues.put("TYPE", type);
pizzaValues.put("TYPE_BONUS", type_bonus);
pizzaValues.put("ORDER_QUANTITY", orderQuantity);
db.insert("PTIME", null, pizzaValues);
}
private void updateMyDatabase(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE PTIME");
db.execSQL("CREATE TABLE PTIME ("
+ "_id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "NAME TEXT, "
+ "DESCRIPTION TEXT, "
+ "BONUS TEXT, "
+ "TYPE INTEGER, "
+ "TYPE_BONUS INTEGER, "
+ "ORDER_QUANTITY INTEGER);");
Log.d(TAG, "updateMyDatabase table create");
insertPizza(db, "Raphael\'s PIZZA", "Pizza with secret ingredients.\n" +
"As Rafael himself says, I just take everything that is in the fridge.",
"Take 3 and get 1 for free", 1, 0, 0);
Log.d(TAG, "updateMyDatabase table create 2");
insertPizza(db, "Raphael\'s PIZZA (Bonus)", "1", "1",
1, 1, 0);
Log.d(TAG, "updateMyDatabase table create 3");
}
}
Код: Выделить всё
try {
SQLiteOpenHelper pizzaDB = new PizzaTimeDatabaseHelper(this);
SQLiteDatabase db = pizzaDB.getReadableDatabase();
Cursor cursor = db.query("PTIME",
new String[]{"TYPE", "TYPE_BONUS", "ORDER_QUANTITY"},
null, null, null, null, null);
cursor.moveToFirst();
if (cursor.moveToFirst()) {
test1 = cursor.getInt(0);
}
cursor.moveToNext();
if (cursor.moveToNext()){
test3 = cursor.getInt(0);
}
TextView textView = findViewById(R.id.textView);
textView.setText(String.valueOf(test1));
TextView textView2 = findViewById(R.id.textView2);
textView2.setText(String.valueOf(test3));
cursor.close();
db.close();
} catch (SQLiteException e) {
toastCenterLong(getString(R.string.db_error));
}
Смотрю по логам и в Дебагере...
В public void onCreate(SQLiteDatabase db) попросту не заходит...
Почему?!?!