示例#1
0
        /// <summary>
        /// Método que retorna uma lista de tabelas e suas descrições
        /// </summary>
        /// <returns></returns>
        public static void RetornaDetalhesCampos(Visao.BarraDeCarregamento barra, ref List <Model.Campo> campos)
        {
            string sentenca = @"SELECT case
                                            when OBJECTPROPERTY(OBJECT_ID(constraint_name), 'IsPrimaryKey') = 1 then '1'
                                            else '0' 
                                        end as primarykey, 
                                        case
		                                    when OBJECTPROPERTY(OBJECT_ID(constraint_name), 'IsUniqueCnst') = 1 then '1'
		                                    else '0' 
		                                end as isunique,
                                        c.*
                                FROM information_schema.COLUMNS c 
                                LEFT join INFORMATION_SCHEMA.KEY_COLUMN_USAGE pk 
                                on (c.COLUMN_NAME = pk.COLUMN_NAME and c.TABLE_NAME = pk.TABLE_NAME)";

            DbDataReader reader = DataBase.Connection.Select(sentenca);

            while (reader.Read())
            {
                barra.AvancaBarra(1);

                string nome         = reader["COLUMN_NAME"].ToString();
                bool   notnull      = reader["IS_NULLABLE"].ToString().ToUpper().Equals("YES");
                string tipo         = reader["DATA_TYPE"].ToString();
                string valueDefault = reader["COLUMN_DEFAULT"].ToString().Replace('(', ' ').Replace(')', ' ').Trim();
                bool   primarykey   = reader["primarykey"].ToString().Equals("1");
                bool   unique       = reader["isunique"].ToString().Equals("1");
                string tamanho      = reader["CHARACTER_MAXIMUM_LENGTH"].ToString();
                string precisao     = reader["NUMERIC_PRECISION"].ToString();
                string tabela       = reader["TABLE_NAME"].ToString();

                Model.Campo c = new Model.Campo();
                c.Name_Field   = nome;
                c.NotNull      = notnull;
                c.Type         = tipo;
                c.ValueDefault = valueDefault;
                c.PrimaryKey   = primarykey;
                c.Unique       = unique;
                c.Size         = string.IsNullOrEmpty(tamanho) ? 0 : int.Parse(tamanho);
                c.Precision    = string.IsNullOrEmpty(precisao) ? decimal.Zero : decimal.Parse(precisao);
                c.Tabela       = tabela;

                campos.Add(c);
            }
            reader.Close();
        }
示例#2
0
        /// <summary>
        /// Método que retorna uma lista de tabelas e suas descrições
        /// </summary>
        /// <returns></returns>
        public static void RetornaDetalhesCampos(Visao.BarraDeCarregamento barra, List <DAO.MDN_Table> tabelas, ref List <Model.Campo> campos)
        {
            foreach (DAO.MDN_Table table in tabelas)
            {
                string sentenca = "PRAGMA table_info('" + table.Table_Name + "')";

                DbDataReader reader = DataBase.Connection.Select(sentenca);

                while (reader.Read())
                {
                    barra.AvancaBarra(1);
                    string nome         = reader["name"].ToString();
                    bool   notnull      = reader["notnull"].ToString().Equals("1");
                    string tipo         = reader["type"].ToString();
                    string valueDefault = reader["dflt_value"].ToString();
                    bool   primarykey   = reader["pk"].ToString().Equals("1");
                    bool   unique       = false;
                    string tamanho      = "0";
                    string precisao     = "0";
                    string tabela       = table.Table_Name;

                    PreencheTipoTamanhoPrecisao(ref tipo, ref tamanho, ref precisao);

                    Model.Campo c = new Model.Campo();
                    c.Name_Field   = nome;
                    c.NotNull      = notnull;
                    c.Type         = tipo;
                    c.ValueDefault = valueDefault;
                    c.PrimaryKey   = primarykey;
                    c.Unique       = unique;
                    c.Size         = string.IsNullOrEmpty(tamanho) ? 0 : int.Parse(tamanho);
                    c.Precision    = string.IsNullOrEmpty(precisao) ? decimal.Zero : decimal.Parse(precisao);
                    c.Tabela       = tabela;

                    campos.Add(c);
                }
                reader.Close();
            }
        }
示例#3
0
        /// <summary>
        /// Método que retorna uma lista de tabelas e suas descrições
        /// </summary>
        /// <returns></returns>
        public static void RetornaDetalhesCampos(Visao.BarraDeCarregamento barra, ref List <Model.Campo> campos)
        {
            Util.CL_Files.WriteOnTheLog("Iniciando RetornaDetalhesCampos", Global.TipoLog.SIMPLES);

            if (File.Exists(Global.app_exportacao_campos_file))
            {
                File.Delete(Global.app_exportacao_campos_file);
            }

            string sentenca = @"SELECT
                                   col.COLUMN_NAME,
                                   col.DATA_TYPE,
                                   col.NULLABLE,
                                   '' AS DATA_DEFAULT,
                                   case
                                       when allCons.CONSTRAINT_TYPE = 'P' then
                                         '1'
                                       else '0'
                                   end primarykey,
                                   case
                                       when allCons.CONSTRAINT_TYPE = 'U' then
                                         '1'
                                       else '0'
                                   end isunique,
                                   col.DATA_LENGTH,
                                   col.DATA_PRECISION,
                                   col.TABLE_NAME,
                                   COMM.COMMENTS
                               FROM all_tab_columns col
                               LEFT JOIN ALL_COL_COMMENTS COMM ON (col.COLUMN_NAME = COMM.COLUMN_NAME AND col.TABLE_NAME = COMM.TABLE_NAME)
                               LEFT JOIN all_cons_columns consCol on (col.COLUMN_NAME = consCol.COLUMN_NAME)
                               LEFT JOIN all_constraints allCons on (consCol.CONSTRAINT_NAME = allCons.CONSTRAINT_NAME)
                               WHERE(NOT col.TABLE_NAME LIKE '%$%') AND(NOT col.TABLE_NAME LIKE '%LOGMNR%')";

            DbDataReader reader = DataBase.Connection.Select(sentenca);
            DataTable    table  = new DataTable();

            table.Load(reader);
            Util.CL_Files.WriteOnTheLog("Rodou consulta. Resultados: " + table.Rows.Count, Global.TipoLog.SIMPLES);
            reader.Close();
            Util.CL_Files.WriteOnTheLog("Fechou conexão", Global.TipoLog.SIMPLES);

            foreach (DataRow row in table.Rows)
            {
                barra.AvancaBarra(1);

                string nome         = row["COLUMN_NAME"].ToString();
                bool   notnull      = row["NULLABLE"].ToString().ToUpper().Equals("YES");
                string tipo         = row["DATA_TYPE"].ToString();
                string valueDefault = row["DATA_DEFAULT"].ToString();
                bool   primarykey   = row["primarykey"].ToString().Equals("1");
                bool   unique       = row["isunique"].ToString().Equals("1");
                string tamanho      = row["DATA_LENGTH"].ToString();
                string precisao     = row["DATA_PRECISION"].ToString();
                string tabela       = row["TABLE_NAME"].ToString();
                string comments     = row["COMMENTS"].ToString();

                Model.Campo c = new Model.Campo();
                c.Name_Field   = nome;
                c.NotNull      = notnull;
                c.Type         = tipo;
                c.ValueDefault = valueDefault;
                c.PrimaryKey   = primarykey;
                c.Unique       = unique;
                c.Size         = string.IsNullOrEmpty(tamanho) ? 0 : int.Parse(tamanho);
                c.Precision    = string.IsNullOrEmpty(precisao) ? decimal.Zero : decimal.Parse(precisao);
                c.Tabela       = tabela;
                c.Comments     = comments;

                campos.Add(c);
            }
        }