IncreaseQueries() public method

public IncreaseQueries ( ulong queries ) : void
queries ulong
return void
示例#1
0
        internal long InsertRow(MySqlCommand mysqlCommand, string database, string table, bool onDuplicateUpdate, params ParameterData[] parameterData)
        {
            DebugOutput("InsertRow", "Database " + database + " table " + table + " data " + string.Join(", ", parameterData.ToList()));

            logData.IncreaseQueries(1);

            mysqlCommand.CommandText = "INSERT INTO `" + database + "`.`" + table + "` (`" + string.Join("`,`", parameterData.Select(n => n.parameterName)) + "`) VALUES (" + string.Join(",", parameterData.Select(n => "@" + n.parameterName)) + ")";

            if (onDuplicateUpdate)
            {
                mysqlCommand.CommandText += " ON DUPLICATE KEY UPDATE `" + string.Join(", `", parameterData.Select(n => n.parameterName + "`=@" + n.parameterName));
            }

            mysqlCommand.Parameters.AddRange(parameterData.Select(n => n.GetMysqlParameter()).ToArray());

            logData.IncreaseUpdates((ulong)mysqlCommand.ExecuteNonQuery());

            mysqlCommand.Parameters.Clear();

            return(mysqlCommand.LastInsertedId);
        }
示例#2
0
        internal long BulkSend(MySqlCommand mysqlCommand, string database, string table, DataTable dataTable, bool onDuplicateUpdate, int updateBatchSize, bool continueUpdateOnError)
        {
            try
            {
                IEnumerable <string> columnNames = dataTable.Columns.Cast <DataColumn>().Select(n => n.ColumnName);

                DebugOutput("BulkSend", string.Format("Database {0} Table {1} Columns {2}", database, table, string.Join(", ", columnNames)));

                logData.IncreaseQueries(1);

                mysqlCommand.Parameters.AddRange(columnNames.Select(n => new MySqlParameter()
                {
                    ParameterName = "@" + n, SourceColumn = n
                }).ToArray());

                mysqlCommand.CommandText = "INSERT INTO `" + database + "`.`" + table + "` (`" + string.Join("`,`", columnNames) + "`) VALUES (" + string.Join(",", columnNames.Select(n => "@" + n)) + ") ";

                if (onDuplicateUpdate)
                {
                    mysqlCommand.CommandText += "ON DUPLICATE KEY UPDATE `" + string.Join(", `", columnNames.Select(n => n + "`=@" + n));
                }

                mysqlCommand.CommandType      = CommandType.Text;
                mysqlCommand.UpdatedRowSource = UpdateRowSource.None;

                using (MySqlDataAdapter adapter = new MySqlDataAdapter())
                {
                    adapter.ContinueUpdateOnError = continueUpdateOnError;
                    adapter.InsertCommand         = mysqlCommand;
                    adapter.UpdateBatchSize       = updateBatchSize;
                    long l = adapter.Update(dataTable);
                    logData.IncreaseUpdates((ulong)l);
                    return(l);
                }
            }
            finally
            {
                mysqlCommand.Parameters.Clear();
            }
        }