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); }
public static string[] StringArrayFromUtf8SizeAndIntPtr(int argc, IntPtr argv) { string str; if (argc < 0) { return(null); } if (argv == IntPtr.Zero) { return(null); } string[] strArrays = new string[argc]; int num = 0; int size = 0; while (num < (int)strArrays.Length) { IntPtr intPtr = SQLiteMarshal.ReadIntPtr(argv, size); string[] strArrays1 = strArrays; int num1 = num; if (intPtr != IntPtr.Zero) { str = SQLiteString.StringFromUtf8IntPtr(intPtr); } else { str = null; } strArrays1[num1] = str; num++; size += IntPtr.Size; } return(strArrays); }
public void Lock() { this.CheckDisposed(); if (this.statement != IntPtr.Zero) { return; } IntPtr zero = IntPtr.Zero; try { int num = 0; zero = SQLiteString.Utf8IntPtrFromString("SELECT 1;", ref num); IntPtr intPtr = IntPtr.Zero; int num1 = 0; SQLiteErrorCode sQLiteErrorCode = UnsafeNativeMethods.sqlite3_prepare_interop(this.GetIntPtr(), zero, num, ref this.statement, ref intPtr, ref num1); if (sQLiteErrorCode != SQLiteErrorCode.Ok) { throw new SQLiteException(sQLiteErrorCode, "sqlite3_prepare_interop"); } } finally { if (zero != IntPtr.Zero) { SQLiteMemory.Free(zero); zero = IntPtr.Zero; } } }
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; }); }
public string GetString() { if (this.pValue == IntPtr.Zero) { return(null); } int num = 0; IntPtr intPtr = UnsafeNativeMethods.sqlite3_value_text_interop(this.pValue, ref num); return(SQLiteString.StringFromUtf8IntPtr(intPtr, num)); }
public static IntPtr[] Utf8IntPtrArrayFromStringArray(string[] values) { if (values == null) { return(null); } IntPtr[] intPtrArray = new IntPtr[(int)values.Length]; for (int i = 0; i < (int)intPtrArray.Length; i++) { intPtrArray[i] = SQLiteString.Utf8IntPtrFromString(values[i]); } return(intPtrArray); }
public void SetError(string value) { if (this.pContext == IntPtr.Zero) { throw new InvalidOperationException(); } byte[] utf8BytesFromString = SQLiteString.GetUtf8BytesFromString(value); if (utf8BytesFromString == null) { throw new ArgumentNullException("value"); } UnsafeNativeMethods.sqlite3_result_error(this.pContext, utf8BytesFromString, (int)utf8BytesFromString.Length); }
public static string StringFromUtf8IntPtr(IntPtr pValue, int length) { if (pValue == IntPtr.Zero) { return(null); } if (length <= 0) { return(string.Empty); } byte[] numArray = new byte[length]; Marshal.Copy(pValue, numArray, 0, length); return(SQLiteString.GetStringFromUtf8Bytes(numArray)); }
public void LoadDifferencesFromTable(string fromDatabaseName, string tableName) { this.CheckDisposed(); this.CheckHandle(); if (fromDatabaseName == null) { throw new ArgumentNullException("fromDatabaseName"); } if (tableName == null) { throw new ArgumentNullException("tableName"); } IntPtr zero = IntPtr.Zero; try { SQLiteErrorCode sQLiteErrorCode = UnsafeNativeMethods.sqlite3session_diff(this.session, SQLiteString.GetUtf8BytesFromString(fromDatabaseName), SQLiteString.GetUtf8BytesFromString(tableName), ref zero); if (sQLiteErrorCode != SQLiteErrorCode.Ok) { string str = null; if (zero != IntPtr.Zero) { str = SQLiteString.StringFromUtf8IntPtr(zero); if (!string.IsNullOrEmpty(str)) { CultureInfo currentCulture = CultureInfo.CurrentCulture; object[] objArray = new object[] { str }; str = HelperMethods.StringFormat(currentCulture, ": {0}", objArray); } } CultureInfo cultureInfo = CultureInfo.CurrentCulture; object[] objArray1 = new object[] { "sqlite3session_diff", str }; throw new SQLiteException(sQLiteErrorCode, HelperMethods.StringFormat(cultureInfo, "{0}{1}", objArray1)); } } finally { if (zero != IntPtr.Zero) { SQLiteMemory.Free(zero); zero = IntPtr.Zero; } } }
private void PopulateOperationMetadata() { if (this.tableName == null || !this.numberOfColumns.HasValue || !this.operationCode.HasValue || !this.indirect.HasValue) { this.CheckIterator(); IntPtr zero = IntPtr.Zero; SQLiteAuthorizerActionCode sQLiteAuthorizerActionCode = SQLiteAuthorizerActionCode.None; int num = 0; int num1 = 0; SQLiteErrorCode sQLiteErrorCode = UnsafeNativeMethods.sqlite3changeset_op(this.iterator.GetIntPtr(), ref zero, ref num1, ref sQLiteAuthorizerActionCode, ref num); if (sQLiteErrorCode != SQLiteErrorCode.Ok) { throw new SQLiteException(sQLiteErrorCode, "sqlite3changeset_op"); } this.tableName = SQLiteString.StringFromUtf8IntPtr(zero); this.numberOfColumns = new int?(num1); this.operationCode = new SQLiteAuthorizerActionCode?(sQLiteAuthorizerActionCode); this.indirect = new bool?(num != 0); } }
public static IntPtr Utf8IntPtrFromString(string value, ref int length) { if (value == null) { return(IntPtr.Zero); } IntPtr zero = IntPtr.Zero; byte[] utf8BytesFromString = SQLiteString.GetUtf8BytesFromString(value); if (utf8BytesFromString == null) { return(IntPtr.Zero); } length = (int)utf8BytesFromString.Length; zero = SQLiteMemory.Allocate(length + 1); if (zero == IntPtr.Zero) { return(IntPtr.Zero); } Marshal.Copy(utf8BytesFromString, 0, zero, length); Marshal.WriteByte(zero, length, 0); return(zero); }
public void AttachTable(string name) { this.CheckDisposed(); this.CheckHandle(); SQLiteErrorCode sQLiteErrorCode = UnsafeNativeMethods.sqlite3session_attach(this.session, SQLiteString.GetUtf8BytesFromString(name)); if (sQLiteErrorCode != SQLiteErrorCode.Ok) { throw new SQLiteException(sQLiteErrorCode, "sqlite3session_attach"); } }
private void InitializeHandle() { if (this.session != IntPtr.Zero) { return; } SQLiteErrorCode sQLiteErrorCode = UnsafeNativeMethods.sqlite3session_create(base.GetIntPtr(), SQLiteString.GetUtf8BytesFromString(this.databaseName), ref this.session); if (sQLiteErrorCode != SQLiteErrorCode.Ok) { throw new SQLiteException(sQLiteErrorCode, "sqlite3session_create"); } }
internal static void ToIntPtr(SQLiteIndex index, IntPtr pIndex, bool includeInput) { if (index == null) { return; } SQLiteIndexOutputs outputs = index.Outputs; if (outputs == null) { return; } SQLiteIndexConstraintUsage[] constraintUsages = outputs.ConstraintUsages; if (constraintUsages == null) { return; } SQLiteIndexInputs inputs = null; SQLiteIndexConstraint[] constraints = null; SQLiteIndexOrderBy[] orderBys = null; if (includeInput) { inputs = index.Inputs; if (inputs == null) { return; } constraints = inputs.Constraints; if (constraints == null) { return; } orderBys = inputs.OrderBys; if (orderBys == null) { return; } } if (pIndex == IntPtr.Zero) { return; } int num = 0; int num1 = SQLiteMarshal.ReadInt32(pIndex, num); if (includeInput && num1 != (int)constraints.Length) { return; } if (num1 != (int)constraintUsages.Length) { return; } num = SQLiteMarshal.NextOffsetOf(num, 4, IntPtr.Size); if (includeInput) { IntPtr intPtr = SQLiteMarshal.ReadIntPtr(pIndex, num); int num2 = Marshal.SizeOf(typeof(UnsafeNativeMethods.sqlite3_index_constraint)); for (int i = 0; i < num1; i++) { UnsafeNativeMethods.sqlite3_index_constraint sqlite3IndexConstraint = new UnsafeNativeMethods.sqlite3_index_constraint(constraints[i]); Marshal.StructureToPtr(sqlite3IndexConstraint, SQLiteMarshal.IntPtrForOffset(intPtr, i * num2), false); } } num = SQLiteMarshal.NextOffsetOf(num, IntPtr.Size, 4); int num3 = (includeInput ? SQLiteMarshal.ReadInt32(pIndex, num) : 0); if (includeInput && num3 != (int)orderBys.Length) { return; } num = SQLiteMarshal.NextOffsetOf(num, 4, IntPtr.Size); if (includeInput) { IntPtr intPtr1 = SQLiteMarshal.ReadIntPtr(pIndex, num); int num4 = Marshal.SizeOf(typeof(UnsafeNativeMethods.sqlite3_index_orderby)); for (int j = 0; j < num3; j++) { UnsafeNativeMethods.sqlite3_index_orderby sqlite3IndexOrderby = new UnsafeNativeMethods.sqlite3_index_orderby(orderBys[j]); Marshal.StructureToPtr(sqlite3IndexOrderby, SQLiteMarshal.IntPtrForOffset(intPtr1, j * num4), false); } } num = SQLiteMarshal.NextOffsetOf(num, IntPtr.Size, IntPtr.Size); IntPtr intPtr2 = SQLiteMarshal.ReadIntPtr(pIndex, num); int num5 = Marshal.SizeOf(typeof(UnsafeNativeMethods.sqlite3_index_constraint_usage)); for (int k = 0; k < num1; k++) { UnsafeNativeMethods.sqlite3_index_constraint_usage sqlite3IndexConstraintUsage = new UnsafeNativeMethods.sqlite3_index_constraint_usage(constraintUsages[k]); Marshal.StructureToPtr(sqlite3IndexConstraintUsage, SQLiteMarshal.IntPtrForOffset(intPtr2, k * num5), false); } num = SQLiteMarshal.NextOffsetOf(num, IntPtr.Size, 4); SQLiteMarshal.WriteInt32(pIndex, num, outputs.IndexNumber); num = SQLiteMarshal.NextOffsetOf(num, 4, IntPtr.Size); SQLiteMarshal.WriteIntPtr(pIndex, num, SQLiteString.Utf8IntPtrFromString(outputs.IndexString)); num = SQLiteMarshal.NextOffsetOf(num, IntPtr.Size, 4); SQLiteMarshal.WriteInt32(pIndex, num, (outputs.NeedToFreeIndexString != 0 ? outputs.NeedToFreeIndexString : 1)); num = SQLiteMarshal.NextOffsetOf(num, 4, 4); SQLiteMarshal.WriteInt32(pIndex, num, outputs.OrderByConsumed); num = SQLiteMarshal.NextOffsetOf(num, 4, 8); if (outputs.EstimatedCost.HasValue) { SQLiteMarshal.WriteDouble(pIndex, num, outputs.EstimatedCost.GetValueOrDefault()); } num = SQLiteMarshal.NextOffsetOf(num, 8, 8); if (outputs.CanUseEstimatedRows() && outputs.EstimatedRows.HasValue) { SQLiteMarshal.WriteInt64(pIndex, num, outputs.EstimatedRows.GetValueOrDefault()); } num = SQLiteMarshal.NextOffsetOf(num, 8, 4); if (outputs.CanUseIndexFlags() && outputs.IndexFlags.HasValue) { SQLiteMarshal.WriteInt32(pIndex, num, (int)outputs.IndexFlags.GetValueOrDefault()); } num = SQLiteMarshal.NextOffsetOf(num, 4, 8); if (outputs.CanUseColumnsUsed() && outputs.ColumnsUsed.HasValue) { SQLiteMarshal.WriteInt64(pIndex, num, outputs.ColumnsUsed.GetValueOrDefault()); } }
public static IntPtr Utf8IntPtrFromString(string value) { int num = 0; return(SQLiteString.Utf8IntPtrFromString(value, ref num)); }
public static string StringFromUtf8IntPtr(IntPtr pValue) { return(SQLiteString.StringFromUtf8IntPtr(pValue, SQLiteString.ProbeForUtf8ByteLength(pValue, SQLiteString.ThirtyBits))); }
internal static void FromIntPtr(IntPtr pIndex, bool includeOutput, ref SQLiteIndex index) { if (pIndex == IntPtr.Zero) { return; } int num = 0; int num1 = SQLiteMarshal.ReadInt32(pIndex, num); num = SQLiteMarshal.NextOffsetOf(num, 4, IntPtr.Size); IntPtr intPtr = SQLiteMarshal.ReadIntPtr(pIndex, num); num = SQLiteMarshal.NextOffsetOf(num, IntPtr.Size, 4); int num2 = SQLiteMarshal.ReadInt32(pIndex, num); num = SQLiteMarshal.NextOffsetOf(num, 4, IntPtr.Size); IntPtr intPtr1 = SQLiteMarshal.ReadIntPtr(pIndex, num); IntPtr zero = IntPtr.Zero; if (includeOutput) { num = SQLiteMarshal.NextOffsetOf(num, IntPtr.Size, IntPtr.Size); zero = SQLiteMarshal.ReadIntPtr(pIndex, num); } index = new SQLiteIndex(num1, num2); SQLiteIndexInputs inputs = index.Inputs; if (inputs == null) { return; } SQLiteIndexConstraint[] constraints = inputs.Constraints; if (constraints == null) { return; } SQLiteIndexOrderBy[] orderBys = inputs.OrderBys; if (orderBys == null) { return; } Type type = typeof(UnsafeNativeMethods.sqlite3_index_constraint); int num3 = Marshal.SizeOf(type); for (int i = 0; i < num1; i++) { IntPtr intPtr2 = SQLiteMarshal.IntPtrForOffset(intPtr, i * num3); UnsafeNativeMethods.sqlite3_index_constraint structure = (UnsafeNativeMethods.sqlite3_index_constraint)Marshal.PtrToStructure(intPtr2, type); constraints[i] = new SQLiteIndexConstraint(structure); } Type type1 = typeof(UnsafeNativeMethods.sqlite3_index_orderby); int num4 = Marshal.SizeOf(type1); for (int j = 0; j < num2; j++) { IntPtr intPtr3 = SQLiteMarshal.IntPtrForOffset(intPtr1, j * num4); UnsafeNativeMethods.sqlite3_index_orderby sqlite3IndexOrderby = (UnsafeNativeMethods.sqlite3_index_orderby)Marshal.PtrToStructure(intPtr3, type1); orderBys[j] = new SQLiteIndexOrderBy(sqlite3IndexOrderby); } if (includeOutput) { SQLiteIndexOutputs outputs = index.Outputs; if (outputs == null) { return; } SQLiteIndexConstraintUsage[] constraintUsages = outputs.ConstraintUsages; if (constraintUsages == null) { return; } Type type2 = typeof(UnsafeNativeMethods.sqlite3_index_constraint_usage); int num5 = Marshal.SizeOf(type2); for (int k = 0; k < num1; k++) { IntPtr intPtr4 = SQLiteMarshal.IntPtrForOffset(zero, k * num5); UnsafeNativeMethods.sqlite3_index_constraint_usage sqlite3IndexConstraintUsage = (UnsafeNativeMethods.sqlite3_index_constraint_usage)Marshal.PtrToStructure(intPtr4, type2); constraintUsages[k] = new SQLiteIndexConstraintUsage(sqlite3IndexConstraintUsage); } num = SQLiteMarshal.NextOffsetOf(num, IntPtr.Size, 4); outputs.IndexNumber = SQLiteMarshal.ReadInt32(pIndex, num); num = SQLiteMarshal.NextOffsetOf(num, 4, IntPtr.Size); outputs.IndexString = SQLiteString.StringFromUtf8IntPtr(SQLiteMarshal.ReadIntPtr(pIndex, num)); num = SQLiteMarshal.NextOffsetOf(num, IntPtr.Size, 4); outputs.NeedToFreeIndexString = SQLiteMarshal.ReadInt32(pIndex, num); num = SQLiteMarshal.NextOffsetOf(num, 4, 4); outputs.OrderByConsumed = SQLiteMarshal.ReadInt32(pIndex, num); num = SQLiteMarshal.NextOffsetOf(num, 4, 8); outputs.EstimatedCost = new double?(SQLiteMarshal.ReadDouble(pIndex, num)); num = SQLiteMarshal.NextOffsetOf(num, 8, 8); if (outputs.CanUseEstimatedRows()) { outputs.EstimatedRows = new long?(SQLiteMarshal.ReadInt64(pIndex, num)); } num = SQLiteMarshal.NextOffsetOf(num, 8, 4); if (outputs.CanUseIndexFlags()) { outputs.IndexFlags = new SQLiteIndexFlags?((SQLiteIndexFlags)SQLiteMarshal.ReadInt32(pIndex, num)); } num = SQLiteMarshal.NextOffsetOf(num, 4, 8); if (outputs.CanUseColumnsUsed()) { outputs.ColumnsUsed = new long?(SQLiteMarshal.ReadInt64(pIndex, num)); } } }