Sqlite Database Query returns null

I have a database and a mthod to get all values from every table.

However, I want to only get the table rows where route = 5 (for example)

This is my query:

  Cursor cursor = db.query(TABLE_NAME_ROUTES, new String[] {"id","route","busstop","longitude","latitude"}, "route" + "=" + busroute , null, null, null, null); 

I've tried tons of different versions of this WHERE clause, however none seem to work, as the list returned is size 0, when it should be about size 20.

EDIT:

Changed the line to:

 Cursor cursor = db.query(TABLE_NAME_ROUTES, new String[] {"id","route","busstop","longitude","latitude"}, "route" + "=`"+ busroute+"`" , null, null, null, null);

Log from Logcat

05-02 18:14:23.396: E/SQLiteLog(15408): (1) no such column: 5

05-02 18:14:23.396: D/AndroidRuntime(15408): Shutting down VM
05-02 18:14:23.396: W/dalvikvm(15408): threadid=1: thread exiting with uncaught exception (group=0x40cee300)
05-02 18:14:23.400: E/AndroidRuntime(15408): FATAL EXCEPTION: main
05-02 18:14:23.400: E/AndroidRuntime(15408): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mso.master/com.mso.master.MainActivity}: android.database.sqlite.SQLiteException: no such column: 5 (code 1): , while compiling: SELECT id, route, busstop, longitude, latitude FROM routes WHERE route=`5`
05-02 18:14:23.400: E/AndroidRuntime(15408):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2185)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at android.app.ActivityThread.access$600(ActivityThread.java:142)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at android.os.Looper.loop(Looper.java:137)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at android.app.ActivityThread.main(ActivityThread.java:4931)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at java.lang.reflect.Method.invokeNative(Native Method)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at java.lang.reflect.Method.invoke(Method.java:511)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at dalvik.system.NativeStart.main(Native Method)
05-02 18:14:23.400: E/AndroidRuntime(15408): Caused by: android.database.sqlite.SQLiteException: no such column: 5 (code 1): , while compiling: SELECT id, route, busstop, longitude, latitude FROM routes WHERE route=`5`
05-02 18:14:23.400: E/AndroidRuntime(15408):    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1200)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at com.mso.master.DataManipulator.selectRoute(DataManipulator.java:167)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at com.mso.master.DBaccess.getBusRoute(DBaccess.java:43)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at com.mso.master.MainActivity.onCreate(MainActivity.java:130)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at android.app.Activity.performCreate(Activity.java:5008)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
05-02 18:14:23.400: E/AndroidRuntime(15408):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139)
05-02 18:14:23.400: E/AndroidRuntime(15408):    ... 11 more

Answers


route type is text, so it should be there in single quotes, try this

Cursor cursor = db.query(TABLE_NAME_ROUTES, new String[] {"id","route","busstop","longitude","latitude"}, "route" + "='"+ busroute+"'" , null, null, null, null);

Need Your Help

Underscore.js templates in backbone.js adding a div around a tr

backbone.js underscore.js

I am using underscore.js's templating capabilities from backbone.js, I have the following template that I define in my page like this:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.