×
Namespaces

Variants
Actions
(Difference between revisions)

Compiling and using SQLite with Windows Phone 8

From Nokia Developer Wiki
Jump to: navigation, search
vinayppatil (Talk | contribs)
m (Vinayppatil -)
hamishwillee (Talk | contribs)
m (Hamishwillee -)
Line 151: Line 151:
 
*Once this is done, you can use the database as you wish.
 
*Once this is done, you can use the database as you wish.
  
{{SeeAlso|http://developer.nokia.com/community/wiki/Compiling_and_using_SQLite_Encryption_Extension_(SEE)_with_Windows_Phone_8}}
+
{{SeeAlso|[[Compiling and using SQLite Encryption Extension (SEE) with Windows Phone 8]]}}

Revision as of 00:28, 31 January 2014

This article explains how to compile and use public SQLite with Windows Phone 8.

WP Metro Icon File.png
WP Metro Icon Tools.png
WP Metro Icon WP8.png
Article Metadata
Tested with
SDK: Windows Phone 8.0 SDK
Compatibility
Platform(s):
Windows Phone 8
Article
Created: vinayppatil (17 Jan 2014)
Last edited: hamishwillee (31 Jan 2014)

Contents

Introduction

This wiki explains how to use SQLite in Windows Phone 8 applications. It explains how to modify the open source SQLite source code and compile it for use in your Windows Phone 8 applications.

This wiki takes you through the following steps:

  1. Compiling the SQLite source code for ARM and x86 targets
  2. Creating an Extension SDK targeted to Windows Phone 8
  3. Using SQLite with your Windows Phone 8 applications

Pre-requisites

Before you begin, you will need:

Compiling SQLite

Following the instructions in the sections below compile SQLite for ARM and x86 architectures.

Building binaries for an ARM target

  1. Open Visual Studio 2012 ARM Phone Tools Command Prompt in administrator mode.
  2. Navigate to where you want to put the source or create a directory:
    mkdir c:\sqlite-arm
    cd c:\sqlite-arm
  3. Get the latest SQLite source code:
    fossil clone http://www.sqlite.org/cgi/src sqlite3.fossil
  4. Open the repository you just created:
    fossil open sqlite3.fossil
  5. Type in the commands below in order:
    SET NCRTLIBPATH=%ProgramFiles(x86)%\Microsoft Visual Studio 11.0\VC\WPSDK\WP80\lib
     
    SET NSDKLIBPATH=%ProgramFiles(x86)%\Windows Phone Kits\8.0\lib\x86
     
    SET USE_RC=0
     
    SET OPTS=-DWINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_WIN32_FILEMAPPING_API=1 -DSQLITE_HAS_CODEC=1
     
    nmake /F Makefile.msc sqlite3.c XCOMPILE=1 USE_NATIVE_LIBPATHS=1 FOR_WINRT=1 NO_TCL=1
     
    nmake -f Makefile.msc sqlite3.dll /I XCOMPILE=1 USE_NATIVE_LIBPATHS=1 FOR_WINRT=1 NO_TCL=1
Final binaries

When you're done, the c:\sqlite-arm source directory should contain sqlite3.dll, sqlite3.h, sqlite3.lib and sqlite3.pdb along with a lot of other generated files.

Building binaries for a x86 target

  1. Open the Visual Studio 2012 x86 Phone Tools Command Prompt in administrator mode.
  2. Create a source directory and navigate to it.
    mkdir c:\sqlite-x86
    cd c:\sqlite-x86
  3. Follow steps 3, 4 and 5 building binaries for ARM target.

Final binaries


When you're done, the c:\sqlite-x86 source directory should contain sqlite3.dll, sqlite3.h, sqlite3.lib and sqlite3.pdb along with a lot of other generated files.

Building the Extension SDK

Now that we have all the required binaries, we will create an Extension SDK targeted to Windows Phone 8.

  • Create a new project by selecting File -> New -> Project -> Visual C# -> Extensibility -> VSIX project
  • Create a new file your_proj_name.props and copy the source code below into it. (Make sure to replace your_proj_name and version accordingly.)
    <?xml version="1.0" encoding="utf-8"?>
    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
    <PackageConfiguration Condition="'$(Configuration)' == ''">Debug</PackageConfiguration>
    <PackageConfiguration Condition="'$(Configuration)' == 'Debug'">Debug</PackageConfiguration>
    <PackageConfiguration Condition="'$(Configuration)' == 'Release'">Retail</PackageConfiguration>
    </PropertyGroup>
    <PropertyGroup>
    <IncludePath>$(FrameworkSDKRoot)\..\..\Windows Phone\v8.0\ExtensionSDKs\your_proj_name\version\DesignTime\CommonConfiguration\Neutral;$(IncludePath)</IncludePath>
    <LibraryPath>$(FrameworkSDKRoot)\..\..\Windows Phone\v8.0\ExtensionSDKs\your_proj_name\version\DesignTime\$(PackageConfiguration)\$(PlatformTarget);$(LibraryPath)</LibraryPath>
    <PropertySheetDisplayName> your_proj_name, version</PropertySheetDisplayName>
    </PropertyGroup>
    <ItemDefinitionGroup>
    <Link>
    <AdditionalDependencies>sqlite3.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
    </ItemDefinitionGroup>
    </Project>
  • Create a new file called SDKManifest.xml in the project root, and copy the XML below into it. (Make sure to replace your_proj_name accordingly.)
    <?xml version="1.0" encoding="utf-8" ?>
    <FileList
    DisplayName="MySQLite for Windows Phone"
    ProductFamilyName="your_proj_name"
    MoreInfo="http://www.sqlite.org/"
    MinVSVersion="11.0"
    SupportsMultipleVersions="Error"
    SupportedArchitectures="x86;ARM">
    </FileList>
  • Create the hierarchy below in the application source, and add the files that were generated during build process to the project. Files from sqlite-x86 go into x86 folders. Files from sqlite-arm go into ARM folders.
    Extension SDK hierarchy
  • Right click on file, click on Properties and change Build Action to Content, Copy to output directory to Copy always and Include in VSIX to True. Repeat this for all the added files.
  • Double click on source.extension.vsixmanifest.
  • Input the options below on the install targets tab.
    install targets tab options
  • Input the options below in the asset tab.
    assets tab options
  • Now build the project. A .VSIX file should be generated in the bin/{config} folder.

SQLite Usage

  • Install the MySQLite Extension SDK you just created on your computer and restart Visual Studio.
  • Create a new Windows phone application.
  • Download sqlite-net-wp8 and add the Sqlite.vcxproj project to your solution by selecting File -> Add -> Existing Project.
  • Add the required compilation symbols as follows:
    Right click on Windows Phone Project -> Properties
    Click on the Build tab.
    In the Configuration dropdown, select All configurations.
    In the Platform dropdown, select All platforms.
    Add USE_WP8_NATIVE_SQLITE;WINDOWS_PHONE;SILVERLIGHT to the Conditional compilation symbols textbox.
  • Add a reference to the SQLite extension to the sqlite project as follows:
    Right click on SQLite Project -> Properties.
    Click on the Common properties tab.
    Remove SQLite.WP80 from the references.
    Click on Add new reference
    Select Windows Phone -> Extensions -> SQLite extension
  • Add the sqlite-net nuget package to the Windows Phone project.
  • Once this is done, you can use the database as you wish.
312 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×