sqlite 语法错误

前端之家收集整理的这篇文章主要介绍了sqlite 语法错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

做android应用,写ContentProvider提供sqliteDatabase操作时,调试过程中出现以下错误

02-07 16:37:41.825: W/System.err(12044): android.database.sqlite.sqliteException: near ".905": Syntax error:,while compiling: SELECT start_time,run_mode,duration_time,_id,reservation_locator FROM reservation_table WHERE (reservation_locator=0.1.905) ORDER BY _id ASC

错误提示为语法错误

仔细检查,是where;子句有错误

代码builer.appendWhere(ReservationMetadata.ReservationTable.LOCATOR + "=" + uri.getPathSegments().get(1));
本来,我的意图是要查询字符串reservation_locator等于“0.1.905”,但是查资料了才发现sqlite中text的比较不能用“=”,而需要用诸如Like/In /Between等关键字。

因此,改为builer.appendWhere(ReservationMetadata.ReservationTable.LOCATOR + " LIKE " + uri.getPathSegments().get(1));

继续调试,仍出错:

02-07 16:46:45.465: W/System.err(12294): android.database.sqlite.sqliteException: near ".905": Syntax error:,reservation_locator FROM reservation_table WHERE (reservation_locator LIKE 0.1.905) ORDER BY _id ASC

意味着,like子句的写法有问题,继续查资料,原来如此:

SELECT * FROM Cars WHERE Name Like 'en'

也即,Like后面的字符串需要用单引号括起来,Ok,继续更正:

builer.appendWhere(ReservationMetadata.ReservationTable.LOCATOR + " LIKE '" + uri.getPathSegments().get(1) + "'");

搞定,得到期望的结果。

以上,作为数据库操作调试的日志。

原文链接:https://www.f2er.com/sqlite/202252.html

猜你在找的Sqlite相关文章