首页 > 数据库技术 > 详细

数据库升级 给原有的表增加字段

时间:2014-01-21 01:15:35      阅读:490      评论:0      收藏:0      [点我收藏+]

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语句。

bubuko.com,布布扣

从官方的图例上可以看出,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);
            }
        }


数据库升级 给原有的表增加字段

原文:http://blog.csdn.net/ameryzhu/article/details/18319839

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!