Beispiel #1
0
        public TableDefinition[] generate(
            string host,
            string database,
            string tableOwner,
            string user,
            string pwd,
            bool generateAll)
        {
            OL.setConnection(host, database, user, pwd);

            ITransaction trx = OL.Instance.BeginTransaction();

            Criterion crit = new CriterionEqual("table_owner", tableOwner);

            if (!generateAll)
            {
                crit = new CriterionAnd(
                    crit,
                    new CriterionEqual("table_type", "T"));
            }

            List <object> tables = trx.Load(
                typeof(PGTable),
                new CriterionAnd(
                    new CriterionEqual("t.schemaname", "public"),
                    new CriterionText("t.tablename=c.relname")));

            List <TableDefinition> defs = new List <TableDefinition>();

            foreach (PGTable t in tables)
            {
                TableDefinition def = new TableDefinition();
                def.table = map(t);

                /*
                 * List<object> idx = trx.Load(
                 *  typeof(PGIndex),
                 *  new CriterionAnd(
                 *      new CriterionEqual("indrelid", t.oid),
                 *      new CriterionEqual("indisprimary", "t")));
                 */
                def.columns = trx.Load(
                    typeof(PGColumn),
                    new CriterionAnd(
                        new CriterionGreaterThan("attnum", 0),
                        new CriterionEqual("t.oid", t.oid)),
                    "attnum")
                              .ConvertAll <Column>(
                    new Converter <object, Column>(
                        delegate(object o) { return(map((PGColumn)o)); }))
                              .ToArray();

                defs.Add(def);
            }

            trx.Commit();

            return(defs.ToArray());
        }
Beispiel #2
0
        public TableDefinition[] generate(
            string host,
            string database,
            string tableOwner,
            string user,
            string pwd,
            bool generateAll)
        {
            OL.setConnection(host, database, user, pwd);

            ITransaction trx = OL.Instance.BeginTransaction();

            Criterion crit = new CriterionEqual("table_owner", tableOwner);

            if (!generateAll)
            {
                crit = new CriterionAnd(
                    crit,
                    new CriterionEqual("table_type", "T"));
            }

            List <object> tables = trx.Load(
                typeof(IITable),
                crit);

            List <TableDefinition> defs = new List <TableDefinition>();

            foreach (IITable t in tables)
            {
                TableDefinition def = new TableDefinition();
                def.table = map(t);

                def.columns = trx.Load(
                    typeof(IIColumn),
                    new CriterionEqual("table_name", t.table_name),
                    "column_sequence")
                              .ConvertAll <Column>(
                    new Converter <object, Column>(
                        delegate(object o) { return(map((IIColumn)o)); }))
                              .ToArray();

                defs.Add(def);
            }

            trx.Commit();

            return(defs.ToArray());
        }