Android sqlite创建表查询无法创建表

时间:2013-11-19 01:45:01

标签: android sqlite

我是Android的新手并试图使用sqlite DB但在创建表时面临一些问题。我创建了一个要触发的查询字符串,并在onCreate中使用DB.execSQl来触发查询

先谢谢

//create table query created
private static final String CREATE_RULES = "CREATE TABLE IF NOT EXISTS "
                + TABLE_RULES + " (" + COLUMN_RULE_ID
                + " INTEGER PRIMARY KEY  NOT NULL  DEFAULT (0) ,"
                + COLUMN_RULE_NAME + " VARCHAR," + COLUMN_RULE_DESCRIPTION
                + " VARCHAR," + COLUMN_TIME_INTERVAL_DAY + " VARCHAR,"
                + COLUMN_IS_DATA_USAGE + " VARCHAR," + COLUMN_IS_VOICE_USAGE
                + " VARCHAR," + COLUMN_VOICE_OUTGOING_LIMIT_YELLOW
                + " DOUBLE DEFAULT (null) ," + COLUMN_VOICE_INCOMING_LIMIT_YELLOW
                + " DOUBLE DEFAULT (null) ," + COLUMN_VOICE_INCOMING_LIMIT_RED
                + " DOUBLE DEFAULT (null) ," + COLUMN_VOICE_OUTGOIONG_LIMIT_RED
                + " DOUBLE DEFAULT (null) ," + COLUMN_DATA_UPLOAD_LIMIT_YELLOW
                + " DOUBLE DEFAULT (null) ," + COLUMN_DATA_DOWNLOAD_LIMIT_YELLOW
                + " DOUBLE DEFAULT (null) ," + COLUMN_DATA_UPLOAD_LIMIT_RED
                + " DOUBLE DEFAULT (null) ," + COLUMN_DATA_DOWNLOAD_LIMIT_RED
                + " DOUBLE DEFAULT (null) ," + COLUMN_IS_DATA_USAGE_ROAMING
                + " VARCHAR," + COLUMN_IS_VOICE_USAGE_ROAMING + " VARCHAR,"
                + COLUMN_DATA_ROAMING_UPLOAD_LIMIT_YELLOW
                + " DOUBLE DEFAULT (null) ," + COLUMN_DATA_ROAMING_UPLOAD_LIMIT_RED
                + " DOUBLE DEFAULT (null) ,"
                + COLUMN_DATA_ROAMING_DOWNLOAD_LIMIT_YELLOW
                + " DOUBLE DEFAULT (null) ,"
                + COLUMN_DATA_ROAMING_DOWNLOAD_LIMIT_RED
                + " DOUBLE DEFAULT (null) ,"
                + COLUMN_VOICE_ROAMING_INCOMING_LIMIT_YELLOW
                + " DOUBLE DEFAULT (null) ,"
                + COLUMN_VOICE_ROAMING_INCOMING_LIMIT_RED
                + " DOUBLE DEFAULT (null) ,"
                + COLUMN_VOICE_ROAMING_OUTGOING_LIMIT_YELLOW
                + " DOUBLE DEFAULT (null) ,"
                + COLUMN_VOICE_ROAMING_OUTGOING_LIMIT_RED
                + " DOUBLE DEFAULT (null) ," + COLUMN_CREATED_DATE + " DATETIME,"
                + COLUMN_MODIFIED_DATE + " DATETIME,"
                + COLUMN_BASE_LINE_USAGE_RECEIVED + " DOUBLE DEFAULT (null) ,"
                + COLUMN_BASE_LINE_USAGE_SENT + " DOUBLE DEFAULT (null) ,"
                + COLUMN_BASE_LINE_ROAMING_USAGE_RECEIVED
                + " DOUBLE DEFAULT (null) ," + COLUMN_BASE_LINE_ROAMING_USAGE_SENT
                + " DOUBLE DEFAULT (null) ," + COLUMN_CURRENT_USAGE_RECEIVED
                + " DOUBLE DEFAULT (null) ," + COLUMN_CURRENT_USAGE_SENT
                + " DOUBLE DEFAULT (null) ,"
                + COLUMN_CURRENT_ROAMING_USAGE_RECEIVED
                + " DOUBLE DEFAULT (null) ," + COLUMN_CURRENT_ROAMING_USAGE_SENT
                + " DOUBLE DEFAULT (null) ," + COLUMN_CURRENT_VOICE_USAGE_RECEIVED
                + " DOUBLE DEFAULT (null) ," + COLUMN_CURRENT_VOICE_USAGE_SENT
                + " DOUBLE DEFAULT (null) ,"
                + COLUMN_CURRENT_ROAMING_VOICE_USAGE_RECEIVED
                + " DOUBLE DEFAULT (null) ,"
                + COLUMN_CURRENT_ROAMING_VOICE_USAGE_SENT
                + " DOUBLE DEFAULT (null) ," + COLUMN_MESSAGE_TO_USER_YELLOW
                + " VARCHAR," + COLUMN_MESSAGE_TO_USER_RED + " VARCHAR,"
                + COLUMN_RULE_SERVER_ID + " VARCHAR,"
                + COLUMN_IS_YELLOW_DATA_UPLOAD_LIMIT_ALERT_SHOWN + " VARCHAR,"
                + COLUMN_IS_RED_DATA_UPLOAD_LIMIT_ALERT_SHOWN + " VARCHAR,"
                + COLUMN_IS_YELLOW_VOICE_INCOMING_LIMIT_ALERT_SHOWN + " VARCHAR,"
                + COLUMN_IS_RED_VOICE_INCOMING_LIMIT_ALERT_SHOWN + " VARCHAR," 
                + COLUMN_IS_YELLOW_DATA_DOWNLOAD_LIMIT_ALERT_SHOWN + " VARCHAR," 
                + COLUMN_IS_RED_VOICE_OUTGOING_LIMIT_ALERT_SHOWN + " VARCHAR,"
                + COLUMN_IS_YELLOW_VOICE_OUTGOING_LIMIT_ALERT_SHOWN + " VARCHAR,"
                + COLUMN_IS_RED_DATA_UPLOAD_ROAMING_LIMIT_ALERT_SHOWN + " VARCHAR,"
                + COLUMN_IS_YELLOW_DATA_UPLOAD_ROAMING_LIMIT_ALERT_SHOWN + " VARCHAR,"
                + COLUMN_IS_RED_VOICE_INCOMING_ROAMING_LIMIT_ALERT_SHOWN + " VARCHAR,"
                + COLUMN_IS_YELLOW_VOICE_INCOMING_ROAMING_LIMIT_ALERT_SHOWN + " VARCHAR,"
                + COLUMN_IS_RED_DATA_DOWNLOAD_ROAMING_LIMIT_ALERT_SHOWN + " VARCHAR,"
                + COLUMN_IS_YELLOW_DATA_DOWNLOAD_ROAMING_LIMIT_ALERT_SHOWN + " VARCHAR,"
                + COLUMN_IS_RED_VOICE_OUTGOING_ROAMING_LIMIT_ALERT_SHOWN + " VARCHAR,"
                + COLUMN_IS_YELLOW_VOICE_OUTGING_ROAMING_LIMIT_ALERT_SHOWN + " VARCHAR,"
                + COLUMN_IS_RED_DATA_DOWNLOAD_LIMIT_ALERT_SHOWN + " VARCHAR,"
                + COLUMN_USER_RULE_ID +"VARCHAR);";



        public DatabaseManager(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }
    //in onCreate of a class CREATE table query is fired
        @Override
        public void onCreate(SQLiteDatabase db) {
        Log.i("DB manager","tables"+CREATE_RULES);
                db.execSQL("DROP TABLE IF EXISTS TABLE_RULES");

                db.execSQL(CREATE_DATAUSAGE);
                db.execSQL(CREATE_RULES);

        }

0 个答案:

没有答案