litesuits / android-lite-orm

LiteOrm is a fast, small, powerful ORM framework for Android. LiteOrm makes you do CRUD operarions on SQLite database with a sigle line of code efficiently.
http://litesuits.com?form=gorm
Apache License 2.0
1.49k stars 362 forks source link

更新数据失败 #64

Open litangyu opened 7 years ago

litangyu commented 7 years ago

日志如下: 06-14 11:15:48.229 22355-22355/com.xiaonengtech.ttwk.debug D/SQLStatement: SQL Execute: [UPDATE com_xiaonengtech_ttwk_api_type_Video SET is_publish=? WHERE uuid] ARGS--> [1, 481567e3-ef42-4766-8268-2c26fb78bad9] 06-14 11:15:48.231 22355-22355/com.xiaonengtech.ttwk.debug W/System.err: java.lang.IllegalArgumentException: Cannot bind argument at index 2 because the index is out of range. The statement has 1 parameters. 06-14 11:15:48.233 22355-22355/com.xiaonengtech.ttwk.debug W/System.err: at android.database.sqlite.SQLiteProgram.bind(SQLiteProgram.java:212) 06-14 11:15:48.233 22355-22355/com.xiaonengtech.ttwk.debug W/System.err: at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:166) 06-14 11:15:48.233 22355-22355/com.xiaonengtech.ttwk.debug W/System.err: at com.litesuits.orm.db.assit.SQLStatement.bind(SQLStatement.java:65) 06-14 11:15:48.233 22355-22355/com.xiaonengtech.ttwk.debug W/System.err: at com.litesuits.orm.db.assit.SQLStatement.execUpdateWithMapping(SQLStatement.java:211) 06-14 11:15:48.233 22355-22355/com.xiaonengtech.ttwk.debug W/System.err: at com.litesuits.orm.db.assit.SQLStatement.execUpdate(SQLStatement.java:200) 06-14 11:15:48.233 22355-22355/com.xiaonengtech.ttwk.debug W/System.err: at com.litesuits.orm.LiteOrm.update(LiteOrm.java:298) 06-14 11:15:48.233 22355-22355/com.xiaonengtech.ttwk.debug W/System.err: at com.xiaonengtech.ttwk.view.fragments.PublishVideoFragment.publishCallback(PublishVideoFragment.java:187) 06-14 11:15:48.233 22355-22355/com.xiaonengtech.ttwk.debug W/System.err: at com.xiaonengtech.ttwk.presenter.PublishVideoPresenterImpl$1.accept(PublishVideoPresenterImpl.java:103) 06-14 11:15:48.233 22355-22355/com.xiaonengtech.ttwk.debug W/System.err: at com.xiaonengtech.ttwk.presenter.PublishVideoPresenterImpl$1.accept(PublishVideoPresenterImpl.java:99) 06-14 11:15:48.233 22355-22355/com.xiaonengtech.ttwk.debug W/System.err: at io.reactivex.internal.subscribers.LambdaSubscriber.onNext(LambdaSubscriber.java:61) 06-14 11:15:48.233 22355-22355/com.xiaonengtech.ttwk.debug W/System.err: at io.reactivex.internal.operators.flowable.FlowableObserveOn$ObserveOnSubscriber.runAsync(FlowableObserveOn.java:400) 06-14 11:15:48.233 22355-22355/com.xiaonengtech.ttwk.debug W/System.err: at io.reactivex.internal.operators.flowable.FlowableObserveOn$BaseObserveOnSubscriber.run(FlowableObserveOn.java:176) 06-14 11:15:48.233 22355-22355/com.xiaonengtech.ttwk.debug W/System.err: at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:109) 06-14 11:15:48.233 22355-22355/com.xiaonengtech.ttwk.debug W/System.err: at android.os.Handler.handleCallback(Handler.java:815) 06-14 11:15:48.233 22355-22355/com.xiaonengtech.ttwk.debug W/System.err: at android.os.Handler.dispatchMessage(Handler.java:104) 06-14 11:15:48.233 22355-22355/com.xiaonengtech.ttwk.debug W/System.err: at android.os.Looper.loop(Looper.java:194) 06-14 11:15:48.233 22355-22355/com.xiaonengtech.ttwk.debug W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5556) 06-14 11:15:48.233 22355-22355/com.xiaonengtech.ttwk.debug W/System.err: at java.lang.reflect.Method.invoke(Native Method) 06-14 11:15:48.233 22355-22355/com.xiaonengtech.ttwk.debug W/System.err: at java.lang.reflect.Method.invoke(Method.java:372) 06-14 11:15:48.233 22355-22355/com.xiaonengtech.ttwk.debug W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:967) 06-14 11:15:48.233 22355-22355/com.xiaonengtech.ttwk.debug W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762) 06-14 11:15:48.238 22355-22355/com.xiaonengtech.ttwk.debug E/PRETTYLOGGER: ╔════════════════════════════════════════════════════════════════════════════════════════ 06-14 11:15:48.238 22355-22355/com.xiaonengtech.ttwk.debug E/PRETTYLOGGER: ║ Thread: main 06-14 11:15:48.238 22355-22355/com.xiaonengtech.ttwk.debug E/PRETTYLOGGER: ╟──────────────────────────────────────────────────────────────────────────────────────── 06-14 11:15:48.239 22355-22355/com.xiaonengtech.ttwk.debug E/PRETTYLOGGER: ║ PublishVideoPresenterImpl$1.accept (PublishVideoPresenterImpl.java:103) 06-14 11:15:48.239 22355-22355/com.xiaonengtech.ttwk.debug E/PRETTYLOGGER: ║ PublishVideoFragment.publishCallback (PublishVideoFragment.java:191) 06-14 11:15:48.239 22355-22355/com.xiaonengtech.ttwk.debug E/PRETTYLOGGER: ╟──────────────────────────────────────────────────────────────────────────────────────── 06-14 11:15:48.239 22355-22355/com.xiaonengtech.ttwk.debug E/PRETTYLOGGER: ║ update success is false 06-14 11:15:48.239 22355-22355/com.xiaonengtech.ttwk.debug E/PRETTYLOGGER: ╚════════════════════════════════════════════════════════════════════════════════════════

更新代码: String uuid = getArguments().getString("uuid");

ColumnsValue columnsValue = new ColumnsValue(new String[]{"is_publish"}, new Object[]{1}); int update = Stores.db.update( WhereBuilder.create(Video.class) .where("uuid", uuid) , columnsValue, ConflictAlgorithm.None); Logger.e("update success is " + String.valueOf(update != -1));

litangyu commented 7 years ago

原因主要是 WhereBuilder.where(String where,Object... whereArgs) 产生的错误 修改代码如下代码后,更新成功 WhereBuilder.create(Video.class) .where("uuid = ?", uuid)