zoukankan      html  css  js  c++  java
  • 数据库升级 给原有的表增加字段

    Logcat报了如下的错误:android.database.sqlite.SQLiteException: near ",": syntax error (code 1): , while compiling:  alter table playhistory add src_type INTEGER,total_time long,definition integer,current_time long,web_type integer,total_episodes integer


    分析:

    由于alter table tablename add 后面加了多个列导致失败。

    如果要增加多个列,需要把这句话拆分成一个个单独的alter table语句。

    ALTER TABLE syntax

    从官方的图例上可以看出,alter table tablename add column 本身不支持Loop循环。


    @Override
            public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
                if (oldVersion < 2) {
                    new_column = "alter table " + PlayHistoryTable.TABLE_NAME + " add " + PlayHistoryTable.SRC_TYPE + " integer";
                    db.execSQL(new_column);
                    new_column = "alter table " + PlayHistoryTable.TABLE_NAME + " add " + PlayHistoryTable.TIME_TOTAL + " long";
                    db.execSQL(new_column);
                    new_column = "alter table " + PlayHistoryTable.TABLE_NAME + " add " + PlayHistoryTable.DEFINITION + " integer";
                    db.execSQL(new_column);
                    new_column = "alter table " + PlayHistoryTable.TABLE_NAME + " add " + PlayHistoryTable.CURRENT_TIME + " long";
                    db.execSQL(new_column);
                    new_column = "alter table " + PlayHistoryTable.TABLE_NAME + " add " + PlayHistoryTable.WEB_TYPE + " integer";
                    db.execSQL(new_column);
                    new_column = "alter table " + PlayHistoryTable.TABLE_NAME + " add " + PlayHistoryTable.TOTAL_EPISODES + " integer";
                    db.execSQL(new_column);
    
                    db.execSQL(SQL_CREATE_DOWNLOAD);
                }
            }


  • 相关阅读:
    BZOJ 1103 Poi2007 大都市meg
    BZOJ 2815 ZJOI2012 灾难
    【bzoj】1046: [HAOI2007]上升序列
    P1168跳房子(焫鷄如我)
    HAIO2017[打酱油的旅行!?]
    [haoi2013]花卉节
    P1298(矩阵切割)DP
    P1216 (list加强版)
    p1219最佳贸易(两边bfs写的)
    p1150[noip2013普及]表达式求值
  • 原文地址:https://www.cnblogs.com/ameryzhu/p/6555616.html
Copyright © 2011-2022 走看看