Tag: oo_pqsdbc_01
User: jbu     
Date: 2007/01/07 05:50:41

Modified:
   dba/connectivity/source/drivers/postgresql/pq_connection.cxx
   dba/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx
   dba/connectivity/source/drivers/postgresql/pq_statement.cxx
   dba/connectivity/source/drivers/postgresql/pq_xcontainer.cxx
   dba/connectivity/source/drivers/postgresql/pq_xcontainer.hxx
   dba/connectivity/source/drivers/postgresql/pq_xtable.cxx
   dba/connectivity/source/drivers/postgresql/pq_xview.cxx
   dba/connectivity/workben/postgresql/ddl.py
   dba/connectivity/workben/postgresql/sdbcx.py

Log:
 driver now compiles in OOo2 build environment, table's schema renaming is now 
supported for postgresql>=8.1

File Changes:

Directory: /dba/connectivity/source/drivers/postgresql/
=======================================================

File [changed]: pq_connection.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/pq_connection.cxx?r1=1.1.2.4&r2=1.1.2.5
Delta lines:  +3 -3
-------------------
--- pq_connection.cxx   10 Jun 2004 15:26:54 -0000      1.1.2.4
+++ pq_connection.cxx   7 Jan 2007 13:50:37 -0000       1.1.2.5
@@ -2,9 +2,9 @@
  *
  *  $RCSfile: pq_connection.cxx,v $
  *
- *  $Revision: 1.1.2.4 $
+ *  $Revision: 1.1.2.5 $
  *
- *  last change: $Author: jbu $ $Date: 2004/06/10 15:26:54 $
+ *  last change: $Author: jbu $ $Date: 2007/01/07 13:50:37 $
  *
  *  The Contents of this file are made available subject to the terms of
  *  either of the following licenses
@@ -175,7 +175,7 @@
     sal_Int32 loglevel = LogLevel::NONE;
     OUString fileName;
     osl_getModuleURLFromAddress(
-        readLogLevelFromConfiguration, (rtl_uString **) &fileName );
+        (void*) readLogLevelFromConfiguration, (rtl_uString **) &fileName );
     fileName = OUString( fileName.getStr(), fileName.lastIndexOf( '/' )+1 );
     fileName += OUString::createFromAscii(  
SAL_CONFIGFILE("postgresql-sdbc.uno") );
     rtl::Bootstrap bootstrapHandle( fileName );

File [changed]: pq_preparedstatement.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx?r1=1.1.2.7&r2=1.1.2.8
Delta lines:  +4 -4
-------------------
--- pq_preparedstatement.cxx    22 Jan 2006 15:14:28 -0000      1.1.2.7
+++ pq_preparedstatement.cxx    7 Jan 2007 13:50:37 -0000       1.1.2.8
@@ -2,9 +2,9 @@
  *
  *  $RCSfile: pq_preparedstatement.cxx,v $
  *
- *  $Revision: 1.1.2.7 $
+ *  $Revision: 1.1.2.8 $
  *
- *  last change: $Author: jbu $ $Date: 2006/01/22 15:14:28 $
+ *  last change: $Author: jbu $ $Date: 2007/01/07 13:50:37 $
  *
  *  The Contents of this file are made available subject to the terms of
  *  either of the following licenses
