lundi 28 mars 2016

SQLITE query to create table is not working

Im trying to create a table with name "knowledge"

Following is my query,

private static final String CREATE_KNOWLEDGE_STATUTORY = "CREATE TABLE " + TABLE_KNOWLEDGE_STATUTORY + "("
            + KEY_ID + " INTEGER PRIMARY KEY,"
            + KEY_STATUTORY_MAPPING + " TEXT,"
            + KEY_LOCATION + " TEXT,"
            + KEY_DESCRIPTION + " TEXT,"
            + KEY_ACTIVE + " TEXT,"
            + KEY_PROVISION + " TEXT,"
            + KEY_COMPLIANCE_TASK + " TEXT,"
            + KEY_FORMAT_FILE_LIST + " TEXT,"
            + KEY_DURATION + " TEXT,"
            + KEY_DOC_NAME + " TEXT,"
            + KEY_PENAL_CONSEQUENCE + " TEXT,"
            + KEY_DURATION_ID + " TEXT,"
            + KEY_FREQUENCY_ID + " INTEGER,"
            + KEY_REPEAT_FREQ + " TEXT,"
            + KEY_COMPLIANCE_ID + " INTEGER,"
            + KEY_REPEAT_TYPE_ID + " TEXT,"
            + KEY_STATUTORY_MONTH + " TEXT,"
            + KEY_STATUTORY_DATE + " TEXT,"
            + KEY_TRIGGER_DATE + " TEXT,"
            + KEY_REPEAT_BY + " TEXT" + ");";

Following is my method that i use to create it,

public void addStatutory(StatutoryModel statutoryModel) {

        SQLiteDatabase sqLiteDatabase = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();

        contentValues.put(KEY_ID, statutoryModel.getId());
        contentValues.put(KEY_STATUTORY_MAPPING, statutoryModel.getStatuoryMapping());
        contentValues.put(KEY_LOCATION, statutoryModel.getLocation());
        contentValues.put(KEY_DESCRIPTION, statutoryModel.getDescription());
        contentValues.put(KEY_ACTIVE, statutoryModel.getIsStatutoryActive());
        contentValues.put(KEY_PROVISION, statutoryModel.getStatutoryProvision());
        contentValues.put(KEY_COMPLIANCE_TASK, statutoryModel.getComplianceTask());
        contentValues.put(KEY_FORMAT_FILE_LIST, statutoryModel.getFormat_fileList());
        contentValues.put(KEY_DURATION, statutoryModel.getDuration());
        contentValues.put(KEY_DOC_NAME, statutoryModel.getDocument_name());
        contentValues.put(KEY_PENAL_CONSEQUENCE, statutoryModel.getPenalConsequences());
        contentValues.put(KEY_DURATION_ID, statutoryModel.getDurationType_id());
        contentValues.put(KEY_FREQUENCY_ID, statutoryModel.getFrequencyId());
        contentValues.put(KEY_REPEAT_FREQ, statutoryModel.getRepeatsEvery());
        contentValues.put(KEY_COMPLIANCE_ID, statutoryModel.getComplianceId());
        contentValues.put(KEY_REPEAT_TYPE_ID, statutoryModel.getRepeatsTypeId());
        contentValues.put(KEY_STATUTORY_MONTH, statutoryModel.getStatutory_month());
        contentValues.put(KEY_STATUTORY_DATE, statutoryModel.getStatutory_date());
        contentValues.put(KEY_TRIGGER_DATE, statutoryModel.getTrigger_before_days());
        contentValues.put(KEY_REPEAT_BY, statutoryModel.getRepeat_by());

        sqLiteDatabase.insert(TABLE_KNOWLEDGE_STATUTORY,null,contentValues);
        sqLiteDatabase.close();
    }

Im invoking it as

DbHandler dbHandler = new DbHandler(getActivity());
dbHandler.addStatutory(new StatutoryModel(i, dbDesc, isStatutoryActive, statutoryProvision, complianceTask, format_fileList, duration, penalConsequences, document_name, durationType_id, frequencyId, repeatsEvery, repeatsTypeId, complianceId, statutory_month, statutory_date, trigger_before_days, repeat_by, compDescription, dbLoc));

The problem is that Im getting like no such table exists error. Following is my error Log.

no such table: knowledge 03-28 15:58:48.584 28428-28428/? E/SQLiteDatabase: Error inserting repeatsEvery=null document_name=null location=India >> South statutoryProvision=Statutory Provision 2603161717 statutory_month=null statutoryMapping=Compliance Description 2603161717 statutory_date=null repeatsTypeId=null duration=null frequencyId=1 _id=1 repeat_by=dayofmonth complianceId=26 penalConsequences= complianceTask=Compliance Task 2603161717-1 trigger_before_days=null description=PRIMARY LEGISLATION 2503161026>>Secondary Legislation 2603161717 format_fileList=null durationType_id=null isStatutoryActive=true android.database.sqlite.SQLiteException: no such table: knowledge (code 1): , while compiling: INSERT INTO knowledge(repeatsEvery,document_name,location,statutoryProvision,statutory_month,statutoryMapping,statutory_date,repeatsTypeId,duration,frequencyId,_id,repeat_by,complianceId,penalConsequences,complianceTask,trigger_before_days,description,format_fileList,durationType_id,isStatutoryActive) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)

Aucun commentaire:

Enregistrer un commentaire