你好我是移动开发者的新手!我有SQLite的问题!我想创建2个表,但无法创建第二个表。 我创建一个没有任何问题的表,但如果我想创建另一个我有问题!如果我执行getAllTableNames,则不会创建我的表。这是我的模特..
public class Model extends SQLiteOpenHelper {
public Model(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.execSQL("CREATE TABLE Plat(C_IDplat INTEGER PRIMARY KEY AUTOINCREMENT , C_IDcategorie INTEGER , C_Nomplat TEXT , C_Photoplat TEXT , C_Descriptionplat TEXT) ");
sqLiteDatabase.execSQL("CREATE TABLE Categorie(C_ID INTEGER PRIMARY KEY AUTOINCREMENT , C_Nom TEXT , C_Photo TEXT , C_Description TEXT) ");
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
sqLiteDatabase.execSQL("DROP TABLE IF EXISTS Categorie");
sqLiteDatabase.execSQL("DROP TABLE IF EXISTS Plat");
// recreate the tables
onCreate(sqLiteDatabase);
}
public void save(Categorie C) {
ContentValues v = new ContentValues();
v.put("C_Nom", C.getNom());
v.put("C_Photo", C.getPhoto());
v.put("C_Description", C.getDescription());
long id = C.getId();
if (id == 0) {
id = this.getWritableDatabase().insert("Categorie", null, v);
C.setId(id);
} else {
this.getWritableDatabase().update("Categorie", v, "C_ID = ?", new String[]{String.valueOf(id)});
}
}
检查这个`* / 公共类菜单扩展了AppCompatActivity {
Model m1 = new Model(this , "DB", null , 3); // i instaciate my model
Categorie pizza = new Categorie("Pizza" , R.drawable.pizza , "Les meilleurs pizza de Dakar " );
Categorie baguettes = new Categorie("Baguettes" , R.drawable.baguette , "Explosion de saveurs a prix mini");
Categorie pastas = new Categorie("Pastas" , R.drawable.pastas , "Laissez vous tenter ");
Categorie donuts = new Categorie("Donuts" , R.drawable.donuts , "Al dente et tellement genereuses");
Categorie snacks = new Categorie("Snacks" , R.drawable.snacks , "Un delice a chaque bouchée");
Categorie Boisson_gaz = new Categorie("Boissons Gazeuses" , R.drawable.gazeuse , "Pensez a vous desalterer");
Categorie Alcool = new Categorie("Alcool" , R.drawable.alcool , "De la bonne qualite");
Categorie Cocktail = new Categorie("Cocktail" , R.drawable.cocktail , "Decouvrez nos cocktails");
Categorie Boisson_chaude = new Categorie("Boissons chaudes" , R.drawable.chaude , "Un bon cafe ne fait jamais de mal");
Monplat plat1 = new Monplat("Renne","une bonne pizza " , R.drawable.pizza);
Monplat plat2 = new Monplat("Renne","une bonne pizza " , R.drawable.pizza);
Monplat plat3 = new Monplat("Renne","une bonne pizza " , R.drawable.pizza);
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menus);
List<String> listetable = m1.getAllTableName(); // i check here if my all table are being created but only the first table i createe yesterday is created
Log.i("Liste" , "listeTable :"+listetable);
`