Exemplo n.º 1
0
        public void PqsqlDataReaderTest1()
        {
            // TODO we don't support xid and inet datatypes yet
            mCmd.CommandText = "select datid,datname,pid,application_name,backend_start,query from pg_stat_activity";
            PqsqlDataReader reader = mCmd.ExecuteReader();

            Assert.AreEqual(false, reader.IsClosed);
            Assert.AreEqual(6, reader.FieldCount);

            DataTable dt = reader.GetSchemaTable();

            Assert.AreNotEqual(null, dt);

            Assert.AreEqual(6, dt.Rows.Count);

            Assert.AreEqual("datid", dt.Rows[0][SchemaTableColumn.ColumnName]);
            Assert.AreEqual(1, dt.Rows[0][SchemaTableColumn.ColumnOrdinal]);

            Assert.AreEqual("datname", dt.Rows[1][SchemaTableColumn.ColumnName]);
            Assert.AreEqual(2, dt.Rows[1][SchemaTableColumn.ColumnOrdinal]);

            Assert.AreEqual("pid", dt.Rows[2][SchemaTableColumn.ColumnName]);
            Assert.AreEqual(3, dt.Rows[2][SchemaTableColumn.ColumnOrdinal]);

            Assert.AreEqual("application_name", dt.Rows[3][SchemaTableColumn.ColumnName]);
            Assert.AreEqual(4, dt.Rows[3][SchemaTableColumn.ColumnOrdinal]);

            Assert.AreEqual("backend_start", dt.Rows[4][SchemaTableColumn.ColumnName]);
            Assert.AreEqual(5, dt.Rows[4][SchemaTableColumn.ColumnOrdinal]);

            Assert.AreEqual("query", dt.Rows[5][SchemaTableColumn.ColumnName]);
            Assert.AreEqual(6, dt.Rows[5][SchemaTableColumn.ColumnOrdinal]);

            reader.Close();
            Assert.AreEqual(ConnectionState.Open, mConnection.State);
            Assert.AreEqual(true, reader.IsClosed);
        }
Exemplo n.º 2
0
        public void PqsqlDataReaderTest5()
        {
            mConnection.Open();

            // get dbname from connection
            object dbname = mConnection.Database;

            PqsqlDataReader reader      = new PqsqlDataReader(mCmd, CommandBehavior.SchemaOnly, new[] { "select oid as ObjectId from pg_class" });
            DataTable       schematable = reader.GetSchemaTable();

            Assert.IsNotNull(schematable);

            Assert.AreEqual(13, schematable.Columns.Count);

            DataRowCollection rows = schematable.Rows;

            Assert.AreEqual(1, rows.Count);

            DataRow row = rows[0];

            Assert.AreEqual(PqsqlDbType.Oid, (PqsqlDbType)row[PqsqlSchemaTableColumn.TypeOid]);
            Assert.AreEqual(true, row[SchemaTableColumn.AllowDBNull]);
            Assert.AreEqual("objectid", row[SchemaTableColumn.BaseColumnName]);
            Assert.AreEqual(dbname, row[SchemaTableOptionalColumn.BaseCatalogName]);
            Assert.AreEqual("pg_catalog", row[SchemaTableColumn.BaseSchemaName]);
            Assert.AreEqual("pg_class", row[SchemaTableColumn.BaseTableName]);
            Assert.AreEqual("objectid", row[SchemaTableColumn.ColumnName]);

            Assert.AreEqual(1, row[SchemaTableColumn.ColumnOrdinal]);
            Assert.AreEqual(4, row[SchemaTableColumn.ColumnSize]);

            Assert.AreEqual(0, row[SchemaTableColumn.NumericPrecision]);
            Assert.AreEqual(0, row[SchemaTableColumn.NumericScale]);

            Assert.AreEqual("oid", row[SchemaTableColumn.ProviderType]);
            Assert.AreEqual(typeof(uint), row[SchemaTableColumn.DataType]);
        }