/// <summary> /// Call to the unmanaged sqlite3_exec SQLite library function. /// </summary> /// <param name="db">An open database</param> /// <param name="sql">SQL to be evaluated</param> /// <param name="errmsg">Error msg written here (may be null)</param> /// <param name="callback">The method which gets called with the result /// set.</param> /// <returns>SQLITE_OK on sucess.</returns> public static int sqlite3_exec(IntPtr db, string sql, ref IntPtr errmsg, SQLiteCallback callback) { byte[] utf8SQL = System.Text.Encoding.UTF8.GetBytes(sql + "\0"); IntPtr funcPtr = Marshal.GetFunctionPointerForDelegate(callback); return(IntPtr.Size == 8 /* 64bit */ ? sqlite3_execx64(db, utf8SQL, funcPtr, IntPtr.Zero, ref errmsg) : sqlite3_execx64(db, utf8SQL, funcPtr, IntPtr.Zero, ref errmsg)); }
/// <summary> /// Disposes of any active contextData variables that were not automatically cleaned up. Sometimes this can happen if /// someone closes the connection while a DataReader is open. /// </summary> public void Dispose() { Dispose(true); IDisposable disp; foreach (KeyValuePair <long, object> kv in _contextDataList) { disp = kv.Value as IDisposable; if (disp != null) { disp.Dispose(); } } _contextDataList.Clear(); _InvokeFunc = null; _StepFunc = null; _FinalFunc = null; _CompareFunc = null; _base = null; _contextDataList = null; GC.SuppressFinalize(this); }
protected virtual void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { foreach (KeyValuePair <IntPtr, SQLiteFunction.AggregateData> keyValuePair in this._contextDataList) { IDisposable value = keyValuePair.Value._data as IDisposable; if (value == null) { continue; } value.Dispose(); } this._contextDataList.Clear(); this._contextDataList = null; this._flags = SQLiteConnectionFlags.None; this._InvokeFunc = null; this._StepFunc = null; this._FinalFunc = null; this._CompareFunc = null; this._base = null; } this.disposed = true; } }
internal override IntPtr CreateFunction(string strFunction, int nArgs, SQLiteCallback func, SQLiteCallback funcstep, SQLiteCallback funcfinal) { IntPtr nCookie; int n = UnsafeNativeMethods.sqlite3_create_function16_interop(_sql, strFunction, nArgs, 4, func, funcstep, funcfinal, out nCookie); if (n > 0) { throw new SQLiteException(n, SQLiteLastError()); } return(nCookie); }
internal override void CreateFunction(string strFunction, int nArgs, bool needCollSeq, SQLiteCallback func, SQLiteCallback funcstep, SQLiteFinalCallback funcfinal) { //int n = UnsafeNativeMethods.sqlite3_create_function(_sql, ToUTF8(strFunction), nArgs, 4, IntPtr.Zero, func, // funcstep, funcfinal); //if (n == 0) //{ // n = UnsafeNativeMethods.sqlite3_create_function(_sql, ToUTF8(strFunction), nArgs, 1, IntPtr.Zero, func, // funcstep, funcfinal); //} //if (n > 0) //{ // throw new SqliteException(n, SQLiteLastError()); //} throw new NotImplementedException(); }
internal override void CreateFunction(string strFunction, int nArgs, bool needCollSeq, SQLiteCallback func, SQLiteCallback funcstep, SQLiteFinalCallback funcfinal) { int n; #if MONOTOUCH var data = new FunctionData(); data.Func = func; data.FuncStep = funcstep; data.FuncFinal = funcfinal; SQLiteCallback func_callback = func == null ? null : new SQLiteCallback(scalar_callback); SQLiteCallback funcstep_callback = funcstep == null ? null : new SQLiteCallback(step_callback); SQLiteFinalCallback funcfinal_callback = funcfinal == null ? null : new SQLiteFinalCallback(final_callback); IntPtr user_data; user_data = GCHandle.ToIntPtr(GCHandle.Alloc(data)); n = UnsafeNativeMethods.sqlite3_create_function_v2(_sql, ToUTF8(strFunction), nArgs, 4, user_data, func_callback, funcstep_callback, funcfinal_callback, destroy_callback); if (n == 0) { // sqlite3_create_function_v2 will call 'destroy_callback' if it fails, so we need to recreate the gchandle here. user_data = GCHandle.ToIntPtr(GCHandle.Alloc(data)); n = UnsafeNativeMethods.sqlite3_create_function_v2(_sql, ToUTF8(strFunction), nArgs, 1, user_data, func_callback, funcstep_callback, funcfinal_callback, destroy_callback); } #elif !SQLITE_STANDARD n = UnsafeNativeMethods.sqlite3_create_function_interop(_sql, ToUTF8(strFunction), nArgs, 4, IntPtr.Zero, func, funcstep, funcfinal, (needCollSeq == true) ? 1 : 0); if (n == 0) { n = UnsafeNativeMethods.sqlite3_create_function_interop(_sql, ToUTF8(strFunction), nArgs, 1, IntPtr.Zero, func, funcstep, funcfinal, (needCollSeq == true) ? 1 : 0); } #else n = UnsafeNativeMethods.sqlite3_create_function(_sql, ToUTF8(strFunction), nArgs, 4, IntPtr.Zero, func, funcstep, funcfinal); if (n == 0) { n = UnsafeNativeMethods.sqlite3_create_function(_sql, ToUTF8(strFunction), nArgs, 1, IntPtr.Zero, func, funcstep, funcfinal); } #endif if (n > 0) { throw new SqliteException(n, SQLiteLastError()); } }
protected virtual void Dispose(bool disposing) { if (disposing) { foreach (KeyValuePair <long, AggregateData> pair in this._contextDataList) { IDisposable disposable = pair.Value._data as IDisposable; if (disposable != null) { disposable.Dispose(); } } this._contextDataList.Clear(); this._InvokeFunc = null; this._StepFunc = null; this._FinalFunc = null; this._CompareFunc = null; this._base = null; this._contextDataList = null; } }
/////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Placeholder for a user-defined disposal routine /// </summary> /// <param name="disposing">True if the object is being disposed explicitly</param> protected virtual void Dispose(bool disposing) { if (!disposed) { if (disposing) { //////////////////////////////////// // dispose managed resources here... //////////////////////////////////// IDisposable disp; foreach (KeyValuePair <IntPtr, AggregateData> kv in _contextDataList) { disp = kv.Value._data as IDisposable; if (disp != null) { disp.Dispose(); } } _contextDataList.Clear(); _contextDataList = null; _flags = SQLiteConnectionFlags.None; _InvokeFunc = null; _StepFunc = null; _FinalFunc = null; _CompareFunc = null; _base = null; } ////////////////////////////////////// // release unmanaged resources here... ////////////////////////////////////// disposed = true; } }
/// <summary> /// Placeholder for a user-defined disposal routine /// </summary> /// <param name="disposing">True if the object is being disposed explicitly</param> protected virtual void Dispose(bool disposing) { if (disposing) { IDisposable disp; foreach (KeyValuePair <long, AggregateData> kv in _contextDataList) { disp = kv.Value._data as IDisposable; if (disp != null) { disp.Dispose(); } } _contextDataList.Clear(); _InvokeFunc = null; _StepFunc = null; _FinalFunc = null; _CompareFunc = null; _base = null; _contextDataList = null; } }
internal static extern int sqlite3_create_function_v2(IntPtr db, byte[] strName, int nArgs, int nType, IntPtr pvUser, SQLiteCallback func, SQLiteCallback fstep, SQLiteFinalCallback ffinal, SQLiteFinalCallback fdestroy);
internal abstract IntPtr CreateFunction(string strFunction, int nArgs, SQLiteCallback func, SQLiteCallback funcstep, SQLiteCallback funcfinal);
internal static extern int sqlite3_create_function_interop(IntPtr db, byte[] strName, int nArgs, int nType, IntPtr pvUser, SQLiteCallback func, SQLiteCallback fstep, SQLiteFinalCallback ffinal, int needCollSeq);
internal static extern int sqlite3_create_function(IntPtr db, byte[] strName, int nArgs, int nType, IntPtr pvUser, SQLiteCallback func, SQLiteCallback fstep, SQLiteFinalCallback ffinal);
/// <summary> /// Placeholder for a user-defined disposal routine /// </summary> /// <param name="disposing">True if the object is being disposed explicitly</param> protected virtual void Dispose(bool disposing) { if (disposing) { IDisposable disp; foreach (KeyValuePair<long, AggregateData> kv in _contextDataList) { disp = kv.Value._data as IDisposable; if (disp != null) disp.Dispose(); } _contextDataList.Clear(); _InvokeFunc = null; _StepFunc = null; _FinalFunc = null; _CompareFunc = null; _base = null; _contextDataList = null; } }
internal override IntPtr CreateFunction(string strFunction, int nArgs, SQLiteCallback func, SQLiteCallback funcstep, SQLiteCallback funcfinal) { IntPtr nCookie; int n = UnsafeNativeMethods.sqlite3_create_function16_interop(_sql, strFunction, nArgs, 4, func, funcstep, funcfinal, out nCookie); if (n > 0) throw new SQLiteException(n, SQLiteLastError()); return nCookie; }
/////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Placeholder for a user-defined disposal routine /// </summary> /// <param name="disposing">True if the object is being disposed explicitly</param> protected virtual void Dispose(bool disposing) { if (!disposed) { if (disposing) { //////////////////////////////////// // dispose managed resources here... //////////////////////////////////// IDisposable disp; foreach (KeyValuePair<IntPtr, AggregateData> kv in _contextDataList) { disp = kv.Value._data as IDisposable; if (disp != null) disp.Dispose(); } _contextDataList.Clear(); _contextDataList = null; _flags = SQLiteConnectionFlags.None; _InvokeFunc = null; _StepFunc = null; _FinalFunc = null; _CompareFunc = null; _base = null; } ////////////////////////////////////// // release unmanaged resources here... ////////////////////////////////////// disposed = true; } }
internal override SQLiteErrorCode CreateFunction(string strFunction, int nArgs, bool needCollSeq, SQLiteCallback func, SQLiteCallback funcstep, SQLiteFinalCallback funcfinal, bool canThrow) { SQLiteErrorCode n; #if !SQLITE_STANDARD n = UnsafeNativeMethods.sqlite3_create_function_interop(_sql, ToUTF8(strFunction), nArgs, 4, IntPtr.Zero, func, funcstep, funcfinal, (needCollSeq == true) ? 1 : 0); if (n == SQLiteErrorCode.Ok) n = UnsafeNativeMethods.sqlite3_create_function_interop(_sql, ToUTF8(strFunction), nArgs, 1, IntPtr.Zero, func, funcstep, funcfinal, (needCollSeq == true) ? 1 : 0); #else n = UnsafeNativeMethods.sqlite3_create_function(_sql, ToUTF8(strFunction), nArgs, 4, IntPtr.Zero, func, funcstep, funcfinal); if (n == SQLiteErrorCode.Ok) n = UnsafeNativeMethods.sqlite3_create_function(_sql, ToUTF8(strFunction), nArgs, 1, IntPtr.Zero, func, funcstep, funcfinal); #endif if (canThrow && (n != SQLiteErrorCode.Ok)) throw new SQLiteException(n, GetLastError()); return n; }
internal static extern SQLiteErrorCode sqlite3_create_function_interop(IntPtr db, byte[] strName, int nArgs, int nType, IntPtr pvUser, SQLiteCallback func, SQLiteCallback fstep, SQLiteFinalCallback ffinal, int needCollSeq);
internal static extern int sqlite3_create_function16_interop(IntPtr db, string strName, int nArgs, int nType, SQLiteCallback func, SQLiteCallback funcstep, SQLiteCallback funcfinal, out IntPtr nCookie);
internal static extern int sqlite3_create_function_interop(IntPtr db, byte[] strName, int nArgs, int nType, SQLiteCallback func, SQLiteCallback fstep, SQLiteCallback ffinal, out IntPtr nCookie);
internal override void CreateFunction(string strFunction, int nArgs, bool needCollSeq, SQLiteCallback func, SQLiteCallback funcstep, SQLiteFinalCallback funcfinal) { int errorCode = UnsafeNativeMethods.sqlite3_create_function_interop((IntPtr)this._sql, SQLiteConvert.ToUTF8(strFunction), nArgs, 4, IntPtr.Zero, func, funcstep, funcfinal, needCollSeq ? 1 : 0); if (errorCode == 0) { errorCode = UnsafeNativeMethods.sqlite3_create_function_interop((IntPtr)this._sql, SQLiteConvert.ToUTF8(strFunction), nArgs, 1, IntPtr.Zero, func, funcstep, funcfinal, needCollSeq ? 1 : 0); } if (errorCode > 0) { throw new SQLiteException(errorCode, this.SQLiteLastError()); } }
/// <summary> /// Disposes of any active contextData variables that were not automatically cleaned up. Sometimes this can happen if /// someone closes the connection while a DataReader is open. /// </summary> public void Dispose() { Dispose(true); IDisposable disp; foreach (KeyValuePair<long, object> kv in _contextDataList) { disp = kv.Value as IDisposable; if (disp != null) disp.Dispose(); } _contextDataList.Clear(); _InvokeFunc = null; _StepFunc = null; _FinalFunc = null; _CompareFunc = null; _base = null; _contextDataList = null; GC.SuppressFinalize(this); }
internal abstract SQLiteErrorCode CreateFunction(string strFunction, int nArgs, bool needCollSeq, SQLiteCallback func, SQLiteCallback funcstep, SQLiteFinalCallback funcfinal, bool @throw);
internal override void CreateFunction(string strFunction, int nArgs, bool needCollSeq, SQLiteCallback func, SQLiteCallback funcstep, SQLiteFinalCallback funcfinal) { int n; #if !SQLITE_STANDARD n = UnsafeNativeMethods.sqlite3_create_function_interop(_sql, ToUTF8(strFunction), nArgs, 4, IntPtr.Zero, func, funcstep, funcfinal, (needCollSeq == true) ? 1 : 0); if (n == 0) n = UnsafeNativeMethods.sqlite3_create_function_interop(_sql, ToUTF8(strFunction), nArgs, 1, IntPtr.Zero, func, funcstep, funcfinal, (needCollSeq == true) ? 1 : 0); #else n = UnsafeNativeMethods.sqlite3_create_function(_sql, ToUTF8(strFunction), nArgs, 4, IntPtr.Zero, func, funcstep, funcfinal); if (n == 0) n = UnsafeNativeMethods.sqlite3_create_function(_sql, ToUTF8(strFunction), nArgs, 1, IntPtr.Zero, func, funcstep, funcfinal); #endif if (n > 0) throw new SqliteException(n, SQLiteLastError()); }
internal override void CreateFunction(string strFunction, int nArgs, bool needCollSeq, SQLiteCallback func, SQLiteCallback funcstep, SQLiteFinalCallback funcfinal) { int n; #if !SQLITE_STANDARD n = UnsafeNativeMethods.sqlite3_create_function_interop(_sql, ToUTF8(strFunction), nArgs, 4, IntPtr.Zero, func, funcstep, funcfinal, (needCollSeq == true) ? 1 : 0); if (n == 0) { n = UnsafeNativeMethods.sqlite3_create_function_interop(_sql, ToUTF8(strFunction), nArgs, 1, IntPtr.Zero, func, funcstep, funcfinal, (needCollSeq == true) ? 1 : 0); } #else n = UnsafeNativeMethods.sqlite3_create_function(_sql, ToUTF8(strFunction), nArgs, 4, IntPtr.Zero, func, funcstep, funcfinal); if (n == 0) { n = UnsafeNativeMethods.sqlite3_create_function(_sql, ToUTF8(strFunction), nArgs, 1, IntPtr.Zero, func, funcstep, funcfinal); } #endif if (n > 0) { throw new SqliteException(n, SQLiteLastError()); } }
/////////////////////////////////////////////////////////////////// /// <summary> /// See the <see cref="ISQLiteNativeModule.xFindFunction" /> method. /// </summary> /// <param name="pVtab"> /// See the <see cref="ISQLiteNativeModule.xFindFunction" /> method. /// </param> /// <param name="nArg"> /// See the <see cref="ISQLiteNativeModule.xFindFunction" /> method. /// </param> /// <param name="zName"> /// See the <see cref="ISQLiteNativeModule.xFindFunction" /> method. /// </param> /// <param name="callback"> /// See the <see cref="ISQLiteNativeModule.xFindFunction" /> method. /// </param> /// <param name="pClientData"> /// See the <see cref="ISQLiteNativeModule.xFindFunction" /> method. /// </param> /// <returns> /// See the <see cref="ISQLiteNativeModule.xFindFunction" /> method. /// </returns> public int xFindFunction( IntPtr pVtab, int nArg, IntPtr zName, ref SQLiteCallback callback, ref IntPtr pClientData ) { // // NOTE: Called by native code. // // CheckDisposed(); /* EXEMPT */ if (module == null) { ModuleNotAvailableTableError(pVtab); return 0; } return module.xFindFunction( pVtab, nArg, zName, ref callback, ref pClientData); }
internal abstract void CreateFunction(string strFunction, int nArgs, bool needCollSeq, SQLiteCallback func, SQLiteCallback funcstep, SQLiteFinalCallback funcfinal);
/////////////////////////////////////////////////////////////////////// /// <summary> /// See the <see cref="ISQLiteNativeModule.xFindFunction" /> method. /// </summary> /// <param name="pVtab"> /// See the <see cref="ISQLiteNativeModule.xFindFunction" /> method. /// </param> /// <param name="nArg"> /// See the <see cref="ISQLiteNativeModule.xFindFunction" /> method. /// </param> /// <param name="zName"> /// See the <see cref="ISQLiteNativeModule.xFindFunction" /> method. /// </param> /// <param name="callback"> /// See the <see cref="ISQLiteNativeModule.xFindFunction" /> method. /// </param> /// <param name="pClientData"> /// See the <see cref="ISQLiteNativeModule.xFindFunction" /> method. /// </param> /// <returns> /// See the <see cref="ISQLiteNativeModule.xFindFunction" /> method. /// </returns> private int xFindFunction( IntPtr pVtab, int nArg, IntPtr zName, ref SQLiteCallback callback, ref IntPtr pClientData ) { try { SQLiteVirtualTable table = TableFromIntPtr(pVtab); if (table != null) { string name = SQLiteString.StringFromUtf8IntPtr(zName); SQLiteFunction function = null; if (FindFunction( table, nArg, name, ref function, ref pClientData)) { if (function != null) { string key = GetFunctionKey(nArg, name, function); functions[key] = function; callback = function.ScalarCallback; return 1; } else { SetTableError(pVtab, "no function was created"); } } } } catch (Exception e) /* NOTE: Must catch ALL. */ { SetTableError(pVtab, e.ToString()); } return 0; /* NOTE: On any error, return "no such function". */ }
private static extern ResultCode sqlite3_exec(IntPtr handle, IntPtr query, SQLiteCallback callBack, IntPtr pArg, out string errMsg);
internal override void CreateFunction(string strFunction, int nArgs, bool needCollSeq, SQLiteCallback func, SQLiteCallback funcstep, SQLiteFinalCallback funcfinal) { int n; #if MONOTOUCH var data = new FunctionData(); data.Func = func; data.FuncStep = funcstep; data.FuncFinal = funcfinal; SQLiteCallback func_callback = func == null ? null : new SQLiteCallback(scalar_callback); SQLiteCallback funcstep_callback = funcstep == null ? null : new SQLiteCallback(step_callback); SQLiteFinalCallback funcfinal_callback = funcfinal == null ? null : new SQLiteFinalCallback(final_callback); IntPtr user_data; user_data = GCHandle.ToIntPtr(GCHandle.Alloc(data)); n = UnsafeNativeMethods.sqlite3_create_function_v2(_sql, ToUTF8(strFunction), nArgs, 4, user_data, func_callback, funcstep_callback, funcfinal_callback, destroy_callback); if (n == 0) { // sqlite3_create_function_v2 will call 'destroy_callback' if it fails, so we need to recreate the gchandle here. user_data = GCHandle.ToIntPtr(GCHandle.Alloc(data)); n = UnsafeNativeMethods.sqlite3_create_function_v2(_sql, ToUTF8(strFunction), nArgs, 1, user_data, func_callback, funcstep_callback, funcfinal_callback, destroy_callback); } #elif !SQLITE_STANDARD n = UnsafeNativeMethods.sqlite3_create_function_interop(_sql, ToUTF8(strFunction), nArgs, 4, IntPtr.Zero, func, funcstep, funcfinal, (needCollSeq == true) ? 1 : 0); if (n == 0) n = UnsafeNativeMethods.sqlite3_create_function_interop(_sql, ToUTF8(strFunction), nArgs, 1, IntPtr.Zero, func, funcstep, funcfinal, (needCollSeq == true) ? 1 : 0); #else n = UnsafeNativeMethods.sqlite3_create_function(_sql, ToUTF8(strFunction), nArgs, 4, IntPtr.Zero, func, funcstep, funcfinal); if (n == 0) n = UnsafeNativeMethods.sqlite3_create_function(_sql, ToUTF8(strFunction), nArgs, 1, IntPtr.Zero, func, funcstep, funcfinal); #endif if (n > 0) throw new SqliteException(n, SQLiteLastError()); }
internal static void BindFunction(SQLiteBase sqliteBase, SQLiteFunctionAttribute functionAttribute, SQLiteFunction function, SQLiteConnectionFlags flags) { SQLiteCallback sQLiteCallback; SQLiteCallback sQLiteCallback1; SQLiteFinalCallback sQLiteFinalCallback; SQLiteCollation sQLiteCollation; SQLiteCollation sQLiteCollation1; if (sqliteBase == null) { throw new ArgumentNullException("sqliteBase"); } if (functionAttribute == null) { throw new ArgumentNullException("functionAttribute"); } if (function == null) { throw new ArgumentNullException("function"); } FunctionType funcType = functionAttribute.FuncType; function._base = sqliteBase; function._flags = flags; SQLiteFunction sQLiteFunction = function; if (funcType == FunctionType.Scalar) { sQLiteCallback = new SQLiteCallback(function.ScalarCallback); } else { sQLiteCallback = null; } sQLiteFunction._InvokeFunc = sQLiteCallback; SQLiteFunction sQLiteFunction1 = function; if (funcType == FunctionType.Aggregate) { sQLiteCallback1 = new SQLiteCallback(function.StepCallback); } else { sQLiteCallback1 = null; } sQLiteFunction1._StepFunc = sQLiteCallback1; SQLiteFunction sQLiteFunction2 = function; if (funcType == FunctionType.Aggregate) { sQLiteFinalCallback = new SQLiteFinalCallback(function.FinalCallback); } else { sQLiteFinalCallback = null; } sQLiteFunction2._FinalFunc = sQLiteFinalCallback; SQLiteFunction sQLiteFunction3 = function; if (funcType == FunctionType.Collation) { sQLiteCollation = new SQLiteCollation(function.CompareCallback); } else { sQLiteCollation = null; } sQLiteFunction3._CompareFunc = sQLiteCollation; SQLiteFunction sQLiteFunction4 = function; if (funcType == FunctionType.Collation) { sQLiteCollation1 = new SQLiteCollation(function.CompareCallback16); } else { sQLiteCollation1 = null; } sQLiteFunction4._CompareFunc16 = sQLiteCollation1; string name = functionAttribute.Name; if (funcType == FunctionType.Collation) { sqliteBase.CreateCollation(name, function._CompareFunc, function._CompareFunc16, true); return; } bool flag = function is SQLiteFunctionEx; sqliteBase.CreateFunction(name, functionAttribute.Arguments, flag, function._InvokeFunc, function._StepFunc, function._FinalFunc, true); }