예제 #1
0
 private static void TraceCommandEnd(MySqlCommand command, string diagnostic)
 {
     if (_IsDebugTraceEnabled)
     {
         Debugging.Print($"MySql command ({command.GetHashCode()}) {diagnostic}");
     }
 }
예제 #2
0
 private static void TraceCommand(MySqlCommand command)
 {
     if (_IsDebugTraceEnabled)
     {
         Debugging.Print($"MySql command ({command.GetHashCode()}): {command.CommandText}");
     }
 }
예제 #3
0
        public void DoSelect()
        {
            Console.WriteLine($"{DateTime.Now:HH:mm:ss}, DoSelect({ThreadId}, {minWorkerId}, {maxWorkerId}, ct) started...");

            Random    rand  = new Random();
            Stopwatch watch = new Stopwatch();

            try
            {
                using (MySqlConnection conn = new MySqlConnection(Program.ConnectionString))
                {
                    Console.WriteLine($"DoSelect, THD={ThreadId}, MySqlConnection.GetHashCode()={conn.GetHashCode()}");
                    using (MySqlCommand cmd = new MySqlCommand(Program.SqlSelect, conn))
                    {
                        Console.WriteLine($"DoSelect, THD={ThreadId}, MySqlCommand.GetHashCode()={cmd.GetHashCode()}");
                        cmd.Parameters.Add("@P1", MySqlDbType.VarChar);

                        conn.Open();

                        bool moreToDo = true;
                        while (moreToDo)
                        {
                            if (!this.ct.IsCancellationRequested)
                            {
                                // 파라미터를 랜덤하게 생성
                                string p1     = string.Format($"W{rand.Next(minWorkerId, maxWorkerId):D5}");
                                int    result = 0;

                                cmd.Parameters["@P1"].Value = p1;

                                watch.Restart();
                                switch (this.dataSelectType)
                                {
                                case DataSelectType.DataAdapter:
                                    using (MySqlDataAdapter adapter = new MySqlDataAdapter(cmd))
                                    {
                                        DataSet dataSet = new DataSet();
                                        result = adapter.Fill(dataSet);
                                    }
                                    break;

                                case DataSelectType.DataReader:
                                    using (MySqlDataReader reader = cmd.ExecuteReader())
                                    {
                                        result = reader.HasRows ? 1 : 0;
                                    }
                                    break;
                                }
                                watch.Stop();

                                Interlocked.Increment(ref this.stats[ST_TYPE_COUNT]);
                                Interlocked.Add(ref this.stats[ST_TYPE_ELAPSED_MILLISECONDS], watch.ElapsedMilliseconds);
                            }
                            else
                            {
                                ct.ThrowIfCancellationRequested();
                            }
                        }
                    }
                }
            }
            catch (OperationCanceledException ex)
            {
                Console.WriteLine($"DoSelect(), {ex.Message}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"DoSelect(), ThreadId={ThreadId}, {ex.Message}");
            }
        }