@@ -405,8 +405,8 @@
         }
         else
         {
-            int start = 0;
-            for( int index = 1 ; index < str.getLength() ; index ++ )
+            int start = 0,index;
+            for( index = 1 ; index < str.getLength() ; index ++ )
             {
                 if( str[index] == '?' )
                 {

File [changed]: pq_statement.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/pq_statement.cxx?r1=1.1.2.4&r2=1.1.2.5
Delta lines:  +4 -3
-------------------
--- pq_statement.cxx    17 Jul 2006 21:17:43 -0000      1.1.2.4
+++ pq_statement.cxx    7 Jan 2007 13:50:37 -0000       1.1.2.5
@@ -2,9 +2,9 @@
  *
  *  $RCSfile: pq_statement.cxx,v $
  *
- *  $Revision: 1.1.2.4 $
+ *  $Revision: 1.1.2.5 $
  *
- *  last change: $Author: jbu $ $Date: 2006/07/17 21:17:43 $
+ *  last change: $Author: jbu $ $Date: 2007/01/07 13:50:37 $
  *
  *  The Contents of this file are made available subject to the terms of
  *  either of the following licenses
@@ -571,7 +571,8 @@
                     pSettings);
 
                 // check, whether the columns are in the result set (required 
!)
-                for( int i = 0 ; i < sourceTableKeys.getLength() ;  i ++ )
+                int i;
+                for( i = 0 ; i < sourceTableKeys.getLength() ;  i ++ )
                 {
                     if( -1 == PQfnumber(
                             result,

File [changed]: pq_xcontainer.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/pq_xcontainer.cxx?r1=1.1.2.4&r2=1.1.2.5
Delta lines:  +7 -6
-------------------
--- pq_xcontainer.cxx   22 Jan 2006 15:14:38 -0000      1.1.2.4
+++ pq_xcontainer.cxx   7 Jan 2007 13:50:38 -0000       1.1.2.5
@@ -2,9 +2,9 @@
  *

  *  $RCSfile: pq_xcontainer.cxx,v $

  *

- *  $Revision: 1.1.2.4 $

+ *  $Revision: 1.1.2.5 $

  *

- *  last change: $Author: jbu $ $Date: 2006/01/22 15:14:38 $

+ *  last change: $Author: jbu $ $Date: 2007/01/07 13:50:38 $

  *

  *  The Contents of this file are made available subject to the terms of

  *  either of the following licenses

@@ -331,21 +331,22 @@
     m_origin.clear();

 }

 

-void Container::rename( const rtl::OUString &schema, const rtl::OUString 
&oldName, const rtl::OUString &newName )

+void Container::rename( const rtl::OUString &oldName, const rtl::OUString 
&newName )

 {

     Any newValue;

     {

         osl::MutexGuard guard ( m_refMutex->mutex );

-        String2IntMap::iterator ii = m_name2index.find( concatQualified( 
schema, oldName ) );

+        String2IntMap::iterator ii = m_name2index.find( oldName );

         if( ii != m_name2index.end() )

         {

             sal_Int32 nIndex = ii->second;

             newValue = m_values[nIndex];

             m_name2index.erase( ii );

-            m_name2index[ concatQualified( schema,newName) ] = nIndex;

+            m_name2index[ newName ] = nIndex;

+            newValue = m_values[nIndex];

         }

     }

-    fire( ReplacedBroadcaster( *this, concatQualified( schema, newName ), 
newValue, concatQualified(schema,oldName) ) );

+    fire( ReplacedBroadcaster( *this, newName, newValue, oldName ) );

     fire( RefreshedBroadcaster( *this ) );

 }

 


File [changed]: pq_xcontainer.hxx
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/pq_xcontainer.hxx?r1=1.1.2.3&r2=1.1.2.4
Delta lines:  +3 -3
-------------------
--- pq_xcontainer.hxx   29 Aug 2004 08:33:31 -0000      1.1.2.3
+++ pq_xcontainer.hxx   7 Jan 2007 13:50:38 -0000       1.1.2.4
@@ -2,9 +2,9 @@
  *

  *  $RCSfile: pq_xcontainer.hxx,v $

  *

- *  $Revision: 1.1.2.3 $

+ *  $Revision: 1.1.2.4 $

  *

- *  last change: $Author: jbu $ $Date: 2004/08/29 08:33:31 $

+ *  last change: $Author: jbu $ $Date: 2007/01/07 13:50:38 $

  *

  *  The Contents of this file are made available subject to the terms of

  *  either of the following licenses

@@ -230,7 +230,7 @@
     virtual void SAL_CALL disposing();

 

 public:

-    void rename( const rtl::OUString & schema, const rtl::OUString & oldName, 
const rtl::OUString &newName );

+    void rename( const rtl::OUString & oldName, const rtl::OUString &newName );

 

 protected:

     void fire( const EventBroadcastHelper & helper );


File [changed]: pq_xtable.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/pq_xtable.cxx?r1=1.1.2.5&r2=1.1.2.6
Delta lines:  +54 -15
---------------------
--- pq_xtable.cxx       1 May 2006 19:19:08 -0000       1.1.2.5
+++ pq_xtable.cxx       7 Jan 2007 13:50:38 -0000       1.1.2.6
@@ -2,9 +2,9 @@
  *
  *  $RCSfile: pq_xtable.cxx,v $
  *
- *  $Revision: 1.1.2.5 $
+ *  $Revision: 1.1.2.6 $
  *
- *  last change: $Author: jbu $ $Date: 2006/05/01 19:19:08 $
+ *  last change: $Author: jbu $ $Date: 2007/01/07 13:50:38 $
  *
  *  The Contents of this file are made available subject to the terms of
  *  either of the following licenses
@@ -195,41 +195,80 @@
 
     ::rtl::OUString oldName = extractStringProperty(this,st.NAME );
     ::rtl::OUString schema = extractStringProperty(this,st.SCHEMA_NAME );
+    ::rtl::OUString fullOldName = concatQualified( schema, oldName );
 
-    OUString realNewName = newName;
+    OUString newTableName;
+    OUString newSchemaName;
     // OOo2.0 passes schema + dot + new-table-name while
     // OO1.1.x passes new Name without schema
-    if( newName.match( schema ) && newName[schema.getLength() == '.'] )
+    // in case name contains a dot, it is interpreted as schema.tablename
+    if( newName.indexOf( '.' ) >= 0 )
     {
-        realNewName = newName.copy( schema.getLength() +1);
+        splitConcatenatedIdentifier( newName, &newSchemaName, &newTableName );
     }
+    else
+    {
+        newTableName = newName;
+        newSchemaName = schema;
+    }
+    ::rtl::OUString fullNewName = concatQualified( newSchemaName, newTableName 
);
 
     if( extractStringProperty( this, st.TYPE ).equals( st.VIEW ) && 
m_pSettings->views.is() )
     {
         // maintain view list (really strange API !)
-        Any a = m_pSettings->pViewsImpl->getByName( concatQualified( schema, 
oldName ) );
+        Any a = m_pSettings->pViewsImpl->getByName( fullOldName );
         Reference< com::sun::star::sdbcx::XRename > rename;
         a >>= rename;
         if( rename.is() )
         {
             rename->rename( newName );
+            setPropertyValue_NoBroadcast_public( st.SCHEMA_NAME, 
makeAny(newSchemaName) );
         }
     }
     else
     {
+        if( ! newSchemaName.equals(schema) )
+        {
+            // try new schema name first
+            try
+            {
+                OUStringBuffer buf(128);
+                buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER TABLE" ) );
+                bufferQuoteQualifiedIdentifier(buf, schema, oldName );
+                buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("SET SCHEMA" ) );
+                bufferQuoteIdentifier( buf, newSchemaName );
+                Reference< XStatement > statement = m_conn->createStatement();
+                statement->executeUpdate( buf.makeStringAndClear() );
+                setPropertyValue_NoBroadcast_public( st.SCHEMA_NAME, 
makeAny(newSchemaName) );
+                disposeNoThrow( statement );
+                schema = newSchemaName;
+            }
+            catch( com::sun::star::sdbc::SQLException &e )
+            {
+                OUStringBuffer buf( e.Message );
+                buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "(NOTE: Only 
postgresql server >= V8.1 support changing a table's schema)" ) );
+                e.Message = buf.makeStringAndClear();
+                throw e;
+            }
+
+        }
+        if( ! newTableName.equals( oldName ) ) // might also be just the 
change of a schema name
+        {
         OUStringBuffer buf(128);
         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER TABLE" ) );
         bufferQuoteQualifiedIdentifier(buf, schema, oldName );
         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("RENAME TO" ) );
-        bufferQuoteIdentifier( buf, realNewName );
+            bufferQuoteIdentifier( buf, newTableName );
         Reference< XStatement > statement = m_conn->createStatement();
         statement->executeUpdate( buf.makeStringAndClear() );
+            disposeNoThrow( statement );
+        }
     }
-    setPropertyValue_NoBroadcast_public( st.NAME, makeAny(realNewName) );
+    setPropertyValue_NoBroadcast_public( st.NAME, makeAny(newTableName) );
     // inform the container of the name change !
     if( m_pSettings->tables.is() )
     {
-        m_pSettings->pTablesImpl->rename( schema, oldName, realNewName );
+        m_pSettings->pTablesImpl->rename( fullOldName, fullNewName );
     }
 }
     

