public static object Execute(string commandText, SQLiteExecuteType executeType, CommandBehavior commandBehavior, string connectionString, params object[] args) { object obj; SQLiteConnection sQLiteConnection = null; try { if (connectionString == null) { connectionString = SQLiteCommand.DefaultConnectionString; } SQLiteConnection sQLiteConnection1 = new SQLiteConnection(connectionString); sQLiteConnection = sQLiteConnection1; using (sQLiteConnection1) { sQLiteConnection.Open(); using (SQLiteCommand sQLiteCommand = sQLiteConnection.CreateCommand()) { sQLiteCommand.CommandText = commandText; if (args != null) { object[] objArray = args; for (int i = 0; i < (int)objArray.Length; i++) { object obj1 = objArray[i]; SQLiteParameter sQLiteParameter = obj1 as SQLiteParameter; if (sQLiteParameter == null) { sQLiteParameter = sQLiteCommand.CreateParameter(); sQLiteParameter.DbType = DbType.Object; sQLiteParameter.Value = obj1; } sQLiteCommand.Parameters.Add(sQLiteParameter); } } switch (executeType) { case SQLiteExecuteType.None: { break; } case SQLiteExecuteType.NonQuery: { obj = sQLiteCommand.ExecuteNonQuery(commandBehavior); return(obj); } case SQLiteExecuteType.Scalar: { obj = sQLiteCommand.ExecuteScalar(commandBehavior); return(obj); } case SQLiteExecuteType.Reader: { bool flag = true; try { try { obj = sQLiteCommand.ExecuteReader(commandBehavior | CommandBehavior.CloseConnection); return(obj); } catch { flag = false; throw; } } finally { if (flag) { sQLiteConnection._noDispose = true; } } break; } default: { goto case SQLiteExecuteType.None; } } } } return(null); } finally { if (sQLiteConnection != null) { sQLiteConnection._noDispose = false; } } return(obj); }
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; } } }