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, add the SQLite-WinRT NuGet package to your project.

*NEW FEATURES – October 2014* – Support for Windows Phone 8.1 added (Silverlight and WinRT). Component now published as the SQLite-WinRT NuGet package.

*NEW FEATURES – October 2013* – Component for Windows 8.1 added. Namespace on all platforms is now standardised as SQLWinRT to ease code sharing. BLOB column support added to allow storage of byte arrays or images. Updated SQLite references to version 3.8.0.2.

To use the Component

Install the SQLite-WinRT NuGet package into your project.

Alternatively, you can download the source code and add the project for Windows 8, Windows 8.1,Windows Phone 8, Windows Phone 8.1 (Silverlight) or Windows Phone 8.1 (WinRT) as appropriate to your solution to begin accessing SQLite databases in your Windows apps.

Important: You must also install the SQLite for Windows, SQLite for Windows (8.1) and/or SQLite for Windows Phone Extension SDK from the Visual Studio Extensions and Updates option on the Tools menu.

Important if you are using the source code download: Periodically, you will be prompted to install updates to any of the SQLite extension SDKs that you install. After you install an update, the SQLite version number will change and as a result, the SQLWinRT project that you download from this codeplex project will not open anymore in Visual Studio because the referenced folder path for sqlite3.h will have changed. To rectify this, locate the Update_Project_SQLite_SDK_References.ps1 powershell script in the project folder, right-click and then click Run with Powershell. This updates the project file to the correct path to the SQLite extension SDK.

Supported functionality

The WinRT API gives you a familiar programming model for implementing the following basic operations:

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#): 

async void AddToItemsCollection()
{  
  // Get the file from the install location  
  var file = await Package.Current.InstalledLocation.GetFileAsync("cities.db");  

  // Create a new SQLite instance for the file 
  var db = new Database(file);  

  // Open the database asynchronously
  await db.OpenAsync(SqliteOpenMode.OpenRead);
 
  // Prepare a SQL statement to be executed
  var statement = awaitdb.PrepareStatementAsync(
    "SELECT rowid, CityName FROM Cities;"); 

  // Loop through all the results and add to the collection
  while (awaitstatement.StepAsync())
     items.Add(statement.GetIntAt(0) + ": "+ statement.GetTextAt(1));
}

 

 

Last edited Nov 3 at 12:30 PM by andywigley, version 15