Exemplo n.º 1
0
        private MySqlSchemaCollection GetTable(string sql)
        {
            MySqlSchemaCollection mySqlSchemaCollection = new MySqlSchemaCollection();
            MySqlDataReader       mySqlDataReader       = new MySqlCommand(sql, this.connection).ExecuteReader();

            for (int i = 0; i < mySqlDataReader.FieldCount; i++)
            {
                mySqlSchemaCollection.AddColumn(mySqlDataReader.GetName(i), mySqlDataReader.GetFieldType(i));
            }
            using (mySqlDataReader)
            {
                while (mySqlDataReader.Read())
                {
                    MySqlSchemaRow mySqlSchemaRow = mySqlSchemaCollection.AddRow();
                    for (int j = 0; j < mySqlDataReader.FieldCount; j++)
                    {
                        mySqlSchemaRow[j] = mySqlDataReader.GetValue(j);
                    }
                }
            }
            return(mySqlSchemaCollection);
        }
Exemplo n.º 2
0
        protected MySqlSchemaCollection QueryCollection(string name, string sql)
        {
            MySqlSchemaCollection schemas = new MySqlSchemaCollection(name);
            MySqlDataReader       reader  = new MySqlCommand(sql, this.connection).ExecuteReader();

            for (int i = 0; i < reader.FieldCount; i++)
            {
                schemas.AddColumn(reader.GetName(i), reader.GetFieldType(i));
            }
            using (reader)
            {
                while (reader.Read())
                {
                    MySqlSchemaRow row = schemas.AddRow();
                    for (int j = 0; j < reader.FieldCount; j++)
                    {
                        row[j] = reader.GetValue(j);
                    }
                }
            }
            return(schemas);
        }
Exemplo n.º 3
0
        public static Dictionary<string, object>[] Select(string table, string where, string order, string limit, string fields)
        {
            if (!String.IsNullOrWhiteSpace(where))
            {
                where = " WHERE " + where;
            }

            if (!String.IsNullOrWhiteSpace(order))
            {
                order = " ORDER BY " + order;
            }

            if (!String.IsNullOrWhiteSpace(limit))
            {
                limit = " LIMIT " + limit;
            }

            string sql = "SELECT " + fields + " FROM `" + table + "`" + where + order + limit;

            lock (mySqlReaderLock)
            {
                using (MySqlDataReader resultSet = new MySqlCommand(sql, DefaultConnection()).ExecuteReader())
                {
                    List<Dictionary<string, object>> rtn = new List<Dictionary<string, object>>();

                    while (resultSet.Read())
                    {
                        Dictionary<string, object> row = new Dictionary<string, object>();
                        for (int j = 0; j < resultSet.FieldCount; j++)
                        {
                            row[resultSet.GetName(j)] = resultSet.GetValue(j);
                        }
                        rtn.Add(row);
                    }

                    return rtn.ToArray();
                }
            }
        }
Exemplo n.º 4
0
 internal static void InitCollections(MySqlConnection connection)
 {
     CharSetMap.defaultCollations = new Dictionary <string, string>();
     CharSetMap.maxLengths        = new Dictionary <string, int>();
     using (MySqlDataReader mySqlDataReader = new MySqlCommand("SHOW CHARSET", connection).ExecuteReader())
     {
         while (mySqlDataReader.Read())
         {
             CharSetMap.defaultCollations.Add(mySqlDataReader.GetString(0), mySqlDataReader.GetString(2));
             CharSetMap.maxLengths.Add(mySqlDataReader.GetString(0), Convert.ToInt32(mySqlDataReader.GetValue(3)));
         }
     }
 }