示例#1
0
        //POST GRES
        public static ArrayList GetListTables(string filter)
        {
            ArrayList list = new ArrayList();

            //PgSqlConnection connection = new PgSqlConnection(Session.ConnectionString);

            try
            {
                //connection.Open();

                DataTable dt = SqlHelperPostGres.ExecuteDataTable(Session.ConnectionString, CommandType.Text, "select * from information_schema.tables WHERE table_type = 'BASE TABLE' AND TABLE_SCHEMA = 'public'", null);

                foreach (DataRow dr in dt.Rows)
                {
                    list.Add(dr[2].ToString());
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                //if (connection.State == ConnectionState.Open)
                //    connection.Close();
            }

            return(list);
        }
示例#2
0
        public static DataTable GetSchema(string tableName, string columnNameParameter)
        {
            CustomBoolean.Clear();

            DataTable table = GetDatatableSchema();

            string    query   = string.Format("select * from information_schema.columns where table_name = '{0}' order by ordinal_position", tableName);
            DataTable columns = SqlHelperPostGres.ExecuteDataTable(Session.ConnectionString, CommandType.Text, query, null);

            foreach (DataRow dr in columns.Rows)
            {
                if (dr["table_name"].ToString().Equals(tableName))
                {
                    string newTableName = dr["table_name"].ToString().Trim();
                    string columnsName  = dr["column_name"].ToString().Trim();

                    bool isOk = true;
                    if (!columnNameParameter.Equals(string.Empty))
                    {
                        isOk = false;
                        if (columnNameParameter.Equals(columnsName))
                        {
                            isOk = true;
                        }
                    }

                    if (isOk)
                    {
                        string schema           = dr["table_schema"].ToString().Trim();
                        int    columnsMaxLength = dr["character_octet_length"].ToString().Trim().Equals(string.Empty) ? 0 : Int32.Parse(dr["character_octet_length"].ToString().Trim());
                        bool   columnsNullable  = dr["is_nullable"].ToString().Trim().ToUpper().StartsWith("True") ? true : false;
                        string columnsType      = GetType(columnsName, dr["udt_name"].ToString().Trim(), columnsMaxLength, columnsNullable).Trim();
                        string columnsDBType    = GetType(columnsName, dr["udt_name"].ToString().Trim(), columnsMaxLength, columnsNullable).Trim();

                        string businessName = dr["column_name"].ToString().Trim();
                        string description  = string.Empty;
                        if (!businessName.Equals(string.Empty))
                        {
                            if (businessName.Contains("-"))
                            {
                                string[] array = businessName.Split('-');
                                businessName = array[0].Trim();
                                description  = array[1].Trim();
                            }
                        }

                        DataRow row = table.NewRow();
                        row["Name"]         = columnsName;
                        row["FieldName"]    = columnsName;
                        row["Type"]         = columnsType;
                        row["DbType"]       = columnsDBType;
                        row["Length"]       = columnsMaxLength;
                        row["Nullable"]     = columnsNullable;
                        row["Table"]        = newTableName;
                        row["Schema"]       = schema;
                        row["BusinessName"] = businessName;
                        row["Description"]  = description;

                        table.Rows.Add(row);
                    }
                }
            }
            return(table);
        }