File [changed]: pq_xview.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/pq_xview.cxx?r1=1.1.2.4&r2=1.1.2.5
Delta lines:  +53 -17
---------------------
--- pq_xview.cxx        1 May 2006 19:19:08 -0000       1.1.2.4
+++ pq_xview.cxx        7 Jan 2007 13:50:38 -0000       1.1.2.5
@@ -2,9 +2,9 @@
  *
  *  $RCSfile: pq_xview.cxx,v $
  *
- *  $Revision: 1.1.2.4 $
+ *  $Revision: 1.1.2.5 $
  *
- *  last change: $Author: jbu $ $Date: 2006/05/01 19:19:08 $
+ *  last change: $Author: jbu $ $Date: 2007/01/07 13:50:38 $
  *
  *  The Contents of this file are made available subject to the terms of
  *  either of the following licenses
@@ -146,30 +146,66 @@
 
     Statics & st = getStatics();
 
-    ::rtl::OUString oldName( extractStringProperty( this,st.NAME ) );
-    ::rtl::OUString schema( extractStringProperty( this, st.SCHEMA_NAME ) );
+    ::rtl::OUString oldName = extractStringProperty(this,st.NAME );
+    ::rtl::OUString schema = extractStringProperty(this,st.SCHEMA_NAME );
+    ::rtl::OUString fullOldName = concatQualified( schema, oldName );
     
