jeudi 2 juillet 2015

Unable to view SqlLite Db in DDMS Mode Inside File Explorer

I followed a few examples and tried creating multiple tables in one Database in SQLLite. But I am Unable to see the DB in DDMS Mode in my emulator. I created two Database One For Login and One for the Entire Application. The Login Db is visible in File Explorer Tab Inside DDMS View in Eclipse. I think my DBHelper Class has some issue. If u can Pls review it and let me know the issue

I intialize it in on page like this

Inititate

DBHelper helper;

final Context context = this;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.studentsignup)

    //Initiate DB
    helper = new DBHelper(context);

Code

        package com.demo.assesmenttool;

    /***
     *    Application Name : DemoProject
     *    Author : Tushar Narang
     *    Website : ------
     */


    import android.content.Context;
    import android.database.Cursor;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteOpenHelper;

    public class DBHelper extends SQLiteOpenHelper {

        // Static Final Variable database meta information

        static final String DATABASE = "AssesmentTool.db";
        static final int VERSION = 1;

        //Table Student Details
        static final String TABLEStudent = "StudentDetails";
        static final String S_ID = "_id";
        static final String SchoolID = "schoolid";
        static final String SchoolName = "schoolname";
        static final String StudentFirstName = "StudentFirstName";
        static final String StudentLastName ="StudentLastName";
        static final String StudentClassLevel ="StudentClassLevel";
        static final String RollNo="RollNo";
        static final String TestDate ="TestDate";

         //Table Response Details   
        static final String TABLEResponse = "TableResponse";
        static final String R_ID = "_id";
        static final String StudentID = "StudentID";
        static final String R_QuestionID = "QuestionID";
        static final String QuestOptionID = "QuestOptionID";

        //Table Question Master
        static final String TableQuestionMaster = "questionmaster";
        static final String Q_ID= "_id";
        static final String Title = "Title";
        static final String TitleDescription = "TitleDescription";
        static final String QuestionText = "QuestionText";
        static final String QuestionImage = "QuestionImage";
        static final String QuestionTemplate = "QuestionTemplate";
        static final String CorrectOptionID = "CorrectOptionID";

        //Table Template Master
        static final String TableTemplateMaster = "TemplateMaster";
        static final String T_ID= "_id";
        static final String Name = "Name";
        static final String Description = "Description";

        //Table Question Option 
        static final String TableQuestionOption = "TableQuestionOption";
        static final String TQP_ID= "_id";
        static final String TQP_QuestionID = "QuestionID";
        static final String OptionText = "OptionText";

        // Override constructor
        public DBHelper(Context context) {
            super(context, DATABASE, null, VERSION);

        }

        // Override onCreate method
        @Override
        public void onCreate(SQLiteDatabase db) {


            //Create Table Student Details
            db.execSQL("CREATE TABLE " + TABLEStudent + " ( " + S_ID
                    + " INTEGER PRIMARY KEY AUTOINCREMENT, " + SchoolID + " INTEGER, "
                    + SchoolName + " text, " + StudentFirstName + " text, "  + StudentLastName + " text, " + RollNo + " INTEGER," + TestDate + " text," + StudentClassLevel + " text)");


            //Create Table Response Details     
            db.execSQL("CREATE TABLE " + TABLEResponse + " ( " + R_ID
                    + " INTEGER PRIMARY KEY AUTOINCREMENT, " + StudentID + " text, "
                    + R_QuestionID + " text, " + QuestOptionID + " text)");


            //Create Table Question Master
            db.execSQL("CREATE TABLE " + TableQuestionMaster + " ( " + Q_ID
                    + " INTEGER PRIMARY KEY AUTOINCREMENT, " + Title + " text, "
                    + TitleDescription + " text, " + QuestionText + " text, "  + QuestionImage + " text, " + QuestionTemplate + " INTEGER," + CorrectOptionID + " INTEGER)");


            //Create Table Template Master
            db.execSQL("CREATE TABLE " + TableTemplateMaster + " ( " + T_ID
                    + " INTEGER PRIMARY KEY AUTOINCREMENT, " + Name + " text, "
                    + Description + " text)");


            //Create Table Question Option  
            db.execSQL("CREATE TABLE " + TableQuestionOption + " ( " + TQP_ID
                    + " INTEGER PRIMARY KEY AUTOINCREMENT, " + TQP_QuestionID + " INTEGER, "
                    + OptionText + " text)");   

        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

            // Drop old version table
            db.execSQL("Drop table " + TABLEStudent);
            db.execSQL("Drop table " + TABLEResponse);
            db.execSQL("Drop table " + TableQuestionMaster);
            db.execSQL("Drop table " + TableTemplateMaster);
            db.execSQL("Drop table " + TableQuestionOption);
            // Create New Version table
            onCreate(db);
        }

}

Aucun commentaire:

Enregistrer un commentaire