pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: dmp <danap@ttc-cmc.net>
To: Thomas Kellerer <spam_eater@gmx.net>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Bug in DatabaseMetaData.getColumns() with columns based on domains
Date: Thu, 21 Oct 2010 11:57:01 -0600
Message-ID: <4CC07EED.1030506@ttc-cmc.net> (raw)
In-Reply-To: <i9pdb3$6t5$1@dough.gmane.org>
References: <i9pdb3$6t5$1@dough.gmane.org>

Thomas Kellerer wrote:
> Hi,
>
> consider the following table and domain:
>
> CREATE DOMAIN salary_domain AS numeric(12,2) NOT NULL CHECK (value > 0);
> CREATE TABLE employee (id integer not null, salary salary_domain);
>
> DatabaseMetaData.getColumns(null, "public", "employee", "%");
>
> returns "YES" for the column IS_NULLABLE in the ResultSet whereas it
> should flag that column as not nullable.
>
> Regards
> Thomas
>
>
Perhaps you could provide the Database and JDBC versions to help those that
will need to review the report. I have confirmed on PostgreSQL 9.0.1 and
JDBC postgresql-9.0-801.jdbc3.

Output:

Connection Created
SELECT * FROM "public"."employee" LIMIT 1
Column Name: id IS_NULLABLE: NO
Column Name: salary IS_NULLABLE: YES
Connection Closed

Attached files needed to setup test case and other reviewed data.

danap.

Attachments:

PostgreSQL_JDBC.java (text/plain, 5.7K) download //================================================================= // PostgreSQL_JDBC Class //================================================================= // // This class is used to control the running of the a generic // class to access the PostgreSQL database. // // << PostgreSQL_JDBC.java >> // //================================================================= // Copyright (C) 2010 Dana M. Proctor // Version 1.02 10/21/2010 // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version // 2 of the License, or (at your option) any later version. This // program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See // the GNU General Public License for more details. You should // have received a copy of the GNU General Public License along // with this program; if not, write to the Free Software Foundation, // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // (http://opensource.org) // //----------------------------------------------------------------- // danap@dandymadeproductions.com //================================================================= //================================================================= // PostgreSQL_JDBC Application //================================================================= import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import java.io.*; import java.sql.*; /** * The PostgreSQL class is used to control the running of the a generic class to * access the PostgreSQL database. Arguments -debug. * @author Dana M. Proctor * @version 1.02 10/21/2010 */ class PostgreSQL_JDBC { //============================================================== // PostgreSQL_JDBC Constructor //============================================================== public PostgreSQL_JDBC(Connection con) { testColumnNull(con); } //============================================================== // Test Methods // CREATE DOMAIN salary_domain AS numeric(12,2) NOT NULL CHECK (value > 0); // CREATE TABLE employee (id integer not null, salary salary_domain); // DatabaseMetaData.getColumns(null, "public", "employee", "%"); //============================================================== private void testColumnNull(Connection con) { // Method Instances DatabaseMetaData dbMetaData; ResultSetMetaData tableMetaData; String sqlStatementString; Statement sqlStatement; ResultSet rs, db_resultSet; String identifierQuoteString = "\""; try { // Setup a connection statement. sqlStatement = con.createStatement(); sqlStatementString = "SELECT * FROM " + identifierQuoteString + "public" + identifierQuoteString + "." + identifierQuoteString + "employee" + identifierQuoteString + " LIMIT 1"; System.out.println(sqlStatementString); db_resultSet = sqlStatement.executeQuery(sqlStatementString); dbMetaData = con.getMetaData(); rs = dbMetaData.getColumns(null, "public", "employee", "%"); while (rs.next()) { System.out.print("Column Name: " + rs.getString("COLUMN_NAME") + " " + "IS_NULLABLE: " + rs.getString("IS_NULLABLE")); System.out.println(); } rs.close(); db_resultSet.close(); sqlStatement.close(); } catch (SQLException sqle) { System.out.println("SQL Exeception" + sqle); } } //============================================================ // Main public access point method for instantiating the // PostgreSQL_JDBC application. Arguments: database, username, // & password. //============================================================== public static void main(String[] args) { String host, database, username, password; Connection dbConnection; // Collect connection properties. and setup connection. host = "localhost"; dbConnection = null; if (args.length != 0) { database = args[0]; username = (args.length > 1) ? args[1] : null; password = (args.length > 2) ? args[2] : null; } else { database = "your_database"; username = "your_username"; password = "your_password"; } try { Class.forName("org.postgresql.Driver"); } catch (ClassNotFoundException cne) {System.out.println("ClassNotFoundException" + cne.toString());} // Try to make a connection. try { dbConnection = DriverManager.getConnection("jdbc:postgresql://" + host + "/" + database, username, password); // Connection Good. if (dbConnection != null) { System.out.println("Connection Created"); // Go Do Something. new PostgreSQL_JDBC(dbConnection); // Close. dbConnection.close(); System.out.println("Connection Closed"); } } catch (SQLException sqle) {System.out.println("SQLExeception" + sqle.toString());} } }
public_employee_20101021.sql (text/plain, 585B) download -- -- MyJSQLView SQL Dump -- Version: 3.23 -- WebSite: http://myjsqlview.org -- -- Host: 127.0.0.1 -- Generated On: 2010.10.21 AD at 11:13:04 MDT -- SQL version: PostgreSQL 9.0.1 -- Database: key_tables -- -- ------------------------------------------ -- -- Table structure for table "public"."employee" -- DROP DOMAIN IF EXISTS "salary_domain"; CREATE DOMAIN "salary_domain" AS numeric(12,2) NOT NULL CHECK (value > 0); DROP TABLE IF EXISTS "public"."employee"; CREATE TABLE "public"."employee" ( "id" serial NOT NULL, "salary" "salary_domain", PRIMARY KEY ("id") );
public_employee_columns.sql (text/plain, 326B) download SELECT table_catalog, table_name, column_name, ordinal_position, column_default, is_nullable, data_type, character_maximum_length, numeric_precision, numeric_scale, datetime_precision FROM information_schema.columns WHERE table_catalog='key_tables' AND table_schema='public' AND table_name='employee' ORDER BY ordinal_position
employee_columns_20101021.pdf (application/pdf, 2.1K) download

view thread (8+ messages)  latest in thread

Message-ID: <4CC07EED.1030506@ttc-cmc.net>
Permalink:  ../4CC07EED.1030506@ttc-cmc.net/
Also on:    postgresql.org/message-id/4CC07EED.1030506@ttc-cmc.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: danap@ttc-cmc.net, spam_eater@gmx.net
  Subject: Re: Bug in DatabaseMetaData.getColumns() with columns based on domains
  In-Reply-To: <4CC07EED.1030506@ttc-cmc.net>
  References: <i9pdb3$6t5$1@dough.gmane.org> <4CC07EED.1030506@ttc-cmc.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox