How to find my .db file in sqlite?

被刻印的时光 ゝ 提交于 2019-12-08 07:33:54

问题


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();

        }

        });


}

回答1:


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.




回答2:


In SQLite, all tables of a database are inside one single file.




回答3:


"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.




回答4:


The "databases" folder contains your database (a single file). There is no other file called "table".




回答5:


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"



来源:https://stackoverflow.com/questions/11483992/how-to-find-my-db-file-in-sqlite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!