32369

Android SQlite query problem

Question:

As the title says I am having a little trouble with a query on an sqlite database.Basically, what I am trying to do is retrieve a bunch of quotes from the database, depending on the author chosen from user in a list.

But there is a problem with my SELECT statement(it seems..), and I can't seem to spot it, so if any of you good folk could lend a pair of eyes I would really appreciate it.

My query:

public Cursor getQuotes(int position){ String who = authorName[position]; return qmDB.query(QUOTES_TABLE, new String[]{ KEY_QUOTE }, KEY_AUTHNAME + "=" + who, null, null, null, null); }

Error:

04-28 20:05:10.685: ERROR/AndroidRuntime(25017): Caused by: android.database.sqlite.SQLiteException: near "Anton": syntax error: , while compiling: SELECT quote FROM Quotes WHERE auth_name=Robert Anton Wilson

Answer1:

You need single quotes around your "who" string.

Recommend

  • how to zoom in the image inside a scrollable panel in vb
  • Bash Prompt Wrapping Issue
  • Default isolation level in Microsoft SQL Server 2005
  • Android Application first run
  • Android - Determine sound levels around phone
  • iOS: Uniquely identify ViewControllers from Storyboard
  • Bootstrap fixed navigation jumps when scrolling
  • How to create a Unix-domain socket with specific access permissions
  • Pre-populated SQLite Database not reading properly in Android Studio
  • Converting query results into DataFrame in python
  • Getting the scrolling offset when storing coordinates
  • How to 'create temp table as select' in Slick?
  • Possible to get mouse events fired when cursor is outside page?
  • MySQL Order by column = x, column asc?
  • xtable package: Skipping some rows in the output
  • GridView breaks while scrolling
  • copying resource to sdcard gives a damaged file in android
  • Database structure design with variable amounts of fields
  • how to adjust image in a panel in Java swing?
  • Java Scanner input dilemma. Automatically inputs without allowing user to type
  • Different response to non-authenticated users and AJAX calls
  • C# - Serializing and deserializing static member
  • Problems to linebreak with an int in JLabel
  • How reduce the height of an mschart by breaking up the y-axis
  • output of program is not same as passed argument
  • Incrementing object id automatically JS constructor (static method and variable)
  • MySQL WHERE-condition in procedure ignored
  • How to model a transition system with SPIN
  • Weird JavaScript statement, what does it mean?
  • ORA-29908: missing primary invocation for ancillary operator
  • Do create extension work in single-user mode in postgres?
  • How to get next/previous record number?
  • Rearranging Cells in UITableView Bug & Saving Changes
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • How do you join a server to an Active Directory (domain)?
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • How does Linux kernel interrupt the application?
  • Sorting a 2D array using the second column C++
  • Converting MP3 duration time
  • java string with new operator and a literal