如何在android中使用rawQuery()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1617280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 03:20:59  来源:igfitidea点击:

How to use rawQuery() in android

sqlandroid

提问by Dennie

I have a sql query like this

我有一个像这样的 sql 查询

String loadFav = "SELECT _id, title, name, favorite FROM table1 where favorite= 1 " 
                     + "UNION ALL" 
                     + "SELECT _id, title, name, favorite FROM table2 where favorite= 1"
                     ;

    Cursor mCursor = mSQLiteDatabase.rawQuery(loadFav, null);

I got an error when run this query. Is it right structure? Can someone help me?

运行此查询时出现错误。是正确的结构吗?有人能帮我吗?

回答by Bill Karwin

Always troubleshoot by looking at the SQL string -- not the code that builds the SQL string!

总是通过查看 SQL 字符串来排除故障——而不是构建 SQL 字符串的代码!

SELECT _id, title, name, favorite FROM table1 where favorite= 1 UNION ALLSELECT _id, title, name, favorite FROM table2 where favorite= 1

You need a space between ALLand the second SELECT.

您需要在ALL和 第二个之间留一个空格SELECT