Getting SQLite to work in a Tizen App built using .net

Does anyone know of a good tut or source for using SQLite in tizen .net. Whenever I try I get segmentation errors, I tried using Xamarin examples but they don’t work, even the Github examples seem to not work.
Cheers

This is how I use it, I can’t guarantee it will fix your segmentation errors though. I used to get those when I was building for the wrong tizen version, using privileges or features that were not supported and stuff like that.

  1. Create a Visual C# project for Tizen 4.0 [Tizen Wearable Xaml App]

  2. Install these NuGet packages
    sqlite-net-base (Frank A. Krueger) v1.6.292
    SQLitePCLRaw.provider.sqlite3.netstandard11 (Eric Sink, et al) v1.1.14

  3. In App.xaml.cs file (above namespace)

using SQLitePCL;
using SQLite;
using System.IO;

And then inside the class

public SQLiteConnection dbConnection;
public void InitiateSQLite()
{
string databaseFileName = “YourDatabaseName.db3”;
string dataPath = global::Tizen.Applications.Application.Current.DirectoryInfo.Data;
string databasePath = Path.Combine(dataPath, databaseFileName);

// Need to initialize SQLite
raw.SetProvider(new SQLite3Provider_sqlite3());
raw.FreezeProvider(true);

bool needCreateTable = false;
// Check the database file to decide table creation.
if (!File.Exists(databasePath))
{
needCreateTable = true;
}

dbConnection = new SQLiteConnection(databasePath);
if (needCreateTable)
{
dbConnection.CreateTable();
}
}

You need to call InitiateSQLite(); , possibly from within public App() {}, perhaps under MainPage = new MainPage();

  1. In a file called “YourDatabaseItem.cs”

public class YourDatabaseItem
{
[SQLite.PrimaryKey]
public string yourDatabaseItemPrimaryKey { get; set; }

public double someDataAsDouble { get; set; }
public string someDataAsString { get; set; }
}

  1. Now you should be able to insert data into SQLite:

//from within App.xaml.cs:

YourDatabaseItem dbItem = new YourDatabaseItem();
dbItem.yourDatabaseItemPrimaryKey = “some_id_123”;
dbItem.someDataAsDouble = 1.23;
dbItem.someDataAsString = “123”;

dbConnection.Insert(dbItem);

//from outside App.xaml.cs:

YourDatabaseItem dbItem = new YourDatabaseItem();
dbItem.yourDatabaseItemPrimaryKey = “some_id_123”;
dbItem.someDataAsDouble = 1.23;
dbItem.someDataAsString = “123”;

(Application.Current as App).dbConnection.Insert(dbItem);

Some useful stuff…
Query for items:

List itemList = dbConnection.Query(“SELECT * FROM YourDatabaseItem ORDER BY someDataAsDouble ASC”);

//Find item:

YourDatabaseItem myItem = dbConnection.Find(“some_id_123”);

//Delete all items:

dbConnection.Query(“DELETE FROM YourDatabaseItem”);

//Insert or replace item

YourDatabaseItem dbItem = new YourDatabaseItem();
[…]
dbConnection.InsertOrReplace(dbItem);