コード例 #1
0
        }//ProcessQuery()

        //
        private void ProcessWriteQuery(Queries.QueryBase query, MySqlConnection mySqlConnection)
        {
            try
            {
                string cmdString = query.GetQuery(m_Database);
                Log.NewEntry(LogLevel.Minor, "ProcessQuery: {0}", cmdString);
                if (string.IsNullOrEmpty(cmdString))
                {
                    Log.NewEntry(LogLevel.Major, "ProcessQuery: Query provided is empty.");
                    query.Status = Queries.QueryStatus.Failed;
                    OnQueryResponse((EventArgs)query);
                }
                MySqlCommand cmd   = new MySqlCommand(cmdString, mySqlConnection);
                int          nRows = cmd.ExecuteNonQuery();

                query.Status = Queries.QueryStatus.Completed;
            }
            catch (Exception e)
            {
                Log.NewEntry(LogLevel.Major, "ProcessQuery: {1} exception: {0}", e.Message, query);
                query.ErrorMessage = e.Message;
                query.Status       = Queries.QueryStatus.Failed;
            }
            //
            // This is complete.  Push onto the queue.
            //
            this.HubEventEnqueue(query);
        }//ProcessQuery()
コード例 #2
0
        }//HubEventHandler()

        //
        //
        // *************************************************
        // ****         ProcessQuery(iQuery)            ****
        // *************************************************
        private void ProcessReadQuery(Queries.QueryBase query)
        {
            MySqlConnection mySqlConnection = null;

            // Try to connect
            if (!m_Database.IsTryToConnect(ref mySqlConnection))
            {   // Failed to connect.
                Log.NewEntry(LogLevel.Major, "ProcessQuery: Failed to connect to {0}.", m_Database);
                query.Status = Queries.QueryStatus.Failed;
                OnQueryResponse((EventArgs)query);
            }

            //
            MySqlDataReader reader = null;

            try
            {
                string cmdString = query.GetQuery(m_Database);
                Log.NewEntry(LogLevel.Minor, "ProcessQuery: {0}", cmdString);
                if (string.IsNullOrEmpty(cmdString))
                {
                    Log.NewEntry(LogLevel.Major, "ProcessQuery: Query provided is empty.");
                    query.Status = Queries.QueryStatus.Failed;
                    OnQueryResponse((EventArgs)query);
                }
                MySqlCommand cmd = new MySqlCommand(cmdString, mySqlConnection);

                reader = cmd.ExecuteReader();
                int           fieldCount = reader.FieldCount;
                List <string> fieldNames = new List <string>();     // place to store column names
                List <object> values     = new List <object>();     // place to store values.  Count will be (fieldCount * nRows)
                for (int i = 0; i < fieldCount; ++i)
                {
                    fieldNames.Add(reader.GetName(i));
                }
                while (reader.Read())
                {     // Reading the next row
                    for (int i = 0; i < fieldCount; ++i)
                    { // Read the ith column in this row.
                        if (reader.IsDBNull(i))
                        {
                            values.Add(null);
                            continue;
                        }
                        Type type = reader.GetFieldType(i);
                        if (type == typeof(int))
                        {
                            values.Add(reader.GetInt32(i));
                        }
                        else if (type == typeof(double))
                        {
                            values.Add(reader.GetDouble(i));
                        }
                        else
                        {
                            object o = reader.GetValue(i);
                            values.Add(o);
                        }
                    }//next ith column.
                }
                // Give the data to the query.
                query.Status = query.AcceptData(m_Database, values, fieldNames);
            }
            catch (Exception e)
            {
                Log.NewEntry(LogLevel.Major, "ProcessQuery: {1} exception: {0}", e.Message, query);
                query.ErrorMessage = e.Message;
                query.Status       = Queries.QueryStatus.Failed;
            }
            if (reader != null && reader.IsClosed == false)
            {
                try
                {
                    reader.Close();
                }
                catch (Exception e)
                {
                    Log.NewEntry(LogLevel.Major, "ProcessQuery: Closing reader {1} exception: {0}", e.Message, query);
                }
            }
            if (mySqlConnection != null)
            {
                mySqlConnection.Close();
            }

            //
            // This is complete.  Push onto the queue.
            //
            this.HubEventEnqueue(query);
        }//ProcessQuery()