Skip to content

Instantly share code, notes, and snippets.

@rolfbjarne
Created April 7, 2015 16:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rolfbjarne/cc147285de8e9734aec2 to your computer and use it in GitHub Desktop.
Save rolfbjarne/cc147285de8e9734aec2 to your computer and use it in GitHub Desktop.
//
// Copyright (c) 2009-2015 Krueger Systems, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
using System;
using System.Drawing;
using Foundation;
using UIKit;
using ObjCRuntime;
using System.Runtime.InteropServices;
namespace UnifiedSingleViewIphone1
{
public partial class UnifiedSingleViewIphone1ViewController : UIViewController
{
public enum Result
{
OK = 0,
Error = 1,
Internal = 2,
Perm = 3,
Abort = 4,
Busy = 5,
Locked = 6,
NoMem = 7,
ReadOnly = 8,
Interrupt = 9,
IOError = 10,
Corrupt = 11,
NotFound = 12,
Full = 13,
CannotOpen = 14,
LockErr = 15,
Empty = 16,
SchemaChngd = 17,
TooBig = 18,
Constraint = 19,
Mismatch = 20,
Misuse = 21,
NotImplementedLFS = 22,
AccessDenied = 23,
Format = 24,
Range = 25,
NonDBFile = 26,
Notice = 27,
Warning = 28,
Row = 100,
Done = 101
}
public delegate void ErrorLogCallback (IntPtr pArg, int iErrCode, string zMsg);
[DllImport("sqlite3", EntryPoint = "sqlite3_config", CallingConvention=CallingConvention.Cdecl)]
static extern Result ConfigOther (ConfigOption option, ErrorLogCallback callback, IntPtr pArg);
[DllImport("sqlite3", EntryPoint = "sqlite3_config", CallingConvention=CallingConvention.Cdecl)]
static extern Result ConfigArm64 (ConfigOption option, IntPtr p2, IntPtr p3, IntPtr p4, IntPtr p5, IntPtr p6, IntPtr p7, IntPtr p8, ErrorLogCallback callback, IntPtr pArg);
public static Result Config (ConfigOption option, ErrorLogCallback callback, IntPtr pArg)
{
if (IntPtr.Size == 8 && Runtime.Arch == Arch.DEVICE) {
return ConfigArm64 (option, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, callback, pArg);
} else {
return ConfigOther (option, callback, pArg);
}
}
[DllImport("sqlite3", EntryPoint = "sqlite3_log", CallingConvention=CallingConvention.Cdecl)]
static extern void LogOther (int iErroCode, string zFormat, string zMsg);
[DllImport("sqlite3", EntryPoint = "sqlite3_log", CallingConvention=CallingConvention.Cdecl)]
static extern void LogArm64 (int iErroCode, string zFormat, IntPtr p3, IntPtr p4, IntPtr p5, IntPtr p6, IntPtr p7, IntPtr p8, string zMsg);
public static void Log (int iErrorCode, string zFormat, string zMsg)
{
if (IntPtr.Size == 8 && Runtime.Arch == Arch.DEVICE) {
LogArm64 (iErrorCode, zFormat, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, zMsg);
} else {
LogOther (iErrorCode, zFormat, zMsg);
}
}
[MonoPInvokeCallback (typeof (ErrorLogCallback))]
public static void SQLite3ErrorCallback (IntPtr pArg, int iErrCode, string zMsg)
{
Console.WriteLine ("Called the callback! {0} {1} {2}", pArg, iErrCode, zMsg);
}
public enum ConfigOption {
Log = 16
}
public UnifiedSingleViewIphone1ViewController(IntPtr handle) : base(handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
Config(ConfigOption.Log, SQLite3ErrorCallback, new IntPtr (12345678));
Log(987654321, "%s", "Hello world.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment