Monday, August 26, 2013

Testing sql queries

I was working on an Android application, and one of my queries wasn't returning what I expected it to.  

To test my query, I decided to just run sqlite on my computer, which is pretty simple.  Here are the steps:
  1. Download sqlite from http://www.sqlite.org/ .
  2. Unzip the file into some folder and then you can start a database called test1 with a command like this:
    ~/bin/sqlite3 test1.db
  3. Create a table and insert some data.
    create table phrase_table (words char(50));
    insert into phrase_table (words) values ('hello');
  4. Run queries like:
    select * from phrase_table;

While that was pretty simple, another tool to quickly test queries is http://sqlfiddle.com/ .  This is a web tool where you can set up a database table and then test queries.  For simple cases where you'd like to share your queries, this is a fantastic tool.

No comments:

Post a Comment