Skip to content

Instantly share code, notes, and snippets.

@nkundu
Created December 5, 2015 01:37
Show Gist options
  • Save nkundu/d33bda6add205290e28d to your computer and use it in GitHub Desktop.
Save nkundu/d33bda6add205290e28d to your computer and use it in GitHub Desktop.
Sample for using Sqlite3 on Raspbian with Mono
// apt-get install scite mono-complete sqlite3
// mcs program.cs -r:System.Data -r:Mono.Data.Sqlite
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Mono.Data.Sqlite;
namespace Example
{
class Program
{
const string connStr = "Data Source=SqliteTest.db";
static SqliteConnection conn;
static void Main(string[] args)
{
conn = new SqliteConnection(connStr);
conn.Open();
conn.Close();
}
static void Example(List<int> a)
{
using(var tr = conn.BeginTransaction())
{
foreach (var x in a)
{
foreach (var y in a)
{
using (var cmd = conn.CreateCommand())
{
cmd.Transaction = tr;
cmd.CommandText = "insert into Rf values (@x, @y, @x+@y), (@x, @y, @x*@y)";
cmd.Parameters.AddWithValue("@x", x);
cmd.Parameters.AddWithValue("@y", y);
cmd.ExecuteNonQuery();
}
}
}
tr.Commit();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment