Project Description
SQLite wrapper for WinRT
The SQLite WinRT wrapper offers lightweight Windows Runtime (WinRT) APIs you can use to access the most common SQLite database functionality. The latest update of the library supports Windows Phone 8 development in addition to Windows 8 development.
This project does not have a binary download; to use the component, download the source code and add the WinRT component project to your solution.
To use the Component
Download the source code and add the project for Windows 8 or Windows Phone 8 as appropriate to your solution to begin accessing SQLite databases in your Windows Phone 8 apps.
Important: You must also install the SQLite for Windowsand/or SQLite for Windows Phone Extension SDK from the Visual Studio Extensions and Updates option on the Tools menu.
Supported functionality
The WinRT API gives you a familiar programming model for implementing the following basic operations:
- Opening a database (wraps the sqlite3_open_v2 function)
- Executing a single SQL statement (wraps the sqlite3_exec function)
- Creating a complex SQL statement (wraps the sqlite3_prepare16_v2 function)
- Binding parameters to a statement (wraps the sqlite3_bind_xyz functions)
- Iterating over statement results (wraps the sqlite3_step and sqlite3_column_xyz functions)
All operations follow the async pattern– they perform operations on a worker thread, which helps make your database apps fast and fluid. The wrapper also supports exception-based programming, so you don’t need to check the return value from every method call. Note that the API doesn’t support all of the advanced features of SQLite, nor does it attempt to hide the underlying SQL statements, untyped result sets, and so on. It’s designed to provide a very thin wrapper over the SQLite functionality that many people already know and love, rather than to provide an equivalent programming model to LINQ-to-SQL or ADO.NET.
For more information, see the following blog post: SQLite WinRT wrapper for Windows Phone
Example (C#):
asyncvoid AddToItemsCollection()
{
// Get the file from the install locationvar file = awaitPackage.Current.InstalledLocation.GetFileAsync("cities.db");
// Create a new SQLite instance for the filevar db = newDatabase(file);
// Open the database asynchronouslyawait db.OpenAsync(SqliteOpenMode.OpenRead);
// Prepare a SQL statement to be executedvar statement = await db.PrepareStatementAsync(
"SELECT rowid, CityName FROM Cities;");
// Loop through all the results and add to the collectionwhile (await statement.StepAsync())
items.Add(statement.GetIntAt(0) + ": "+ statement.GetTextAt(1));
}