複数の SQLite テーブルを作成すると、奇妙なクラッシュが発生します...
CREATE_MOVEMENTS_TABLE を実行する行をコメントアウトすると、コードは正常に機能します。
最初のテーブルは問題なく作成されます。両方を作成しようとすると、アプリがクラッシュします。
奇妙なこと: 2 番目のテーブルを作成せずに電話でアプリをテストすると、正常に動作し、(アプリをインストールして) もう一度テストすると、2 つの SQL ステートメントで (両方のテーブルを作成する) 、アプリは動作します...アプリが電話にまったく存在しない場合に問題が発生します
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.util.ArrayList;
import java.util.List;
public class DatabaseHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "ClientsManager";
private static final String CLIENTS_TABLE = "Clients";
private static final String MOVEMENTS_TABLE = "Movements";
//Client Table Columns
private static final String KEY_ROWID = "numint";
private static final String KEY_NAME = "name";
private static final String KEY_LOCAL = "locality";
private static final String KEY_ADDR = "address";
private static final String KEY_BTTLP = "bottle_price";
private static final String KEY_PBLNC = "prev_balance";
private static final String KEY_BLNC = "balance";
private static final String KEY_BBTTLS = "bonif_bottles";
private static final String KEY_PBTTLS = "prev_bottles";
private static final String KEY_BTTLS = "bottles";
private static final String KEY_SYNC = "sync_date";
private static final String KEY_MODIF = "modif_date";
//Movements Table Columns
private static final String MKEY_ROWID = "numint";
private static final String MKEY_ID_MOVE = "move_id";
private static final String MKEY_CLIENT_ID = "client_id";
private static final String MKEY_PICKUP = "pickup";
private static final String MKEY_DELIVER = "deliver";
private static final String MKEY_PAYMENT = "payment";
private static final String MKEY_MOVE_DATE = "move_date";
private static final String MKEY_SYNC_DATE = "sync_date";
private static final String MKEY_FLAG_SYNC = "flag_sync";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
String CREATE_CLIENTS_TABLE = "CREATE TABLE " + CLIENTS_TABLE + "("
+ KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
+ KEY_NAME + " TEXT NOT NULL, "
+ KEY_LOCAL + " TEXT NOT NULL, "
+ KEY_ADDR + " TEXT NOT NULL, "
+ KEY_BTTLP + " REAL NOT NULL, "
+ KEY_PBLNC + " REAL NOT NULL, "
+ KEY_BLNC + " REAL NOT NULL, "
+ KEY_BBTTLS + " INTEGER NOT NULL, "
+ KEY_PBTTLS + " INTEGER NOT NULL, "
+ KEY_BTTLS + " INTEGER NOT NULL, "
+ KEY_SYNC + " TEXT NOT NULL, "
+ KEY_MODIF + " TEXT NOT NULL )";
String CREATE_MOVEMENTS_TABLE = "CREATE TABLE " + MOVEMENTS_TABLE + "("
+ MKEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
+ MKEY_ID_MOVE + "TEXT NOT NULL"
+ MKEY_CLIENT_ID + " INTEGER NOT NULL, "
+ MKEY_PICKUP + " INTEGER NOT NULL, "
+ MKEY_DELIVER + " INTEGER NOT NULL, "
+ MKEY_PAYMENT + " REAL NOT NULL, "
+ MKEY_MOVE_DATE + " TEXT NOT NULL, "
+ MKEY_SYNC_DATE + " TEXT NOT NULL, "
+ MKEY_FLAG_SYNC + " INTEGER NOT NULL )";
sqLiteDatabase.execSQL(CREATE_CLIENTS_TABLE);
sqLiteDatabase.execSQL(CREATE_MOVEMENTS_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + CLIENTS_TABLE);
sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + MOVEMENTS_TABLE);
onCreate(sqLiteDatabase);
}