微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android-SQLite插入引发语法异常

我从sqlite收到此错误,

靠近“,”:语法错误(代码1):,而在编译时:

UPDATE OutfitItem 
SET outfit_img_relative_pos_x=?,clothing_item_ID=?,outfit_img_relative_pos_y=?,
outfit_img_relative_size_width=?,outfit_ID=?,outfit_img_relative_size_height=? 
WHERE (outfit_ID,clothing_item_ID) = (60,5)

有人可以为我找出错误吗?

以下是被编译的代码

// ---updates a outfitItem---
        public boolean update(long outfitID, long clothingItemID, double imgrelativePos_X, double imgrelativePos_Y,
                double imgrelativeSize_width, double imgrelativeSize_height)
        {
            ContentValues args = new ContentValues();
            args.put(KEY_OUTFIT_ID, outfitID);
            args.put(KEY_CLOTHING_ITEM_ID, clothingItemID);
            args.put(KEY_OUTFIT_IMAGE_RELATIVE_POS_X, imgrelativePos_X);
            args.put(KEY_OUTFIT_IMAGE_RELATIVE_POS_Y, imgrelativePos_Y);
            args.put(KEY_OUTFIT_IMAGE_RELATIVE_SIZE_WIDTH, imgrelativeSize_width);
            args.put(KEY_OUTFIT_IMAGE_RELATIVE_SIZE_HEIGHT, imgrelativeSize_height);
            return db.update(TABLE_NAME, args, "(" + KEY_OUTFIT_ID + "," + KEY_CLOTHING_ITEM_ID + ") = (" + outfitID
                    + "," + clothingItemID + ")", null) > 0;
        }

以下是创建表的代码,并注意将外键设置为on …

public static final String TABLE_NAME = "OutfitItem";

        public static final String TABLE_CREATE = "create table " + TABLE_NAME + "(" + KEY_OUTFIT_ID
                + " int not null REFERENCES " + Table_Outfit.TABLE_NAME + "(" + KEY_OUTFIT_ID + ") ON DELETE CASCADE,"
                + KEY_CLOTHING_ITEM_ID + " int not null REFERENCES " + Table_ClothingItem.TABLE_NAME + "("
                + KEY_CLOTHING_ITEM_ID + ") ON DELETE CASCADE, " + KEY_OUTFIT_IMAGE_RELATIVE_POS_X + " real not null, "
                + KEY_OUTFIT_IMAGE_RELATIVE_POS_Y + " real not null, " + KEY_OUTFIT_IMAGE_RELATIVE_SIZE_WIDTH
                + " real not null, " + KEY_OUTFIT_IMAGE_RELATIVE_SIZE_HEIGHT + " real not null, " + "primary key ("
                + KEY_OUTFIT_ID + "," + KEY_CLOTHING_ITEM_ID + "));";

解决方法:

您的问题出在您的WHERE子句中:

WHERE (outfit_ID,clothing_item_ID) = (60,5)

这是无效的sql语法.您需要对AND联接使用单独的条件.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