public static void Initialize() { if (SQLite3.StaticIsInitialized()) { return; } if (!AppDomain.CurrentDomain.IsDefaultAppDomain() && UnsafeNativeMethods.GetSettingValue("Force_SQLiteLog", null) == null) { return; } lock (SQLiteLog.syncRoot) { if (SQLiteLog._domainUnload == null) { SQLiteLog._domainUnload = new EventHandler(SQLiteLog.DomainUnload); AppDomain.CurrentDomain.DomainUnload += SQLiteLog._domainUnload; } if (SQLiteLog._sql == null) { SQLiteLog._sql = new SQLite3(SQLiteDateFormats.ISO8601, DateTimeKind.Unspecified, null, IntPtr.Zero, null, false); } if (SQLiteLog._callback == null) { SQLiteLog._callback = new SQLiteLogCallback(SQLiteLog.LogCallback); SQLiteErrorCode sQLiteErrorCode = SQLiteLog._sql.SetLogCallback(SQLiteLog._callback); if (sQLiteErrorCode != SQLiteErrorCode.Ok) { throw new SQLiteException(sQLiteErrorCode, "Failed to initialize logging."); } } SQLiteLog._enabled = true; SQLiteLog.AddDefaultHandler(); } }
protected UnsafeNativeMethods.xSessionFilter GetDelegate(SessionTableFilterCallback tableFilterCallback, object clientData) { if (tableFilterCallback == null) { return(null); } return((IntPtr context, IntPtr pTblName) => { int num; try { string str = SQLiteString.StringFromUtf8IntPtr(pTblName); num = (tableFilterCallback(clientData, str) ? 1 : 0); } catch (Exception exception1) { Exception exception = exception1; try { if (HelperMethods.LogCallbackExceptions(base.GetFlags())) { SQLiteLog.LogMessage(-2146233088, HelperMethods.StringFormat(CultureInfo.CurrentCulture, "Caught exception in \"{0}\" method: {1}", new object[] { "xSessionFilter", exception })); } } catch { } return 0; } return num; }); }
private int Filter(IntPtr context, IntPtr pTblName) { int num; try { num = (this.tableFilterCallback(this.tableFilterClientData, SQLiteString.StringFromUtf8IntPtr(pTblName)) ? 1 : 0); } catch (Exception exception1) { Exception exception = exception1; try { if (HelperMethods.LogCallbackExceptions(base.GetFlags())) { CultureInfo currentCulture = CultureInfo.CurrentCulture; object[] objArray = new object[] { "xSessionFilter", exception }; SQLiteLog.LogMessage(-2146233088, HelperMethods.StringFormat(currentCulture, "Caught exception in \"{0}\" method: {1}", objArray)); } } catch { } return(0); } return(num); }
internal int CompareCallback16(IntPtr ptr, int len1, IntPtr ptr1, int len2, IntPtr ptr2) { int num; try { num = this.Compare(SQLite3_UTF16.UTF16ToString(ptr1, len1), SQLite3_UTF16.UTF16ToString(ptr2, len2)); } catch (Exception exception1) { Exception exception = exception1; try { if (HelperMethods.LogCallbackExceptions(this._flags)) { CultureInfo currentCulture = CultureInfo.CurrentCulture; object[] objArray = new object[] { "Compare (UTF16)", exception }; SQLiteLog.LogMessage(-2146233088, HelperMethods.StringFormat(currentCulture, "Caught exception in \"{0}\" method: {1}", objArray)); } } catch { } if (this._base != null && this._base.IsOpen()) { this._base.Cancel(); } return(0); } return(num); }
protected virtual void Dispose(bool disposing) { try { if (!this.disposed && this.statement != IntPtr.Zero) { try { if (HelperMethods.LogPrepare(this.GetFlags())) { CultureInfo currentCulture = CultureInfo.CurrentCulture; object[] objArray = new object[] { (disposing ? "disposed" : "finalized"), this.statement }; SQLiteLog.LogMessage(SQLiteErrorCode.Misuse, HelperMethods.StringFormat(currentCulture, "Connection lock object was {0} with statement {1}", objArray)); } } catch { } } } finally { this.disposed = true; } }
private static void DomainUnload(object sender, EventArgs e) { lock (SQLiteLog.syncRoot) { SQLiteLog.RemoveDefaultHandler(); SQLiteLog._enabled = false; if (SQLiteLog._sql != null) { SQLiteErrorCode sQLiteErrorCode = SQLiteLog._sql.Shutdown(); if (sQLiteErrorCode != SQLiteErrorCode.Ok) { throw new SQLiteException(sQLiteErrorCode, "Failed to shutdown interface."); } sQLiteErrorCode = SQLiteLog._sql.SetLogCallback(null); if (sQLiteErrorCode != SQLiteErrorCode.Ok) { throw new SQLiteException(sQLiteErrorCode, "Failed to shutdown logging."); } } if (SQLiteLog._callback != null) { SQLiteLog._callback = null; } if (SQLiteLog._domainUnload != null) { AppDomain.CurrentDomain.DomainUnload -= SQLiteLog._domainUnload; SQLiteLog._domainUnload = null; } } }
protected UnsafeNativeMethods.xSessionConflict GetDelegate(SessionConflictCallback conflictCallback, object clientData) { if (conflictCallback == null) { return(null); } return((IntPtr context, SQLiteChangeSetConflictType type, IntPtr iterator) => { SQLiteChangeSetConflictResult sQLiteChangeSetConflictResult; try { ISQLiteChangeSetMetadataItem sQLiteChangeSetMetadataItem = this.CreateMetadataItem(iterator); if (sQLiteChangeSetMetadataItem == null) { throw new SQLiteException("could not create metadata item"); } sQLiteChangeSetConflictResult = conflictCallback(clientData, type, sQLiteChangeSetMetadataItem); } catch (Exception exception1) { Exception exception = exception1; try { if (HelperMethods.LogCallbackExceptions(base.GetFlags())) { SQLiteLog.LogMessage(-2146233088, HelperMethods.StringFormat(CultureInfo.CurrentCulture, "Caught exception in \"{0}\" method: {1}", new object[] { "xSessionConflict", exception })); } } catch { } return SQLiteChangeSetConflictResult.Abort; } return sQLiteChangeSetConflictResult; }); }
static SQLiteFactory() { SQLiteFactory.Instance = new SQLiteFactory(); SQLiteFactory.DefaultTypeName = "EntityWorker.SQLite.Linq.SQLiteProviderServices, EntityWorker.SQLite.Linq, Version={0}, Culture=neutral, PublicKeyToken=db937bc2d44ff139"; SQLiteFactory.DefaultBindingFlags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic; EntityWorker.SQLite.UnsafeNativeMethods.Initialize(); SQLiteLog.Initialize(); string str = "3.5.0.0"; CultureInfo invariantCulture = CultureInfo.InvariantCulture; object[] objArray = new object[] { str }; SQLiteFactory._dbProviderServicesType = Type.GetType(HelperMethods.StringFormat(invariantCulture, "System.Data.Common.DbProviderServices, System.Data.Entity, Version={0}, Culture=neutral, PublicKeyToken=b77a5c561934e089", objArray), false); }
internal void FinalCallback(IntPtr context) { SQLiteFunction.AggregateData aggregateDatum; try { object obj = null; if (this._base != null) { IntPtr intPtr = this._base.AggregateContext(context); if (this._contextDataList != null && this._contextDataList.TryGetValue(intPtr, out aggregateDatum)) { obj = aggregateDatum._data; this._contextDataList.Remove(intPtr); } } try { this._context = context; this.SetReturnValue(context, this.Final(obj)); } finally { IDisposable disposable = obj as IDisposable; if (disposable != null) { disposable.Dispose(); } } } catch (Exception exception1) { Exception exception = exception1; try { if (HelperMethods.LogCallbackExceptions(this._flags)) { CultureInfo currentCulture = CultureInfo.CurrentCulture; object[] objArray = new object[] { "Final", exception }; SQLiteLog.LogMessage(-2146233088, HelperMethods.StringFormat(currentCulture, "Caught exception in \"{0}\" method: {1}", objArray)); } } catch { } } }
private SQLiteErrorCode Input(IntPtr context, IntPtr pData, ref int nData) { SQLiteErrorCode sQLiteErrorCode; try { Stream stream = this.stream; if (stream != null) { if (nData > 0) { byte[] numArray = new byte[nData]; int num = stream.Read(numArray, 0, nData); if (num > 0 && pData != IntPtr.Zero) { Marshal.Copy(numArray, 0, pData, num); } nData = num; } sQLiteErrorCode = SQLiteErrorCode.Ok; } else { sQLiteErrorCode = SQLiteErrorCode.Misuse; } } catch (Exception exception1) { Exception exception = exception1; try { if (HelperMethods.LogCallbackExceptions(this.GetFlags())) { CultureInfo currentCulture = CultureInfo.CurrentCulture; object[] objArray = new object[] { "xSessionInput", exception }; SQLiteLog.LogMessage(-2146233088, HelperMethods.StringFormat(currentCulture, "Caught exception in \"{0}\" method: {1}", objArray)); } } catch { } return(SQLiteErrorCode.IoErr_Read); } return(sQLiteErrorCode); }
internal void StepCallback(IntPtr context, int nArgs, IntPtr argsptr) { try { SQLiteFunction.AggregateData aggregateDatum = null; if (this._base != null) { IntPtr intPtr = this._base.AggregateContext(context); if (this._contextDataList != null && !this._contextDataList.TryGetValue(intPtr, out aggregateDatum)) { aggregateDatum = new SQLiteFunction.AggregateData(); this._contextDataList[intPtr] = aggregateDatum; } } if (aggregateDatum == null) { aggregateDatum = new SQLiteFunction.AggregateData(); } try { this._context = context; this.Step(this.ConvertParams(nArgs, argsptr), aggregateDatum._count, ref aggregateDatum._data); } finally { aggregateDatum._count++; } } catch (Exception exception1) { Exception exception = exception1; try { if (HelperMethods.LogCallbackExceptions(this._flags)) { CultureInfo currentCulture = CultureInfo.CurrentCulture; object[] objArray = new object[] { "Step", exception }; SQLiteLog.LogMessage(-2146233088, HelperMethods.StringFormat(currentCulture, "Caught exception in \"{0}\" method: {1}", objArray)); } } catch { } } }
internal void ScalarCallback(IntPtr context, int nArgs, IntPtr argsptr) { try { this._context = context; this.SetReturnValue(context, this.Invoke(this.ConvertParams(nArgs, argsptr))); } catch (Exception exception1) { Exception exception = exception1; try { if (HelperMethods.LogCallbackExceptions(this._flags)) { CultureInfo currentCulture = CultureInfo.CurrentCulture; object[] objArray = new object[] { "Invoke", exception }; SQLiteLog.LogMessage(-2146233088, HelperMethods.StringFormat(currentCulture, "Caught exception in \"{0}\" method: {1}", objArray)); } } catch { } } }
public static void AddDefaultHandler() { SQLiteLog.InitializeDefaultHandler(); SQLiteLog.Log += SQLiteLog._defaultHandler; }
public static void RemoveDefaultHandler() { SQLiteLog.InitializeDefaultHandler(); SQLiteLog.Log -= SQLiteLog._defaultHandler; }
public static void LogMessage(int errorCode, string message) { SQLiteLog.LogMessage(errorCode, message); }
public static void LogMessage(string message) { SQLiteLog.LogMessage(null, message); }
private void BindParameter(int index, SQLiteParameter param) { bool flag; SQLiteBase sQLiteBase; SQLiteConnectionFlags sQLiteConnectionFlag; int num; string str; if (param == null) { throw new SQLiteException("Insufficient parameters supplied to the command"); } if ((this._flags & SQLiteConnectionFlags.UseConnectionBindValueCallbacks) == SQLiteConnectionFlags.UseConnectionBindValueCallbacks) { this.InvokeBindValueCallback(index, param, out flag); if (flag) { return; } } object value = param.Value; DbType dbType = param.DbType; if (value != null && dbType == DbType.Object) { dbType = SQLiteConvert.TypeToDbType(value.GetType()); } if (HelperMethods.LogPreBind(this._flags)) { IntPtr _sqliteStmt = this._sqlite_stmt; CultureInfo currentCulture = CultureInfo.CurrentCulture; object[] objArray = new object[] { _sqliteStmt, index, dbType, value }; SQLiteLog.LogMessage(HelperMethods.StringFormat(currentCulture, "Binding statement {0} paramter #{1} with database type {2} and raw value {{{3}}}...", objArray)); } if (value == null || Convert.IsDBNull(value)) { this._sql.Bind_Null(this, this._flags, index); return; } CultureInfo invariantCulture = CultureInfo.InvariantCulture; bool flag1 = (this._flags & SQLiteConnectionFlags.BindInvariantText) == SQLiteConnectionFlags.BindInvariantText; CultureInfo cultureInfo = CultureInfo.CurrentCulture; if ((this._flags & SQLiteConnectionFlags.ConvertInvariantText) == SQLiteConnectionFlags.ConvertInvariantText) { cultureInfo = invariantCulture; } if ((this._flags & SQLiteConnectionFlags.BindAllAsText) == SQLiteConnectionFlags.BindAllAsText) { if (value is DateTime) { this._sql.Bind_DateTime(this, this._flags, index, (DateTime)value); return; } this._sql.Bind_Text(this, this._flags, index, (flag1 ? SQLiteConvert.ToStringWithProvider(value, invariantCulture) : SQLiteConvert.ToStringWithProvider(value, cultureInfo))); return; } bool flag2 = (this._flags & SQLiteConnectionFlags.BindInvariantDecimal) == SQLiteConnectionFlags.BindInvariantDecimal; if ((this._flags & SQLiteConnectionFlags.BindDecimalAsText) == SQLiteConnectionFlags.BindDecimalAsText && value is decimal) { this._sql.Bind_Text(this, this._flags, index, (flag1 || flag2 ? SQLiteConvert.ToStringWithProvider(value, invariantCulture) : SQLiteConvert.ToStringWithProvider(value, cultureInfo))); return; } switch (dbType) { case DbType.Binary: { this._sql.Bind_Blob(this, this._flags, index, (byte[])value); return; } case DbType.Byte: { this._sql.Bind_UInt32(this, this._flags, index, Convert.ToByte(value, cultureInfo)); return; } case DbType.Boolean: { this._sql.Bind_Boolean(this, this._flags, index, SQLiteConvert.ToBoolean(value, cultureInfo, true)); return; } case DbType.Currency: case DbType.Double: case DbType.Single: { this._sql.Bind_Double(this, this._flags, index, Convert.ToDouble(value, cultureInfo)); return; } case DbType.Date: case DbType.DateTime: case DbType.Time: { this._sql.Bind_DateTime(this, this._flags, index, (value is string?this._sql.ToDateTime((string)value) : Convert.ToDateTime(value, cultureInfo))); return; } case DbType.Decimal: { this._sql.Bind_Text(this, this._flags, index, (flag1 || flag2 ? SQLiteConvert.ToStringWithProvider(Convert.ToDecimal(value, cultureInfo), invariantCulture) : SQLiteConvert.ToStringWithProvider(Convert.ToDecimal(value, cultureInfo), cultureInfo))); return; } case DbType.Guid: { if (this._command.Connection._binaryGuid) { SQLiteBase sQLiteBase1 = this._sql; SQLiteConnectionFlags sQLiteConnectionFlag1 = this._flags; Guid guid = (Guid)value; sQLiteBase1.Bind_Blob(this, sQLiteConnectionFlag1, index, guid.ToByteArray()); return; } this._sql.Bind_Text(this, this._flags, index, (flag1 ? SQLiteConvert.ToStringWithProvider(value, invariantCulture) : SQLiteConvert.ToStringWithProvider(value, cultureInfo))); return; } case DbType.Int16: { this._sql.Bind_Int32(this, this._flags, index, Convert.ToInt16(value, cultureInfo)); return; } case DbType.Int32: { this._sql.Bind_Int32(this, this._flags, index, Convert.ToInt32(value, cultureInfo)); return; } case DbType.Int64: { this._sql.Bind_Int64(this, this._flags, index, Convert.ToInt64(value, cultureInfo)); return; } case DbType.Object: case DbType.String: { sQLiteBase = this._sql; sQLiteConnectionFlag = this._flags; num = index; str = (flag1 ? SQLiteConvert.ToStringWithProvider(value, invariantCulture) : SQLiteConvert.ToStringWithProvider(value, cultureInfo)); sQLiteBase.Bind_Text(this, sQLiteConnectionFlag, num, str); return; } case DbType.SByte: { this._sql.Bind_Int32(this, this._flags, index, Convert.ToSByte(value, cultureInfo)); return; } case DbType.UInt16: { this._sql.Bind_UInt32(this, this._flags, index, Convert.ToUInt16(value, cultureInfo)); return; } case DbType.UInt32: { this._sql.Bind_UInt32(this, this._flags, index, Convert.ToUInt32(value, cultureInfo)); return; } case DbType.UInt64: { this._sql.Bind_UInt64(this, this._flags, index, Convert.ToUInt64(value, cultureInfo)); return; } default: { sQLiteBase = this._sql; sQLiteConnectionFlag = this._flags; num = index; str = (flag1 ? SQLiteConvert.ToStringWithProvider(value, invariantCulture) : SQLiteConvert.ToStringWithProvider(value, cultureInfo)); sQLiteBase.Bind_Text(this, sQLiteConnectionFlag, num, str); return; } } }