Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

180行执行报错:【Failed to restore data from temp table 】MUSIC_TEMP android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: MUSIC._id (code 1555) #29

Closed
yuxingfafu opened this issue Jul 12, 2017 · 4 comments

Comments

@yuxingfafu
Copy link

07-12 15:44:32.985 2846-2846/com.jinrisheng.yinyuehui E/MigrationHelper: 【Failed to restore data from temp table 】MUSIC_TEMP
android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: MUSIC._id (code 1555)
at android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(Native Method)
at android.database.sqlite.SQLiteConnection.executeForChangedRowCount(SQLiteConnection.java:732)
at android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:754)
at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:64)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1676)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1605)
at org.greenrobot.a.d.f.a(StandardDatabase.java:37)
at com.jinrisheng.yinyuehui.util.b.b.c(MigrationHelper.java:180)

@yuxingfafu
Copy link
Author

yuxingfafu commented Jul 12, 2017

~
package com.jinrisheng.yinyuehui.model;

import android.os.Parcel;
import android.os.Parcelable;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Property;
import org.greenrobot.greendao.annotation.Unique;
import org.greenrobot.greendao.annotation.Generated;

/**

  • 单曲信息

  • Created by wcy on 2015/11/27.
    */
    @entity
    public class Music implements Parcelable {

    @Property
    @unique
    private String musicId;
    @id(autoincrement=true)
    private Long id;
    @Property
    private String title; // 音乐标题
    @Property
    private String artist; // 艺术家
    @Property
    private String album; // 专辑
    @Property
    private long duration; // 持续时间
    @Property
    private String path; // 音乐路径
    @Property
    private String coverPath; // 专辑封面路径
    @Property
    private String fileName; // 文件名
    @Property
    private long fileSize; // 文件大小
    @Property
    private Integer isCollect ;// 是否收藏 1是0否
    private boolean isClick;
    @Property
    private int musicType;//1 音乐 2 节目
    @Property
    private String lrcPath;
    @Property
    private String time;
    @Property
    private int isVip;

    public String getMusicId() {
    return musicId;
    }

    public void setMusicId(String musicId) {
    this.musicId = musicId;
    }

    public Long getId() {
    return id;
    }

    public void setId(Long id) {
    this.id = id;
    }

    public String getTitle() {
    return title;
    }

    public void setTitle(String title) {
    this.title = title;
    }

    public String getArtist() {
    return artist;
    }

    public void setArtist(String artist) {
    this.artist = artist;
    }

    public String getAlbum() {
    return album;
    }

    public void setAlbum(String album) {
    this.album = album;
    }

    public long getDuration() {
    return duration;
    }

    public void setDuration(long duration) {
    this.duration = duration;
    }

    public String getPath() {
    return path;
    }

    public void setPath(String path) {
    this.path = path;
    }

    public String getCoverPath() {
    return coverPath;
    }

    public void setCoverPath(String coverPath) {
    this.coverPath = coverPath;
    }

    public String getFileName() {
    return fileName;
    }

    public void setFileName(String fileName) {
    this.fileName = fileName;
    }

    public long getFileSize() {
    return fileSize;
    }

    public void setFileSize(long fileSize) {
    this.fileSize = fileSize;
    }

    public Integer getIsCollect() {
    return isCollect;
    }

    public void setIsCollect(Integer isCollect) {
    this.isCollect = isCollect;
    }

    public boolean isClick() {
    return isClick;
    }

    public void setClick(boolean click) {
    isClick = click;
    }

    public int getMusicType() {
    return musicType;
    }

    public void setMusicType(int musicType) {
    this.musicType = musicType;
    }

    public String getLrcPath() {
    return lrcPath;
    }

    public void setLrcPath(String lrcPath) {
    this.lrcPath = lrcPath;
    }

    public String getTime() {
    return time;
    }

    public void setTime(String time) {
    this.time = time;
    }

    public int getIsVip() {
    return isVip;
    }

    public void setIsVip(int isVip) {
    this.isVip = isVip;
    }

    @OverRide
    public int describeContents() {
    return 0;
    }

    @OverRide
    public void writeToParcel(Parcel dest, int flags) {
    dest.writeString(this.musicId);
    dest.writeValue(this.id);
    dest.writeString(this.title);
    dest.writeString(this.artist);
    dest.writeString(this.album);
    dest.writeLong(this.duration);
    dest.writeString(this.path);
    dest.writeString(this.coverPath);
    dest.writeString(this.fileName);
    dest.writeLong(this.fileSize);
    dest.writeValue(this.isCollect);
    dest.writeByte(this.isClick ? (byte) 1 : (byte) 0);
    dest.writeInt(this.musicType);
    dest.writeString(this.lrcPath);
    dest.writeString(this.time);
    dest.writeInt(this.isVip);
    }

    public boolean getIsClick() {
    return this.isClick;
    }

    public void setIsClick(boolean isClick) {
    this.isClick = isClick;
    }

    public Music() {
    }

    protected Music(Parcel in) {
    this.musicId = in.readString();
    this.id = (Long) in.readValue(Long.class.getClassLoader());
    this.title = in.readString();
    this.artist = in.readString();
    this.album = in.readString();
    this.duration = in.readLong();
    this.path = in.readString();
    this.coverPath = in.readString();
    this.fileName = in.readString();
    this.fileSize = in.readLong();
    this.isCollect = (Integer) in.readValue(Integer.class.getClassLoader());
    this.isClick = in.readByte() != 0;
    this.musicType = in.readInt();
    this.lrcPath = in.readString();
    this.time = in.readString();
    this.isVip = in.readInt();
    }

    @generated(hash = 141852340)
    public Music(String musicId, Long id, String title, String artist, String album,
    long duration, String path, String coverPath, String fileName,
    long fileSize, Integer isCollect, boolean isClick, int musicType,
    String lrcPath, String time, int isVip) {
    this.musicId = musicId;
    this.id = id;
    this.title = title;
    this.artist = artist;
    this.album = album;
    this.duration = duration;
    this.path = path;
    this.coverPath = coverPath;
    this.fileName = fileName;
    this.fileSize = fileSize;
    this.isCollect = isCollect;
    this.isClick = isClick;
    this.musicType = musicType;
    this.lrcPath = lrcPath;
    this.time = time;
    this.isVip = isVip;
    }

    public static final Creator CREATOR = new Creator() {
    @OverRide
    public Music createFromParcel(Parcel source) {
    return new Music(source);
    }

     @Override
     public Music[] newArray(int size) {
         return new Music[size];
     }
    

    };
    }

@yuweiguocn
Copy link
Owner

添加了唯一键约束@unique导致的,把@unique去掉试试。

@atearsan
Copy link

atearsan commented Nov 15, 2017

@yuweiguocn id如果设置成主键就是不能重复的。
把INSERT INTRO换成INSERT OR REPLACE INTO可以处理重复的问题。
@yuxingfafu

@yuweiguocn
Copy link
Owner

@atearsan 好的,感谢。

yuweiguocn added a commit that referenced this issue Nov 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants