예제 #1
0
        public IDatabaseMeta ReadMetaInfo()
        {
            AbstractDatabaseMeta meta = new DatabaseMeta(new TypeMap());

            var b = new OracleConnectionStringBuilder(_exe.Connection.ConnectionString);

            var dtTable = _exe.ExecuteQuery(string.Format("SELECT * FROM ALL_TABLES WHERE OWNER = '{0}'", b.UserID.ToUpper()));

            foreach (DataRow dr in dtTable.Rows)
            {
                string name = (string)dr["TABLE_NAME"];
                meta.AddTable(name);
            }

            DataTable dtColumn = _exe.ExecuteQuery(string.Format("SELECT * FROM ALL_TAB_COLUMNS WHERE OWNER = '{0}'", b.UserID.ToUpper()));
            string    sqlPK    = "SELECT * FROM user_cons_columns WHERE constraint_name IN (SELECT constraint_name FROM user_constraints WHERE Constraint_type='P') AND owner='{0}'";
            DataTable dtPK     = _exe.ExecuteQuery(string.Format(sqlPK, b.UserID.ToUpper()));

            foreach (DataRow dr in dtColumn.Rows)
            {
                string tblName  = (string)dr["TABLE_NAME"];
                string colName  = (string)dr["COLUMN_NAME"];
                bool   nullable = (string)dr["NULLABLE"] != "N";
                string dbType   = (string)dr["DATA_TYPE"];

                bool isPK = false;
                foreach (DataRow row in dtPK.Rows)
                {
                    if ((string)row["COLUMN_NAME"] == colName)
                    {
                        isPK = true;
                        break;
                    }
                }

                meta.AddColumn(tblName, colName, dbType, isPK, nullable, 0);//Extend: length
            }

            meta.Build();
            return(meta);
        }
예제 #2
0
파일: MetaQuery.cs 프로젝트: rexzh/RexToy
        public IDatabaseMeta ReadMetaInfo()
        {
            AbstractDatabaseMeta meta = new DatabaseMeta(new TypeMap());

            var b = new OracleConnectionStringBuilder(_exe.Connection.ConnectionString);

            var dtTable = _exe.ExecuteQuery(string.Format("SELECT * FROM ALL_TABLES WHERE OWNER = '{0}'", b.UserID.ToUpper()));
            foreach (DataRow dr in dtTable.Rows)
            {
                string name = (string)dr["TABLE_NAME"];
                meta.AddTable(name);
            }

            DataTable dtColumn = _exe.ExecuteQuery(string.Format("SELECT * FROM ALL_TAB_COLUMNS WHERE OWNER = '{0}'", b.UserID.ToUpper()));
            string sqlPK = "SELECT * FROM user_cons_columns WHERE constraint_name IN (SELECT constraint_name FROM user_constraints WHERE Constraint_type='P') AND owner='{0}'";
            DataTable dtPK = _exe.ExecuteQuery(string.Format(sqlPK, b.UserID.ToUpper()));

            foreach (DataRow dr in dtColumn.Rows)
            {
                string tblName = (string)dr["TABLE_NAME"];
                string colName = (string)dr["COLUMN_NAME"];
                bool nullable = (string)dr["NULLABLE"] != "N";
                string dbType = (string)dr["DATA_TYPE"];

                bool isPK = false;
                foreach (DataRow row in dtPK.Rows)
                {
                    if ((string)row["COLUMN_NAME"] == colName)
                    {
                        isPK = true;
                        break;
                    }
                }

                meta.AddColumn(tblName, colName, dbType, isPK, nullable, 0);//Extend: length
            }

            meta.Build();
            return meta;
        }