internal static bool ResetConnection(SQLiteConnectionHandle hdl, IntPtr db, bool canThrow) { SQLiteErrorCode sQLiteErrorCode; if (hdl == null || db == IntPtr.Zero) { return(false); } bool flag = false; try { } finally { lock (hdl) { if (canThrow && hdl.IsInvalid) { throw new InvalidOperationException("The connection handle is invalid."); } if (canThrow && hdl.IsClosed) { throw new InvalidOperationException("The connection handle is closed."); } if (!hdl.IsInvalid && !hdl.IsClosed) { IntPtr zero = IntPtr.Zero; do { zero = UnsafeNativeMethods.sqlite3_next_stmt(db, zero); if (zero == IntPtr.Zero) { continue; } sQLiteErrorCode = UnsafeNativeMethods.sqlite3_reset_interop(zero); }while (zero != IntPtr.Zero); if (!SQLiteBase.IsAutocommit(hdl, db)) { sQLiteErrorCode = UnsafeNativeMethods.sqlite3_exec(db, SQLiteConvert.ToUTF8("ROLLBACK"), IntPtr.Zero, IntPtr.Zero, ref zero); if (sQLiteErrorCode == SQLiteErrorCode.Ok) { flag = true; } else if (canThrow) { throw new SQLiteException(sQLiteErrorCode, SQLiteBase.GetLastError(hdl, db)); } } else { flag = true; } } } } GC.KeepAlive(hdl); return(flag); }
public byte[] ToUTF8(DateTime dateTimeValue) { return(SQLiteConvert.ToUTF8(this.ToString(dateTimeValue))); }
internal override void Open(string strFilename, string vfsName, SQLiteConnectionFlags connectionFlags, SQLiteOpenFlagsEnum openFlags, int maxPoolSize, bool usePool) { SQLiteErrorCode sQLiteErrorCode; if (this._sql != null) { this.Close(true); } if (this._sql != null) { throw new SQLiteException("connection handle is still active"); } this._usePool = usePool; this._fileName = strFilename; this._flags = connectionFlags; if (usePool) { this._sql = SQLiteConnectionPool.Remove(strFilename, maxPoolSize, out this._poolVersion); SQLiteConnectionHandle sQLiteConnectionHandle = this._sql; object[] objArray = new object[] { typeof(SQLite3_UTF16), strFilename, vfsName, connectionFlags, openFlags, maxPoolSize, usePool, this._poolVersion }; SQLiteConnection.OnChanged(null, new ConnectionEventArgs(SQLiteConnectionEventType.OpenedFromPool, null, null, null, null, sQLiteConnectionHandle, strFilename, objArray)); } if (this._sql == null) { try { } finally { IntPtr zero = IntPtr.Zero; int num = ((connectionFlags & SQLiteConnectionFlags.NoExtensionFunctions) != SQLiteConnectionFlags.NoExtensionFunctions ? 1 : 0); if (vfsName != null || num != 0) { sQLiteErrorCode = UnsafeNativeMethods.sqlite3_open16_interop(SQLiteConvert.ToUTF8(strFilename), SQLiteConvert.ToUTF8(vfsName), openFlags, num, ref zero); } else { if ((openFlags & SQLiteOpenFlagsEnum.Create) != SQLiteOpenFlagsEnum.Create && !File.Exists(strFilename)) { throw new SQLiteException(SQLiteErrorCode.CantOpen, strFilename); } if (vfsName != null) { CultureInfo currentCulture = CultureInfo.CurrentCulture; object[] objArray1 = new object[] { vfsName }; throw new SQLiteException(SQLiteErrorCode.CantOpen, HelperMethods.StringFormat(currentCulture, "cannot open using UTF-16 and VFS \"{0}\": need interop assembly", objArray1)); } sQLiteErrorCode = UnsafeNativeMethods.sqlite3_open16(strFilename, ref zero); } if (sQLiteErrorCode != SQLiteErrorCode.Ok) { throw new SQLiteException(sQLiteErrorCode, null); } this._sql = new SQLiteConnectionHandle(zero, true); } lock (this._sql) { } SQLiteConnectionHandle sQLiteConnectionHandle1 = this._sql; object[] objArray2 = new object[] { typeof(SQLite3_UTF16), strFilename, vfsName, connectionFlags, openFlags, maxPoolSize, usePool }; SQLiteConnection.OnChanged(null, new ConnectionEventArgs(SQLiteConnectionEventType.NewCriticalHandle, null, null, null, null, sQLiteConnectionHandle1, strFilename, objArray2)); } if ((connectionFlags & SQLiteConnectionFlags.NoBindFunctions) != SQLiteConnectionFlags.NoBindFunctions) { if (this._functions == null) { this._functions = new Dictionary <SQLiteFunctionAttribute, SQLiteFunction>(); } foreach (KeyValuePair <SQLiteFunctionAttribute, SQLiteFunction> value in SQLiteFunction.BindFunctions(this, connectionFlags)) { this._functions[value.Key] = value.Value; } } this.SetTimeout(0); GC.KeepAlive(this._sql); }
public static SQLiteBlob Create(SQLiteDataReader dataReader, int i, bool readOnly) { SQLiteConnection connection = SQLiteDataReader.GetConnection(dataReader); if (connection == null) { throw new InvalidOperationException("Connection not available"); } SQLite3 sQLite3 = connection._sql as SQLite3; if (sQLite3 == null) { throw new InvalidOperationException("Connection has no wrapper"); } SQLiteConnectionHandle sQLiteConnectionHandle = sQLite3._sql; if (sQLiteConnectionHandle == null) { throw new InvalidOperationException("Connection has an invalid handle."); } long?rowId = dataReader.GetRowId(i); if (!rowId.HasValue) { throw new InvalidOperationException("No RowId is available"); } SQLiteBlobHandle sQLiteBlobHandle = null; try { } finally { IntPtr zero = IntPtr.Zero; SQLiteErrorCode sQLiteErrorCode = UnsafeNativeMethods.sqlite3_blob_open(sQLiteConnectionHandle, SQLiteConvert.ToUTF8(dataReader.GetDatabaseName(i)), SQLiteConvert.ToUTF8(dataReader.GetTableName(i)), SQLiteConvert.ToUTF8(dataReader.GetName(i)), rowId.Value, (readOnly ? 0 : 1), ref zero); if (sQLiteErrorCode != SQLiteErrorCode.Ok) { throw new SQLiteException(sQLiteErrorCode, null); } sQLiteBlobHandle = new SQLiteBlobHandle(sQLiteConnectionHandle, zero); } object[] objArray = new object[] { typeof(SQLiteBlob), dataReader, i, readOnly }; SQLiteConnection.OnChanged(null, new ConnectionEventArgs(SQLiteConnectionEventType.NewCriticalHandle, null, null, null, dataReader, sQLiteBlobHandle, null, objArray)); return(new SQLiteBlob(sQLite3, sQLiteBlobHandle)); }