简体   繁体   中英

General Questions Regarding Android App Uninstall and Status of Tables

i am newbie in android and getting difficulty i have insert data in table with Id as Primary Key Unique , When i am trying to unInstall app from Device and trying to reinstall again its giving me error during Insertion that "primary Key must be unique" which clearly states that unInstall of app does not remove TABLES.

Please do comment about this Table Information.This is big issue in my case and i am failed to move a head just becuase of this problem

Code of SQLITEHelper :

package com.survey.management.util;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DatabaseHelper extends SQLiteOpenHelper {

    public static final String DB_NAME = "surveyapp.db";
    private static final int DB_VER = 1;
    private static final String TAG = "DATABASE_HELPER";
    private static final String parameterString = "CREATE TABLE IF NOT EXISTS parameterTable(ID INTEGER PRIMARY KEY AUTOINCREMENT,param_type TEXT,cash_code TEXT,param_description TEXT)";
    private static final String menuFieldsString = "CREATE TABLE IF NOT EXISTS menu_fieldsTable('ID' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,'menu_id' INTEGER NOT NULL,'field_type_id' INTEGER NOT NULL,'c4w_code' TEXT,'field_label' TEXT NOT NULL,'field_values' TEXT,'date_created' DATETIME,'date_modified' DATETIME,'is_required' INTEGER DEFAULT 0,'is_static' INTEGER DEFAULT 0,'field_order' INTEGER DEFAULT NULL)";
    private static final String briefTable = "CREATE TABLE IF NOT EXISTS proposalEnquiry('ID' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,'caller_name' TEXT NOT NULL,'telephone_number' TEXT DEFAULT NULL,'email_address' TEXT NOT NULL,'address' TEXT NOT NULL,'requirements' TEXT NOT NULL,'work_done' TEXT DEFAULT NULL,'proposal_id' INTEGER DEFAULT NULL,'date_created' datetime DEFAULT NULL,'date_modified' datetime DEFAULT NULL,'system_type' TEXT DEFAULT NULL,'premises_type' TEXT DEFAULT NULL,'premises_size' TEXT DEFAULT NULL,'internal_notes' TEXT,'company_name' TEXT DEFAULT NULL,'post_code' TEXT NOT NULL,'hear_for_us' TEXT DEFAULT NULL,'surveyor' TEXT DEFAULT NULL,'estimator' TEXT DEFAULT NULL)";
    private static final String customerTable = "CREATE TABLE IF NOT EXISTS customer('ID' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,'company_name' TEXT ,'contact_person_name' TEXT,'email_address' TEXT ,'contact_person_title' TEXT DEFAULT NULL,'customer_no' TEXT DEFAULT NULL,'contact_person_position' TEXT DEFAULT NULL,'dear_name' TEXT DEFAULT NULL,'address_1' TEXT DEFAULT NULL,'address_2' TEXT DEFAULT NULL,'address_3' TEXT DEFAULT NULL,'address_4' TEXT DEFAULT NULL,'postcode' TEXT DEFAULT NULL,'telephone_number' TEXT DEFAULT NULL,'mobile_number' TEXT DEFAULT NULL,'fax_number' TEXT DEFAULT NULL,'vat_number' TEXT DEFAULT NULL,'email_address_for_invoicing' TEXT DEFAULT NULL)";
    private static final String mainSetupTable = "CREATE TABLE IF NOT EXISTS main_setup('ID' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,'surveyour_id' INTEGER DEFAULT NULL,'enquiry_no' TEXT DEFAULT NULL,'status' TEXT NOT NULL,'end_user_contractor' TEXT DEFAULT NULL,'proposal_type' TEXT DEFAULT NULL, 'proposal_based' TEXT DEFAULT NULL, 'invoice_method' TEXT DEFAULT NULL, 'deposit_required' REAL DEFAULT NULL, 'Increase_in_maint' TEXT DEFAULT NULL, 'completion_date' DATE DEFAULT NULL, 'date_created' DATETIME NULL, 'date_modified' DATETIME , 'version' REAL  DEFAULT 1,  'estimator_id' INTEGER DEFAULT NULL, 'enquiry_date' DATE DEFAULT NULL, 'quotation_date' DATE DEFAULT NULL, 'enquiry_type' TEXT DEFAULT NULL, 'created_by' INTEGER NOT NULL, 'assigned_me' INTEGER DEFAULT NULL,'total_cost' REAL,'total_sale' REAL, 'vat' TEXT DEFAULT NULL, 'appointment_date' DATE DEFAULT NULL , 'appointment_time' TIME DEFAULT NULL, 'contract_type' TEXT DEFAULT NULL,'contract_term' TEXT DEFAULT NULL,'quotation_sent_date' DATETIME DEFAULT NULL, 'proposal_due_date' DATETIME DEFAULT NULL ,'email_sent_by_user' INTEGER,'assigned_surveyour' INTEGER,'email_sent_time' DATETIME DEFAULT NULL,'linked_to' INTEGER)";



public DatabaseHelper(Context context) {
        super(context,DB_NAME,null,DB_VER);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {


        db.execSQL(parameterString);
        db.execSQL(menuFieldsString);
        db.execSQL(briefTable);
        db.execSQL(customerTable);
        db.execSQL(mainSetupTable);
        Log.i(TAG,"parameter table onCreate executed..........!");

    }

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

        Log.w(TAG,"Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data");
        try {
            db.execSQL("DROP TABLE IF EXISTS parameterString");

            onCreate(db);

        }
        catch (SQLException e) {
            Log.e(TAG, "getting exception " + e.getLocalizedMessage().toString());
            ExceptionHandler.logException(e);
        }
    }

}

It depends where you have created the database. If it was created in the default location "...data\\data\\\\databases" then it is removed when you uninstall the application.

You must have specified a path on the external sd card or somewhere else...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM