Aegis.Data.MySQL.DBCommand.Query C# (CSharp) Method

Query() public method

public Query ( ) : MySqlDataReader
return MySql.Data.MySqlClient.MySqlDataReader
        public MySqlDataReader Query()
        {
            if (_dbConnector != null || Reader != null)
                throw new AegisException(AegisResult.DataReaderNotClosed, "There is already an open DataReader associated with this Connection which must be closed first.");

            _dbConnector = _pool.GetDBC();
            _command.Connection = _dbConnector.Connection;
            _command.CommandText = CommandText.ToString();

            Prepare();
            Reader = _command.ExecuteReader();
            _dbConnector.QPS.Add(1);

            return Reader;
        }

Same methods

DBCommand::Query ( string query ) : MySqlDataReader

Usage Example

Beispiel #1
0
        public static void Refresh()
        {
            String dbName = Starter.CustomData.GetValue("SystemDB/dbname");
            String dbHost = Starter.CustomData.GetValue("SystemDB/ipaddress");
            Int32 dbPort = Starter.CustomData.GetValue("SystemDB/portno").ToInt32();
            String userId = Starter.CustomData.GetValue("SystemDB/userid");
            String userPwd = Starter.CustomData.GetValue("SystemDB/userpwd");

            ConnectionPool systemDB = new ConnectionPool(dbHost, dbPort, "", dbName, userId, userPwd);
            using (DBCommand cmd = new DBCommand(systemDB))
            {
                cmd.CommandText.Append("select uid, worldid, dbtype, dbname, ipaddress, portno, userid, passwd");
                cmd.CommandText.Append(", charset, shardkey_start, shardkey_end");
                cmd.CommandText.Append(" from t_listdb;");
                MySqlDataReader reader = cmd.Query();

                while (reader.Read())
                {
                    DBInfo info = new DBInfo()
                    {
                        Uid = reader.GetInt32(0),
                        WorldId = reader.GetInt32(1),
                        DBType = (DBType)reader.GetInt32(2),
                        DBName = reader.GetString(3),
                        IPAddress = reader.GetString(4),
                        PortNo = reader.GetInt32(5),
                        UserId = reader.GetString(6),
                        UserPwd = reader.GetString(7),
                        CharSet = (reader.IsDBNull(8) == true ? "" : reader.GetString(8)),
                        ShardKeyStart = (reader.IsDBNull(9) == true ? 0 : reader.GetInt32(9)),
                        ShardKeyEnd = (reader.IsDBNull(10) == true ? 0 : reader.GetInt32(10))
                    };
                    Items.Add(info);

                    if (info.DBType == DBType.System)
                        SystemDB.Initialize(info);

                    else if (info.DBType == DBType.Auth)
                        AuthDB.Initialize(info);

                    else if (info.DBType == DBType.Game)
                        GameDB.AddDBInfo(info);
                }
            }
            systemDB.Release();
        }