public static OldDataPack GetPack(String packname) { if (!datas.ContainsKey(packname)) { OldDataPack data = MysqlService.GetAllData(packname); datas.Add(packname, data); } return(datas[packname]); }
public static OldDataPack GetAllData(string tablename) { MySqlConnection conn = new MySqlConnection(linker); conn.Open(); MySqlCommand command = new MySqlCommand(String.Format("SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '{0}' AND TABLE_SCHEMA = '{1}'", tablename, database), conn); MySqlDataReader reader = command.ExecuteReader(); OldDataPack pack = new OldDataPack(tablename); while (reader.Read()) { pack.header.Add(reader.GetString(0)); pack.datatype.Add(reader.GetString(1)); pack.datasize.Add(reader.IsDBNull(2) ? 0 : reader.GetInt32(2)); pack.comment.Add(reader.GetString(3)); } reader.Close(); command = new MySqlCommand(String.Format("SELECT * FROM `{0}` ORDER BY `{1}`", tablename, pack.header[0]), conn); reader = command.ExecuteReader(); while (reader.Read()) { List <String> item = new List <string>(); for (int i = 0; i < reader.FieldCount; i++) { item.Add(reader.GetString(i)); } int id = int.Parse(item[0]); pack.maxid = Math.Max(pack.maxid, id); pack.data.Add(id, item); } conn.Close(); pack.cachTime = DateTime.Now; return(pack); }