Reputation: 381
I created a database called "enigmeDB" and a table "table_enigme":
public class EnigmeDatabase extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "enigmeBD";
private static final String TABLE_ENIGME = "table_enigme";
// fields
private static final String KEY_ID = "id";
private static final String KEY_DESCRIPTION = "description";
private static final String KEY_REPONSE="reponse";
private static final String KEY_CATEGORIE="categorie";
public EnigmeDatabase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
// creation of the table
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_ENIGME_TABLE =
"CREATE TABLE " + TABLE_ENIGME
+ "("
+ KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
+ KEY_DESCRIPTION + " TEXT,"
+ KEY_REPONSE + " TEXT,"
+ KEY_CATEGORIE + "TEXT"
+ ")";
db.execSQL(CREATE_ENIGME_TABLE);
}
// Update
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_ENIGME);
onCreate(db);
}....
When I open my DDMS perspective and open the file explorer: /data/data/com.android.enigme (my package) I find "enigmeDB" but I don't find "table_enigme".
Although in Sqlite database browser my table looks empty:
I insert data from an Activity , here is my class :
public class EnigmeActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//recuperation des champs depuis main.xml
final EditText description=(EditText) this.findViewById(R.id.description);
final EditText reponse=(EditText)this.findViewById(R.id.reponse);
final EditText categorie=(EditText)this.findViewById(R.id.categorie);
Button ajouter = (Button)this.findViewById(R.id.ajouter);
final EnigmeDatabase db=new EnigmeDatabase(this);
ajouter.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Log.d("Etape : " , "Recuperation");
Log.i("description : ", description.getText().toString());
Log.i("reponse : ", reponse.getText().toString());
Log.i("categorie : ", categorie.getText().toString());
//add a new Enigme
Log.d("Etape : ","Insertion" );
db.ajouterEnigme(new EnigmeBean(description.getText().toString(),reponse.getText().toString(),categorie.getText().toString()));
Toast.makeText(EnigmeActivity.this, "Ajout avec succes!", Toast.LENGTH_SHORT).show();
}
});
}
Upvotes: 1
Views: 3360
Reputation: 381
The error in insertion was in this ligne :
KEY_CATEGORIE + "TEXT"
the table created contains a column named "categorieTEXT" :
categorie is my column name , and TEXT its type
I had to make a space between " and TEXT , like so :
KEY_CATEGORIE + " TEXT"
Upvotes: 0
Reputation: 9439
The "databases" folder contains your database (a single file). There is no other file called "table".
Upvotes: 1
Reputation: 4168
"table_enigme" is in enigmBD. That file contains your database. That file in the explorer is the database. Not sure if you are looking for something more.
Your code does not insert any data, so the table should be empty.
Upvotes: 1
Reputation: 13855
That is a database file which holds all the tables.
You have opened it as in your last picture, and the column names exist as you created them.
The reason it is "empty" is because there is no data in it.
You need to populate your table with data.
Upvotes: 1
Reputation: 91912
In SQLite, all tables of a database are inside one single file.
Upvotes: 1