private void InvokeBindValueCallback(int index, SQLiteParameter parameter, out bool complete) { SQLiteTypeCallbacks sQLiteTypeCallback; complete = false; SQLiteConnectionFlags sQLiteConnectionFlag = this._flags; SQLiteStatement sQLiteStatement = this; sQLiteStatement._flags = sQLiteStatement._flags & (SQLiteConnectionFlags.LogPrepare | SQLiteConnectionFlags.LogPreBind | SQLiteConnectionFlags.LogBind | SQLiteConnectionFlags.LogCallbackException | SQLiteConnectionFlags.LogBackup | SQLiteConnectionFlags.NoExtensionFunctions | SQLiteConnectionFlags.BindUInt32AsInt64 | SQLiteConnectionFlags.BindAllAsText | SQLiteConnectionFlags.GetAllAsText | SQLiteConnectionFlags.NoLoadExtension | SQLiteConnectionFlags.NoCreateModule | SQLiteConnectionFlags.NoBindFunctions | SQLiteConnectionFlags.NoLogModule | SQLiteConnectionFlags.LogModuleError | SQLiteConnectionFlags.LogModuleException | SQLiteConnectionFlags.TraceWarning | SQLiteConnectionFlags.ConvertInvariantText | SQLiteConnectionFlags.BindInvariantText | SQLiteConnectionFlags.NoConnectionPool | SQLiteConnectionFlags.UseConnectionPool | SQLiteConnectionFlags.UseConnectionTypes | SQLiteConnectionFlags.NoGlobalTypes | SQLiteConnectionFlags.StickyHasRows | SQLiteConnectionFlags.StrictEnlistment | SQLiteConnectionFlags.MapIsolationLevels | SQLiteConnectionFlags.DetectTextAffinity | SQLiteConnectionFlags.DetectStringType | SQLiteConnectionFlags.NoConvertSettings | SQLiteConnectionFlags.BindDateTimeWithKind | SQLiteConnectionFlags.RollbackOnException | SQLiteConnectionFlags.DenyOnException | SQLiteConnectionFlags.InterruptOnException | SQLiteConnectionFlags.UnbindFunctionsOnClose | SQLiteConnectionFlags.NoVerifyTextAffinity | SQLiteConnectionFlags.UseConnectionReadValueCallbacks | SQLiteConnectionFlags.UseParameterNameForTypeName | SQLiteConnectionFlags.UseParameterDbTypeForTypeName | SQLiteConnectionFlags.NoVerifyTypeAffinity | SQLiteConnectionFlags.AllowNestedTransactions | SQLiteConnectionFlags.BindDecimalAsText | SQLiteConnectionFlags.GetDecimalAsText | SQLiteConnectionFlags.BindInvariantDecimal | SQLiteConnectionFlags.GetInvariantDecimal | SQLiteConnectionFlags.BindAndGetAllAsText | SQLiteConnectionFlags.ConvertAndBindInvariantText | SQLiteConnectionFlags.BindAndGetAllAsInvariantText | SQLiteConnectionFlags.ConvertAndBindAndGetAllAsInvariantText | SQLiteConnectionFlags.UseParameterAnythingForTypeName | SQLiteConnectionFlags.LogAll | SQLiteConnectionFlags.LogDefault | SQLiteConnectionFlags.Default | SQLiteConnectionFlags.DefaultAndLogAll); try { if (parameter != null) { SQLiteConnection connection = SQLiteStatement.GetConnection(this); if (connection != null) { string typeName = parameter.TypeName; if (typeName == null && (this._flags & SQLiteConnectionFlags.UseParameterNameForTypeName) == SQLiteConnectionFlags.UseParameterNameForTypeName) { typeName = parameter.ParameterName; } if (typeName == null && (this._flags & SQLiteConnectionFlags.UseParameterDbTypeForTypeName) == SQLiteConnectionFlags.UseParameterDbTypeForTypeName) { typeName = SQLiteConvert.DbTypeToTypeName(connection, parameter.DbType, this._flags); } if (typeName != null) { if (connection.TryGetTypeCallbacks(typeName, out sQLiteTypeCallback) && sQLiteTypeCallback != null) { SQLiteBindValueCallback bindValueCallback = sQLiteTypeCallback.BindValueCallback; if (bindValueCallback != null) { object bindValueUserData = sQLiteTypeCallback.BindValueUserData; bindValueCallback(this._sql, this._command, sQLiteConnectionFlag, parameter, typeName, index, bindValueUserData, out complete); } } } } } } finally { this._flags |= SQLiteConnectionFlags.UseConnectionBindValueCallbacks; } }
/// <summary> /// Turn a datatable into a table in the temporary database for the connection /// </summary> /// <param name="cnn">The connection to make the temporary table in</param> /// <param name="table">The table to write out</param> /// <param name="dest">The temporary table name to write to</param> private void DataTableToTable(SQLiteConnection cnn, DataTable table, string dest) { StringBuilder sql = new StringBuilder(); SQLiteCommandBuilder builder = new SQLiteCommandBuilder(); using (SQLiteCommand cmd = cnn.CreateCommand()) using (DataTable source = new DataTable()) { sql.AppendFormat(CultureInfo.InvariantCulture, "CREATE TEMP TABLE {0} (", builder.QuoteIdentifier(dest)); string separator = String.Empty; SQLiteConnectionFlags flags = cnn.Flags; foreach (DataColumn dc in table.Columns) { DbType dbtypeName = SQLiteConvert.TypeToDbType(dc.DataType); string typeName = SQLiteConvert.DbTypeToTypeName(cnn, dbtypeName, flags); sql.AppendFormat(CultureInfo.InvariantCulture, "{2}{0} {1} COLLATE NOCASE", builder.QuoteIdentifier(dc.ColumnName), typeName, separator); separator = ", "; } sql.Append(")"); cmd.CommandText = sql.ToString(); cmd.ExecuteNonQuery(); cmd.CommandText = String.Format("SELECT * FROM TEMP.{0} WHERE 1=2", builder.QuoteIdentifier(dest)); using (SQLiteDataAdapter adp = new SQLiteDataAdapter(cmd)) { builder.DataAdapter = adp; adp.Fill(source); foreach (DataRow row in table.Rows) { object[] arr = row.ItemArray; source.Rows.Add(arr); } adp.Update(source); } } }