Example Code

Jun 9, 2014 at 1:35 AM
Don't you have any example code in the docs showing syntax use of your library?
Developer
Sep 5, 2014 at 6:30 PM
Edited Sep 5, 2014 at 6:31 PM
Hi @IEatCoffeeGrinds,

The API provided with this package mimics the C/C++ interface from sqlite.org , you can always check the mentioned website for reference. Our documentation section is currently focused on installation, but I believe we could add some usage reference and examples.

In the meantime, in order to execute a statement, you first create a new SQLiteConnection instance, passing the db file path. Then, you can prepare an ISQLiteStatement by calling Prepare on the ISQLiteConnection instance, passing a string containing the SQL statement. Once prepared, you would call Step() on it. If its a non-query statement, and everything is fine, it should return SQLiteResult.DONE status; if it's a query statement, you should get a SQLiteResult.ROW status, and be able to read the results from the statement ([] operator), then you can keep calling step to read the following rows, until you no longer get SQLiteResult.ROW status.

When you create a new SQLiteConnection, if the db file doesn't exist, it creates it. If it's a relative path (just the filename), it picks an appropriate directory depending on the platform (CurrentDirectory in Net45, ApplicationData.Current.LocalFolder.Path in Universal apps).

If you download the source code for this package, you'll find plenty examples of use in the test projects.
using (var connection = new SQLiteConnection("sample.db"))
{
    using (var statement = connection.Prepare("SELECT id, description FROM table;"))
    {
        while (statement.Step() == SQLiteResult.ROW)
        {
            var id = (long)statement["id"];
            var description = (string)statement["description"];

            // DO SOME STUFF
        }
    }
}
Regards,
Marked as answer by leotilli on 9/5/2014 at 11:31 AM