简体   繁体   English

有关Android App卸载和表状态的常见问题

[英]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. 我是android的新手,遇到困难时,我已在表中插入ID为主键唯一的表,当我试图从设备上卸载应用程序并尝试重新安装时,在插入过程中出现“主键必须是唯一的”错误明确指出,卸载应用程序不会删除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 : 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. 如果它是在默认位置“ ... data \\ data \\\\ databases”中创建的,则在卸载应用程序时将其删除。

You must have specified a path on the external sd card or somewhere else... 您必须在外部SD卡或其他位置指定了路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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