Esempio n. 1
0
        public static List <DbColumnMetadata> GetTableMetadataFromMySqlDictionary(
            DbConnectionMx conn,
            string schema,
            string tableName)
        {
            string sql = String.Format(
                @"SELECT *
			  FROM INFORMATION_SCHEMA.COLUMNS
				WHERE 
           table_schema = '{0}' 
           AND table_name = '{1}'
				ORDER BY ORDINAL_POSITION"                ,
                schema, tableName);

            DbCommandMx drd = new DbCommandMx();

            drd.MxConn = conn;
            drd.PrepareUsingDefinedConnection(sql);
            DbDataReader rdr = drd.ExecuteReader();

            List <DbColumnMetadata> md = new List <DbColumnMetadata>();

            while (rdr.Read())
            {
                DbColumnMetadata cmd = new DbColumnMetadata();
                cmd.Name      = drd.GetStringByName("column_name");
                cmd.Type      = drd.GetStringByName("data_type");
                cmd.Length    = drd.GetLongByName("character_maximum_length");
                cmd.Precision = drd.GetIntByName("numeric_precision");
                cmd.Scale     = drd.GetIntByName("numeric_scale");
                cmd.Nullable  = drd.GetStringByName("is_nullable");
                cmd.Comment   = drd.GetStringByName("column_comment");

                md.Add(cmd);
            }

            rdr.Close();
            return(md);
        }