/*-------------------------------------------------------------------------
*
* Copyright (c) 2004-2013, PostgreSQL Global Development Group
*
*
*-------------------------------------------------------------------------
*/
package org.postgresql.test.jdbc2;

import org.postgresql.test.TestUtil;
import junit.framework.TestCase;
import java.sql.*;

/*
 * TestCase to test the internal functionality of org.postgresql.jdbc2.DatabaseMetaData
 *
 */

public class SearchPathLookupTest extends TestCase
{

    private Connection con;
    /*
     * Constructor
     */
    public SearchPathLookupTest(String name)
    {
        super(name);
    }

    public void testSearchPathNormalLookup() throws Exception
    {
        con = TestUtil.openDB();
        Statement stmt = con.createStatement();
        try {
            TestUtil.createSchema( con, "first_schema" );
            TestUtil.createTable( con, "first_schema.x", "first_schema_field_n int4");
            TestUtil.createSchema( con, "second_schema" );
            TestUtil.createTable( con, "second_schema.x", "second_schema_field_n text");
            TestUtil.createSchema( con, "third_schema" );
            TestUtil.createTable( con, "third_schema.x", "third_schema_field_n float");
            TestUtil.createSchema( con, "last_schema" );
            TestUtil.createTable( con, "last_schema.x", "last_schema_field_n text");
            stmt.execute("SET search_path TO third_schema;");
            DatabaseMetaData dbmd = con.getMetaData();
            ResultSet rs = dbmd.getColumns("", "", "x", "");
            assertTrue(rs.next());
            assertEquals("third_schema_field_n", rs.getString("COLUMN_NAME"));
            assertTrue(!rs.next());
            TestUtil.dropSchema( con, "first_schema" );
            TestUtil.dropSchema( con, "second_schema" );
            TestUtil.dropSchema( con, "third_schema" );
            TestUtil.dropSchema( con, "last_schema" );
        } finally {
            if ( stmt != null ) stmt.close();
            TestUtil.closeDB( con );
        }
    }
    
    /* -- TODO: make this test work 
    public void testSearchPathBackwardsCompatibleLookup() throws Exception
    {
        con = TestUtil.openDB();
        try {
            TestUtil.createSchema( con, "first_schema" );
            TestUtil.createTable( con, "first_schema.x", "first_schema_field int4");
            TestUtil.createSchema( con, "second_schema" );
            TestUtil.createTable( con, "second_schema.x", "second_schema_field text");
            try {
                DatabaseMetaData dbmd = con.getMetaData();
                ResultSet rs = dbmd.getColumns("", "", "x", "");
                assertTrue(rs.next());
                assertEquals("second_schema_field", rs.getString("COLUMN_NAME"));
                assertTrue(!rs.next());
            } finally {
                TestUtil.dropSchema( con, "first_schema" );
                TestUtil.dropSchema( con, "second_schema" );
            }
        } finally {
            TestUtil.closeDB( con );
        }
    }
    */
}

@@ -252,16 +252,132 @@
 jdbc2;%0A%0A
+import org.postgresql.PGConnection;%0Aimport org.postgresql.core.BaseConnection;%0Aimport org.postgresql.core.TypeInfo;%0A
 import o
@@ -623,16 +623,20 @@
 private 
+Base
 Connecti
@@ -756,16 +756,79 @@
 %0A    %7D%0A%0A
+    // TODO: make @getMetaData() consider search_path as well%0A%0A
     publ
@@ -892,32 +892,49 @@
  %7B%0A        con =
+ (BaseConnection)
  TestUtil.openDB
@@ -1658,108 +1658,177 @@
     
-DatabaseMetaData dbmd = con.getMetaData();%0A            ResultSet rs = dbmd.getColumns(%22%22, %22%22, %22x%22, %22
+TypeInfo typeInfo = con.getTypeInfo();%0A            int OID = typeInfo.getPGType(%22x%22);%0A            ResultSet rs = stmt.executeQuery(%22SELECT 'third_schema.x'::regtype::oid
 %22);%0A
@@ -1891,58 +1891,24 @@
 als(
-%22third_schema_field_n%22, rs.getString(%22COLUMN_NAME%22
+OID, rs.getInt(1
 ));%0A
@@ -2295,45 +2295,8 @@
    %0A
-    /* -- TODO: make this test work %0A
     
@@ -2386,31 +2386,96 @@
   con = 
-TestUtil.openDB
+(BaseConnection) TestUtil.openDB();%0A        Statement stmt = con.createStatement
 ();%0A    
@@ -2789,76 +2789,94 @@
     
-try %7B%0A                DatabaseMetaData dbmd = con.getMetaData();%0A   
+TypeInfo typeInfo = con.getTypeInfo();%0A            int OID = typeInfo.getPGType(%22x%22);%0A
     
@@ -2875,33 +2875,32 @@
 %22);%0A            
- 
 ResultSet rs = d
@@ -2902,46 +2902,100 @@
 s = 
-dbmd.getColumns(%22%22, %22%22, %22x%22, %22%22);%0A    
+stmt.executeQuery(%22SELECT oid FROM pg_type WHERE typname = 'x' ORDER BY oid DESC LIMIT 1%22);%0A
     
@@ -3029,36 +3029,32 @@
 ));%0A            
-    
 assertEquals(%22se
@@ -3054,65 +3054,28 @@
 als(
-%22second_schema_field%22, rs.getString(%22COLUMN_NAME%22));%0A    
+OID, rs.getInt(1));%0A
     
@@ -3110,36 +3110,8 @@
 ));%0A
-            %7D finally %7B%0A    
     
@@ -3166,36 +3166,32 @@
  );%0A            
-    
 TestUtil.dropSch
@@ -3223,22 +3223,8 @@
  );%0A
-            %7D%0A
     
@@ -3292,17 +3292,10 @@
 %7D%0A    %7D%0A
-    */%0A
 %7D%0A

Test is checking search_path usage dirctly on TypeInfo methods