-    OUString realNewName = newName;
+    OUString newTableName;
+    OUString newSchemaName;
     // OOo2.0 passes schema + dot + new-table-name while
     // OO1.1.x passes new Name without schema
-    if( newName.match( schema ) && newName[schema.getLength() == '.'] )
+    // in case name contains a dot, it is interpreted as schema.tablename
+    if( newName.indexOf( '.' ) >= 0 )
     {
-        realNewName = newName.copy( schema.getLength() +1);
+        splitConcatenatedIdentifier( newName, &newSchemaName, &newTableName );
     }
+    else
+    {
+        newTableName = newName;
+        newSchemaName = schema;
+    }
+    ::rtl::OUString fullNewName = concatQualified( newSchemaName, newTableName 
);
 
+    if( ! schema.equals( newSchemaName ) )
+    {
+        try
+        {
+            OUStringBuffer buf(128);
+            buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER TABLE" ) );
+            bufferQuoteQualifiedIdentifier(buf, schema, oldName );
+            buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("SET SCHEMA" ) );
+            bufferQuoteIdentifier( buf, newSchemaName );
+            Reference< XStatement > statement = m_conn->createStatement();
+            statement->executeUpdate( buf.makeStringAndClear() );
+            setPropertyValue_NoBroadcast_public( st.SCHEMA_NAME, 
makeAny(newSchemaName) );
+            disposeNoThrow( statement );
+            schema = newSchemaName;
+        }
+        catch( com::sun::star::sdbc::SQLException &e )
+        {
+            OUStringBuffer buf( e.Message );
+            buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "(NOTE: Only 
postgresql server >= V8.1 support changing a table's schema)" ) );
+            e.Message = buf.makeStringAndClear();
+            throw e;
+        }
+
+    }
+    if( ! oldName.equals( newTableName ) )
+    {
     OUStringBuffer buf(128);
     buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER TABLE" ) );
     bufferQuoteQualifiedIdentifier( buf, schema, oldName );
     buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("RENAME TO" ) );
-    bufferQuoteIdentifier( buf, realNewName );
+        bufferQuoteIdentifier( buf, newTableName );
     Reference< XStatement > statement = m_conn->createStatement();
     statement->executeUpdate( buf.makeStringAndClear() );
-    setPropertyValue_NoBroadcast_public( st.NAME, makeAny(realNewName) );
+        setPropertyValue_NoBroadcast_public( st.NAME, makeAny(newTableName) );
+    }
 
     // inform the container of the name change !
     if( m_pSettings->views.is() )
     {
-        m_pSettings->pViewsImpl->rename( schema, oldName, realNewName );
+        m_pSettings->pViewsImpl->rename( fullOldName, fullNewName );
     }
 }
     

Directory: /dba/connectivity/workben/postgresql/
================================================

File [changed]: ddl.py
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/workben/postgresql/ddl.py?r1=1.1.2.4&r2=1.1.2.5
Delta lines:  +4 -2
-------------------
--- ddl.py      27 May 2006 11:33:10 -0000      1.1.2.4
+++ ddl.py      7 Jan 2007 13:50:38 -0000       1.1.2.5
@@ -2,9 +2,9 @@
 #

 #   $RCSfile: ddl.py,v $

 #

-#   $Revision: 1.1.2.4 $

+#   $Revision: 1.1.2.5 $

 #

-#   last change: $Author: jbu $ $Date: 2006/05/27 11:33:10 $

+#   last change: $Author: jbu $ $Date: 2007/01/07 13:50:38 $

 #

 #   The Contents of this file are made available subject to the terms of

 #   either of the following licenses

@@ -110,6 +110,7 @@
     cleanGroupsAndUsers( stmt )

     executeIgnoringException( stmt, "DROP DOMAIN pqsdbc_short" )

     executeIgnoringException( stmt, "DROP DOMAIN pqsdbc_amount" )

+    executeIgnoringException( stmt, "DROP SCHEMA pqsdbc_test" )

     

     ddls = (

         "BEGIN",

@@ -121,6 +122,7 @@
         "CREATE USER pqsdbc_customer", # technical user (e.g. a webfrontend)

         "CREATE GROUP pqsdbc_employees WITH USER pqsdbc_joe,pqsdbc_susy",

         "CREATE GROUP pqsdbc_admin WITH USER pqsdbc_susy,pqsdbc_boss",

+        "CREATE SCHEMA pqsdbc_test", 

         "CREATE TABLE customer ( "+

               "id char(8) UNIQUE PRIMARY KEY, "+

               "name text, " +


File [changed]: sdbcx.py
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/workben/postgresql/sdbcx.py?r1=1.1.2.5&r2=1.1.2.6
Delta lines:  +30 -8
--------------------
--- sdbcx.py    27 May 2006 11:33:11 -0000      1.1.2.5
+++ sdbcx.py    7 Jan 2007 13:50:38 -0000       1.1.2.6
@@ -2,9 +2,9 @@
 #

 #   $RCSfile: sdbcx.py,v $

 #

-#   $Revision: 1.1.2.5 $

+#   $Revision: 1.1.2.6 $

 #

-#   last change: $Author: jbu $ $Date: 2006/05/27 11:33:11 $

+#   last change: $Author: jbu $ $Date: 2007/01/07 13:50:38 $

 #

 #   The Contents of this file are made available subject to the terms of

 #   either of the following licenses

@@ -188,6 +188,28 @@
 

           self.failUnless( columns.getByIndex(0).Name == "id" )

           

+      def checkRenameTable( self, t , tables):

+          t.rename( "foo" )

+          self.failUnless( tables.hasByName( "public.foo" ) )

+

+          t.rename( "public.foo2" )

+          self.failUnless( tables.hasByName( "public.foo2" ) )

+

+          try:

+              t.rename( "pqsdbc_test.foo2" )

+              self.failUnless( tables.hasByName( "pqsdbc_test.foo2" ) )

+              print "looks like a server 8.1 or later (changing a schema 
succeeded)"

+              t.rename( "pqsdbc_test.foo" )

+              self.failUnless( tables.hasByName( "pqsdbc_test.foo" ) )

+              t.rename( "public.foo2" )

+              self.failUnless( tables.hasByName( "public.foo2" ) )

+          except SQLException,e:

+              if e.Message.find( "support changing" ) >= 0:

+                  print "looks like a server prior to 8.1 (changing schema 
failed with Message [" + e.Message.replace("\n", " ") + "])"

+              else:

+                  raise e

+          tables.dropByName( "public.foo2" )

+          

       def testTables( self ):

           dd = self.driver.getDataDefinitionByConnection( self.connection )

           tables = dd.getTables()

@@ -270,11 +292,11 @@
           

           self.checkDescriptor( cols.getByName( "mytext2" ), "mytext2", 
"text", VARCHAR, 0,0,"'myDefault'","mytext-Description" )

 

-          t.rename( "foo" )

+          t = tables.getByName( "public.customer2" )

+          self.checkRenameTable( t,tables )

 

-          self.failUnless( tables.hasByName( "public.foo" ) )

-#          tables.refresh()

-          tables.dropByName( "public.foo" )

+          t = tables.getByName( "public.blub" )

+          self.checkRenameTable( t,tables )

 

           

 





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to