internal collation_hook_info(delegate_collation func, object v) { _func = func; _user_data = v; _h = GCHandle.Alloc(this); }
/// <summary>Create custom collation.</summary> /// <typeparam name="T">The type of the state object.</typeparam> /// <param name="name">Name of the collation.</param> /// <param name="state">State object passed to each invocation of the collation.</param> /// <param name="comparison">Method that compares two strings, using additional state.</param> public virtual void CreateCollation<T>(string name, T state, Func<T, string, string, int> comparison) { if (string.IsNullOrEmpty(name)) throw new ArgumentNullException(nameof(name)); if (this.State != ConnectionState.Open) throw new InvalidOperationException("RequiresOpenConnection"+((object)nameof(CreateCollation))); delegate_collation f = comparison != null ? (delegate_collation)((v, s1, s2) => comparison((T)v, s1, s2)) : (delegate_collation)null; SqliteException.ThrowExceptionForRC(raw.sqlite3_create_collation(this._db, name, (object)state, f), this._db); }
internal void free() { _func = null; _user_data = null; _h.Free(); }
int ISQLite3Provider.sqlite3_create_collation(IntPtr db, string name, object v, delegate_collation func) { throw new Exception(GRIPE); }
public collation_hook_info(delegate_collation func, object v) { _func = func; _user_data = v; }
static public int sqlite3_create_collation(sqlite3 db, string name, object v, delegate_collation f) { return(_imp.sqlite3_create_collation(db.ptr, name, v, f)); }
int ISQLite3Provider.sqlite3_create_collation (IntPtr db, string name, object v, delegate_collation func) { var info = hooks.getOrCreateFor (db); if (info.collation.ContainsKey (name)) { collation_hook_info hi = info.collation [name]; // TODO maybe turn off the hook here, for now hi.free (); info.collation.Remove (name); } // 1 is SQLITE_UTF8 if (func != null) { collation_hook_info hi = new collation_hook_info (func, v); int rc = NativeMethods.sqlite3_create_collation (db, util.to_utf8 (name), 1, hi.ptr, collation_hook_bridge); if (rc == 0) { info.collation [name] = hi; } return rc; } else { return NativeMethods.sqlite3_create_collation (db, util.to_utf8 (name), 1, IntPtr.Zero, null); } }
static public int sqlite3_create_collation(sqlite3 db, string name, object v, delegate_collation f) { return _imp.sqlite3_create_collation(db.ptr, name, v, f); }
public static void create_collation(this sqlite3 db, string name, object v, delegate_collation f) { int rc = raw.sqlite3_create_collation(db, name, v, f); check_ok(rc); }
public int sqlite3_create_collation(IntPtr db, string name, object v, delegate_collation func) => throw new NotImplementedException();
int ISQLite3Provider.sqlite3_create_collation(IntPtr db, string name, object v, delegate_collation func) { if (_collation_hooks.ContainsKey(name)) { collation_hook_info hi = _collation_hooks[name]; // TODO maybe turn off the hook here, for now hi.free(); _collation_hooks.Remove(name); } GCHandle pinned = GCHandle.Alloc(util.to_utf8(name), GCHandleType.Pinned); IntPtr ptr = pinned.AddrOfPinnedObject(); int rc; // 1 is SQLITE_UTF8 if (func != null) { collation_hook_info hi = new collation_hook_info(func, v); rc = SQLite3RuntimeProvider.sqlite3_create_collation(db.ToInt64(), ptr.ToInt64(), 1, hi.ptr.ToInt64(), Marshal.GetFunctionPointerForDelegate(new callback_collation(collation_hook_bridge)).ToInt64()); if (rc == 0) { _collation_hooks[name] = hi; } } else { rc = SQLite3RuntimeProvider.sqlite3_create_collation(db.ToInt64(), ptr.ToInt64(), 1, IntPtr.Zero.ToInt64(), IntPtr.Zero.ToInt64()); } pinned.Free(); return(rc); }
int ISQLite3Provider.sqlite3_create_collation(IntPtr db, string name, object v, delegate_collation func) { var info = hooks.getOrCreateFor(db); if (info.collation.ContainsKey(name)) { collation_hook_info hi = info.collation[name]; // TODO maybe turn off the hook here, for now hi.free(); info.collation.Remove(name); } GCHandle pinned = GCHandle.Alloc(util.to_utf8(name), GCHandleType.Pinned); IntPtr ptr = pinned.AddrOfPinnedObject(); int rc; // 1 is SQLITE_UTF8 if (func != null) { collation_hook_info hi = new collation_hook_info(func, v); rc = SQLite3RuntimeProvider.sqlite3_create_collation(db.ToInt64(), ptr.ToInt64(), 1, hi.ptr.ToInt64(), Marshal.GetFunctionPointerForDelegate(collation_hook_bridge).ToInt64()); if (rc == 0) { info.collation[name] = hi; } } else { rc = SQLite3RuntimeProvider.sqlite3_create_collation(db.ToInt64(), ptr.ToInt64(), 1, IntPtr.Zero.ToInt64(), IntPtr.Zero.ToInt64()); } pinned.Free(); return rc; }