summaryrefslogtreecommitdiff
path: root/connectivity
diff options
context:
space:
mode:
authorLionel Elie Mamane <lionel@mamane.lu>2011-08-12 16:56:43 +0200
committerLionel Elie Mamane <lionel@mamane.lu>2011-11-17 21:15:24 +0100
commit9f479d9334262f65ea844281ef0281ed736d59fe (patch)
tree14fa8d4c56d23dfc75c835f89f0c6ac089ece458 /connectivity
parent391193b62233866e0e6789c7606b5d8a87cebc3a (diff)
pgsql-sdbc: properly delegate escaping to libpq
In particular, this makes it work whether server parameter standards_conforming_strings is off or on
Diffstat (limited to 'connectivity')
-rw-r--r--connectivity/source/drivers/postgresql/pq_statement.cxx10
-rw-r--r--connectivity/source/drivers/postgresql/pq_tools.cxx117
-rw-r--r--connectivity/source/drivers/postgresql/pq_tools.hxx18
-rw-r--r--connectivity/source/drivers/postgresql/pq_updateableresultset.cxx31
-rw-r--r--connectivity/source/drivers/postgresql/pq_xcolumns.cxx32
-rw-r--r--connectivity/source/drivers/postgresql/pq_xcolumns.hxx4
-rw-r--r--connectivity/source/drivers/postgresql/pq_xindexes.cxx6
-rw-r--r--connectivity/source/drivers/postgresql/pq_xkeys.cxx8
-rw-r--r--connectivity/source/drivers/postgresql/pq_xtable.cxx13
-rw-r--r--connectivity/source/drivers/postgresql/pq_xtables.cxx28
-rw-r--r--connectivity/source/drivers/postgresql/pq_xuser.cxx4
-rw-r--r--connectivity/source/drivers/postgresql/pq_xusers.cxx6
-rw-r--r--connectivity/source/drivers/postgresql/pq_xview.cxx8
-rw-r--r--connectivity/source/drivers/postgresql/pq_xviews.cxx2
14 files changed, 165 insertions, 122 deletions
diff --git a/connectivity/source/drivers/postgresql/pq_statement.cxx b/connectivity/source/drivers/postgresql/pq_statement.cxx
index 881c038bfad6..e25e864965d7 100644
--- a/connectivity/source/drivers/postgresql/pq_statement.cxx
+++ b/connectivity/source/drivers/postgresql/pq_statement.cxx
@@ -784,9 +784,9 @@ Reference< XResultSet > getGeneratedValuesFromLastInsert(
OUStringBuffer buf( 128 );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "SELECT * FROM " ) );
if( schemaName.getLength() )
- bufferQuoteQualifiedIdentifier(buf, schemaName,tableName );
+ bufferQuoteQualifiedIdentifier(buf, schemaName, tableName, pConnectionSettings );
else
- bufferQuoteIdentifier( buf, lastTableInserted );
+ bufferQuoteIdentifier( buf, lastTableInserted, pConnectionSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " WHERE oid = " ) );
buf.append( nLastOid , 10 );
query = buf.makeStringAndClear();
@@ -820,7 +820,7 @@ Reference< XResultSet > getGeneratedValuesFromLastInsert(
{
OUStringBuffer buf( 128 );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "SELECT * FROM " ) );
- bufferQuoteQualifiedIdentifier(buf, schemaName,tableName );
+ bufferQuoteQualifiedIdentifier(buf, schemaName, tableName, pConnectionSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " WHERE " ) );
bool additionalCondition = false;
String2StringMap autoValues;
@@ -880,7 +880,7 @@ Reference< XResultSet > getGeneratedValuesFromLastInsert(
if( additionalCondition )
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " AND " ) );
- bufferQuoteIdentifier( buf, keyColumnNames[i] );
+ bufferQuoteIdentifier( buf, keyColumnNames[i], pConnectionSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " = " ) );
buf.append( value );
additionalCondition = true;
@@ -904,7 +904,7 @@ sal_Bool Statement::execute( const OUString& sql )
{
osl::MutexGuard guard( m_refMutex->mutex );
checkClosed();
- OString cmd = rtl::OUStringToOString( sql, m_pSettings->encoding );
+ OString cmd = OUStringToOString( sql, m_pSettings );
m_lastResultset.clear();
m_lastTableInserted = rtl::OUString();
diff --git a/connectivity/source/drivers/postgresql/pq_tools.cxx b/connectivity/source/drivers/postgresql/pq_tools.cxx
index faabf3518445..0fcbc87889be 100644
--- a/connectivity/source/drivers/postgresql/pq_tools.cxx
+++ b/connectivity/source/drivers/postgresql/pq_tools.cxx
@@ -37,7 +37,9 @@ using com::sun::star::sdbc::XRow;
using com::sun::star::sdbcx::XColumnsSupplier;
+using com::sun::star::uno::RuntimeException;
using com::sun::star::uno::UNO_QUERY;
+using com::sun::star::uno::UNO_QUERY_THROW;
using com::sun::star::uno::Reference;
using com::sun::star::uno::Sequence;
using com::sun::star::uno::XInterface;
@@ -157,53 +159,98 @@ rtl::OUString concatQualified( const rtl::OUString & a, const rtl::OUString &b)
return buf.makeStringAndClear();
}
-void bufferEscapeConstant( rtl::OUStringBuffer & buf, const rtl::OUString & value, sal_Int32 encoding )
+inline rtl::OString OUStringToOString( const rtl::OUString str, ConnectionSettings *settings) {
+ OSL_ENSURE(settings, "pgsql-sdbc: OUStringToOString got NULL settings");
+ return rtl::OUStringToOString( str, settings->encoding );
+}
+
+void bufferEscapeConstant( rtl::OUStringBuffer & buf, const rtl::OUString & value, ConnectionSettings *settings )
{
- rtl::OString y = rtl::OUStringToOString( value, encoding );
+
+ rtl::OString y = OUStringToOString( value, settings );
rtl::OStringBuffer strbuf( y.getLength() * 2 + 2 );
- int len = PQescapeString( ((char*)strbuf.getStr()), y.getStr() , y.getLength() );
+ int error;
+ int len = PQescapeStringConn(settings->pConnection, ((char*)strbuf.getStr()), y.getStr() , y.getLength(), &error );
+ if ( error )
+ {
+ char *errstr = PQerrorMessage(settings->pConnection);
+ // As of PostgreSQL 9.1, the only possible errors "involve invalid multibyte encoding"
+ // According to https://www2.opengroup.org/ogsys/jsp/publications/PublicationDetails.jsp?publicationid=11216
+ // (X/Open SQL CLI, March 1995, ISBN: 1-85912-081-4, X/Open Document Number: C451)
+ // 22018 is for "Invalid character value" and seems to be the best match.
+ // We have no good XInterface Reference to pass here, so just give NULL
+ throw SQLException(OUString(errstr, strlen(errstr), settings->encoding),
+ NULL,
+ OUString(RTL_CONSTASCII_USTRINGPARAM("22018")),
+ -1,
+ Any());
+ }
strbuf.setLength( len );
- buf.append( rtl::OStringToOUString( strbuf.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US ) );
+ // Previously here RTL_TEXTENCODING_ASCII_US; as we set the PostgreSQL client_encoding to UTF8,
+ // we get UTF8 here, too. I'm not sure why it worked well before...
+ buf.append( rtl::OStringToOUString( strbuf.makeStringAndClear(), RTL_TEXTENCODING_UTF8 ) );
}
-void bufferQuoteConstant( rtl::OUStringBuffer & buf, const rtl::OUString & value, sal_Int32 encoding )
+inline void bufferQuoteConstant( rtl::OUStringBuffer & buf, const rtl::OUString & value, ConnectionSettings *settings )
{
- buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " '" ) );
- bufferEscapeConstant( buf, value, encoding );
- buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "' " ) );
+ buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "'" ) );
+ bufferEscapeConstant( buf, value, settings );
+ buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "'" ) );
+}
+
+void bufferQuoteAnyConstant( rtl::OUStringBuffer & buf, const Any &val, ConnectionSettings *settings )
+{
+ if( val.hasValue() )
+ {
+ OUString str;
+ val >>= str;
+ bufferQuoteConstant( buf, str, settings );
+ }
+ else
+ buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "NULL" ) );
}
void bufferQuoteQualifiedIdentifier(
- rtl::OUStringBuffer & buf, const rtl::OUString &schema, const rtl::OUString &name)
+ rtl::OUStringBuffer & buf, const rtl::OUString &schema, const rtl::OUString &table, ConnectionSettings *settings )
{
- buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" \"" ) );
- buf.append(schema);
- buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\".\"" ) );
- buf.append( name );
- buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "\" " ) );
+ bufferQuoteIdentifier(buf, schema, settings);
+ buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "." ) );
+ bufferQuoteIdentifier(buf, table, settings);
}
void bufferQuoteQualifiedIdentifier(
rtl::OUStringBuffer & buf,
const rtl::OUString &schema,
- const rtl::OUString &name,
- const rtl::OUString &col)
+ const rtl::OUString &table,
+ const rtl::OUString &col,
+ ConnectionSettings *settings)
{
- buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" \"" ) );
- buf.append(schema);
- buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\".\"" ) );
- buf.append( name );
- buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\".\"" ) );
- buf.append( col );
- buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "\" " ) );
+ bufferQuoteIdentifier(buf, schema, settings);
+ buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "." ) );
+ bufferQuoteIdentifier(buf, table, settings);
+ buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "." ) );
+ bufferQuoteIdentifier(buf, col, settings);
}
-void bufferQuoteIdentifier( rtl::OUStringBuffer & buf, const rtl::OUString &toQuote )
+inline void bufferQuoteIdentifier( rtl::OUStringBuffer & buf, const rtl::OUString &toQuote, ConnectionSettings *settings )
{
- buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " \"") );
- buf.append( toQuote );
- buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "\" " ) );
+ OSL_ENSURE(settings, "pgsql-sdbc: bufferQuoteIdentifier got NULL settings");
+
+ rtl::OString y = OUStringToOString( toQuote, settings );
+ char *cstr = PQescapeIdentifier(settings->pConnection, y.getStr(), y.getLength());
+ if ( cstr == NULL )
+ {
+ char *errstr = PQerrorMessage(settings->pConnection);
+ // Implementation-defined SQLACCESS error
+ throw SQLException(OUString(errstr, strlen(errstr), settings->encoding),
+ NULL,
+ OUString(RTL_CONSTASCII_USTRINGPARAM("22018")),
+ -1,
+ Any());
+ }
+ buf.append( rtl::OStringToOUString( cstr, RTL_TEXTENCODING_UTF8 ) );
+ PQfreemem( cstr );
}
@@ -747,12 +794,12 @@ void fillAttnum2attnameMap(
"INNER JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid "
"WHERE relname=? AND nspname=?" ) );
- Reference< XParameters > paras( prep, UNO_QUERY );
+ Reference< XParameters > paras( prep, UNO_QUERY_THROW );
paras->setString( 1 , table );
paras->setString( 2 , schema );
Reference< XResultSet > rs = prep->executeQuery();
- Reference< XRow > xRow( rs , UNO_QUERY );
+ Reference< XRow > xRow( rs , UNO_QUERY_THROW );
while( rs->next() )
{
map[ xRow->getInt(2) ] = xRow->getString(1);
@@ -966,7 +1013,7 @@ static void keyType2String( OUStringBuffer & buf, sal_Int32 keyType )
}
void bufferKey2TableConstraint(
- OUStringBuffer &buf, const Reference< XPropertySet > &key )
+ OUStringBuffer &buf, const Reference< XPropertySet > &key, ConnectionSettings *settings )
{
Statics &st = getStatics();
sal_Int32 type = extractIntProperty( key, st.TYPE );
@@ -1006,8 +1053,8 @@ void bufferKey2TableConstraint(
{
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) );
}
- Reference< XPropertySet > keyColumn( colEnum->nextElement(), UNO_QUERY );
- bufferQuoteIdentifier(buf, extractStringProperty( keyColumn, st.NAME ) );
+ Reference< XPropertySet > keyColumn( colEnum->nextElement(), UNO_QUERY_THROW );
+ bufferQuoteIdentifier(buf, extractStringProperty( keyColumn, st.NAME ), settings );
}
}
}
@@ -1019,7 +1066,7 @@ void bufferKey2TableConstraint(
OUString schema;
OUString tableName;
splitConcatenatedIdentifier( referencedTable, &schema, &tableName );
- bufferQuoteQualifiedIdentifier(buf , schema, tableName);
+ bufferQuoteQualifiedIdentifier(buf , schema, tableName, settings );
if(columns.is() )
{
Reference< XEnumerationAccess > colEnumAccess( columns->getColumns(), UNO_QUERY);
@@ -1038,9 +1085,9 @@ void bufferKey2TableConstraint(
{
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) );
}
- Reference< XPropertySet > keyColumn( colEnum->nextElement(), UNO_QUERY );
+ Reference< XPropertySet > keyColumn( colEnum->nextElement(), UNO_QUERY_THROW );
bufferQuoteIdentifier(
- buf, extractStringProperty( keyColumn, st.RELATED_COLUMN ) );
+ buf, extractStringProperty( keyColumn, st.RELATED_COLUMN ), settings );
}
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( ") " ) );
}
diff --git a/connectivity/source/drivers/postgresql/pq_tools.hxx b/connectivity/source/drivers/postgresql/pq_tools.hxx
index fac4b88631d4..71de5ee44164 100644
--- a/connectivity/source/drivers/postgresql/pq_tools.hxx
+++ b/connectivity/source/drivers/postgresql/pq_tools.hxx
@@ -1,3 +1,4 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* $RCSfile: pq_tools.hxx,v $
@@ -90,27 +91,32 @@ com::sun::star::util::DateTime string2DateTime( const rtl::OUString & dateTime )
rtl::OUString concatQualified( const rtl::OUString & a, const rtl::OUString &b);
-void bufferQuoteConstant( rtl::OUStringBuffer & buf, const rtl::OUString & str, sal_Int32 encoding );
+rtl::OString OUStringToOString( rtl::OUString str, ConnectionSettings *settings);
-void bufferEscapeConstant( rtl::OUStringBuffer & buf, const rtl::OUString & str, sal_Int32 encoding );
+void bufferQuoteConstant( rtl::OUStringBuffer & buf, const rtl::OUString & str, ConnectionSettings *settings );
+ void bufferQuoteAnyConstant( rtl::OUStringBuffer & buf, const com::sun::star::uno::Any &val, ConnectionSettings *settings );
+
+void bufferEscapeConstant( rtl::OUStringBuffer & buf, const rtl::OUString & str, ConnectionSettings *settings );
::rtl::OUString sqltype2string(
const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > & column );
void bufferQuoteQualifiedIdentifier(
- rtl::OUStringBuffer & buf, const rtl::OUString &schema, const rtl::OUString &name);
+ rtl::OUStringBuffer & buf, const rtl::OUString &schema, const rtl::OUString &name, ConnectionSettings *settings );
void bufferQuoteQualifiedIdentifier(
rtl::OUStringBuffer & buf,
const rtl::OUString &schema,
const rtl::OUString &name,
- const rtl::OUString &col);
+ const rtl::OUString &col,
+ ConnectionSettings *settings );
-void bufferQuoteIdentifier( rtl::OUStringBuffer & buf, const rtl::OUString &toQuote );
+void bufferQuoteIdentifier( rtl::OUStringBuffer & buf, const rtl::OUString &toQuote, ConnectionSettings *settings );
void bufferKey2TableConstraint(
rtl::OUStringBuffer &buf,
- const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > &key );
+ const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > &key,
+ ConnectionSettings *settings );
rtl::OUString extractStringProperty(
const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > & descriptor,
diff --git a/connectivity/source/drivers/postgresql/pq_updateableresultset.cxx b/connectivity/source/drivers/postgresql/pq_updateableresultset.cxx
index bc48e1e21bd6..640d7de936d5 100644
--- a/connectivity/source/drivers/postgresql/pq_updateableresultset.cxx
+++ b/connectivity/source/drivers/postgresql/pq_updateableresultset.cxx
@@ -102,21 +102,6 @@ com::sun::star::uno::Reference< com::sun::star::sdbc::XCloseable > UpdateableRes
return ret;
}
-static void bufferQuoteAnyConstant( rtl::OUStringBuffer & buf, const Any &val )
-{
- if( val.hasValue() )
- {
- OUString str;
- val >>= str;
- buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "'" ) );
- buf.append( str );
- buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "'" ) );
- }
- else
- buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "NULL" ) );
-}
-
-
com::sun::star::uno::Any UpdateableResultSet::queryInterface(
const com::sun::star::uno::Type & reqType )
throw (com::sun::star::uno::RuntimeException)
@@ -179,9 +164,9 @@ OUString UpdateableResultSet::buildWhereClause()
if( i > 0 )
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " AND " ) );
sal_Int32 index = findColumn( m_primaryKey[i] );
- bufferQuoteIdentifier( buf, m_primaryKey[i] );
+ bufferQuoteIdentifier( buf, m_primaryKey[i], *m_ppSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " = " ) );
- bufferQuoteConstant( buf, getString( index ), (*m_ppSettings)->encoding );
+ bufferQuoteConstant( buf, getString( index ), *m_ppSettings );
}
ret = buf.makeStringAndClear();
}
@@ -203,7 +188,7 @@ void UpdateableResultSet::insertRow( ) throw (SQLException, RuntimeException)
OUStringBuffer buf( 128 );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "INSERT INTO " ) );
- bufferQuoteQualifiedIdentifier( buf, m_schema, m_table );
+ bufferQuoteQualifiedIdentifier( buf, m_schema, m_table, *m_ppSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " ( " ) );
int columns = 0;
@@ -214,7 +199,7 @@ void UpdateableResultSet::insertRow( ) throw (SQLException, RuntimeException)
if( columns > 0 )
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) );
columns ++;
- bufferQuoteIdentifier( buf, m_columnNames[i]);
+ bufferQuoteIdentifier( buf, m_columnNames[i], *m_ppSettings);
}
}
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " ) VALUES ( " ) );
@@ -227,7 +212,7 @@ void UpdateableResultSet::insertRow( ) throw (SQLException, RuntimeException)
if( columns > 0 )
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " , " ) );
columns ++;
- bufferQuoteAnyConstant( buf, m_updateableField[i].value );
+ bufferQuoteAnyConstant( buf, m_updateableField[i].value, *m_ppSettings );
// OUString val;
// m_updateableField[i].value >>= val;
@@ -297,7 +282,7 @@ void UpdateableResultSet::updateRow( ) throw (SQLException, RuntimeException)
OUStringBuffer buf( 128 );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "UPDATE " ) );
- bufferQuoteQualifiedIdentifier( buf, m_schema, m_table );
+ bufferQuoteQualifiedIdentifier( buf, m_schema, m_table, *m_ppSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "SET " ) );
int columns = 0;
@@ -311,7 +296,7 @@ void UpdateableResultSet::updateRow( ) throw (SQLException, RuntimeException)
buf.append( m_columnNames[i] );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" = " ) );
- bufferQuoteAnyConstant( buf, m_updateableField[i].value );
+ bufferQuoteAnyConstant( buf, m_updateableField[i].value, *m_ppSettings );
// OUString val;
// m_updateableField[i].value >>= val;
// bufferQuoteConstant( buf, val ):
@@ -357,7 +342,7 @@ void UpdateableResultSet::deleteRow( ) throw (SQLException, RuntimeException)
DisposeGuard dispGuard( stmt );
OUStringBuffer buf( 128 );
buf.appendAscii( "DELETE FROM " );
- bufferQuoteQualifiedIdentifier( buf, m_schema, m_table );
+ bufferQuoteQualifiedIdentifier( buf, m_schema, m_table, *m_ppSettings );
buf.appendAscii( " " );
buf.append( buildWhereClause() );
diff --git a/connectivity/source/drivers/postgresql/pq_xcolumns.cxx b/connectivity/source/drivers/postgresql/pq_xcolumns.cxx
index a424e3e253f5..ab033dc79bbf 100644
--- a/connectivity/source/drivers/postgresql/pq_xcolumns.cxx
+++ b/connectivity/source/drivers/postgresql/pq_xcolumns.cxx
@@ -1,3 +1,4 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* $RCSfile: pq_xcolumns.cxx,v $
@@ -381,7 +382,7 @@ void Columns::refresh()
void alterColumnByDescriptor(
const OUString & schemaName,
const OUString & tableName,
- rtl_TextEncoding encoding,
+ ConnectionSettings *settings,
const Reference< XStatement > &stmt,
const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > & past,
const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > & future)
@@ -415,9 +416,9 @@ void alterColumnByDescriptor(
{
// create a new column
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER TABLE" ) );
- bufferQuoteQualifiedIdentifier( buf, schemaName, tableName );
+ bufferQuoteQualifiedIdentifier( buf, schemaName, tableName, settings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ADD COLUMN" ) );
- bufferQuoteIdentifier( buf, futureColumnName );
+ bufferQuoteIdentifier( buf, futureColumnName, settings );
buf.append( futureTypeName );
transaction.executeUpdate( buf.makeStringAndClear() );
}
@@ -433,11 +434,11 @@ void alterColumnByDescriptor(
if( pastColumnName != futureColumnName )
{
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER TABLE" ) );
- bufferQuoteQualifiedIdentifier( buf, schemaName, tableName );
+ bufferQuoteQualifiedIdentifier( buf, schemaName, tableName, settings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "RENAME COLUMN" ) );
- bufferQuoteIdentifier( buf, pastColumnName );
+ bufferQuoteIdentifier( buf, pastColumnName, settings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "TO" ) );
- bufferQuoteIdentifier( buf, futureColumnName );
+ bufferQuoteIdentifier( buf, futureColumnName, settings );
transaction.executeUpdate( buf.makeStringAndClear() );
}
}
@@ -448,10 +449,11 @@ void alterColumnByDescriptor(
{
buf = OUStringBuffer( 128 );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER TABLE" ) );
- bufferQuoteQualifiedIdentifier( buf, schemaName, tableName );
+ bufferQuoteQualifiedIdentifier( buf, schemaName, tableName, settings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER COLUMN" ) );
- bufferQuoteIdentifier( buf, futureColumnName );
+ bufferQuoteIdentifier( buf, futureColumnName, settings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "SET DEFAULT " ) );
+ // LEM TODO: check out
// default value is not quoted, caller needs to quote himself (otherwise
// how to pass e.g. nextval('something' ) ????
buf.append( futureDefaultValue );
@@ -465,9 +467,9 @@ void alterColumnByDescriptor(
{
buf = OUStringBuffer( 128 );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER TABLE" ) );
- bufferQuoteQualifiedIdentifier( buf, schemaName, tableName );
+ bufferQuoteQualifiedIdentifier( buf, schemaName, tableName, settings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER COLUMN" ) );
- bufferQuoteIdentifier( buf, futureColumnName );
+ bufferQuoteIdentifier( buf, futureColumnName, settings );
if( futureNullable == com::sun::star::sdbc::ColumnValue::NO_NULLS )
{
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "SET" ) );
@@ -492,9 +494,9 @@ void alterColumnByDescriptor(
{
buf = OUStringBuffer( 128 );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "COMMENT ON COLUMN" ) );
- bufferQuoteQualifiedIdentifier( buf, schemaName, tableName , futureColumnName );
+ bufferQuoteQualifiedIdentifier( buf, schemaName, tableName , futureColumnName, settings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "IS " ) );
- bufferQuoteConstant( buf, futureComment,encoding);
+ bufferQuoteConstant( buf, futureComment, settings );
transaction.executeUpdate( buf.makeStringAndClear() );
}
transaction.commit();
@@ -511,7 +513,7 @@ void Columns::appendByDescriptor(
Reference< XPropertySet > past = createDataDescriptor();
past->setPropertyValue( st.IS_NULLABLE, makeAny( com::sun::star::sdbc::ColumnValue::NULLABLE ) );
alterColumnByDescriptor(
- m_schemaName, m_tableName, m_pSettings->encoding, m_origin->createStatement() , past, future );
+ m_schemaName, m_tableName, m_pSettings, m_origin->createStatement() , past, future );
refresh();
}
@@ -564,9 +566,9 @@ void Columns::dropByIndex( sal_Int32 index )
OUStringBuffer update( 128 );
update.appendAscii( "ALTER TABLE ONLY");
- bufferQuoteQualifiedIdentifier( update, m_schemaName, m_tableName );
+ bufferQuoteQualifiedIdentifier( update, m_schemaName, m_tableName, m_pSettings );
update.appendAscii( "DROP COLUMN" );
- bufferQuoteIdentifier( update, name );
+ bufferQuoteIdentifier( update, name, m_pSettings );
Reference< XStatement > stmt = m_origin->createStatement( );
DisposeGuard disposeIt( stmt );
stmt->executeUpdate( update.makeStringAndClear() );
diff --git a/connectivity/source/drivers/postgresql/pq_xcolumns.hxx b/connectivity/source/drivers/postgresql/pq_xcolumns.hxx
index 3f5301ad14e6..f63508b204a6 100644
--- a/connectivity/source/drivers/postgresql/pq_xcolumns.hxx
+++ b/connectivity/source/drivers/postgresql/pq_xcolumns.hxx
@@ -1,3 +1,4 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* $RCSfile: pq_xcolumns.hxx,v $
@@ -51,6 +52,7 @@
* The Initial Developer of the Original Code is: Joerg Budischewski
*
* Copyright: 2000 by Sun Microsystems, Inc.
+ * 2011 by Lionel Elie Mamane <lionel@mamane.lu>
*
* All Rights Reserved.
*
@@ -71,7 +73,7 @@ namespace pq_sdbc_driver
void alterColumnByDescriptor(
const rtl::OUString & schemaName,
const rtl::OUString & tableName,
- rtl_TextEncoding encoding,
+ ConnectionSettings *settings,
const com::sun::star::uno::Reference< com::sun::star::sdbc::XStatement > &stmt,
const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > & past,
const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > & future);
diff --git a/connectivity/source/drivers/postgresql/pq_xindexes.cxx b/connectivity/source/drivers/postgresql/pq_xindexes.cxx
index a7ee62cab6d0..84d0b70e4e9d 100644
--- a/connectivity/source/drivers/postgresql/pq_xindexes.cxx
+++ b/connectivity/source/drivers/postgresql/pq_xindexes.cxx
@@ -242,9 +242,9 @@ void Indexes::appendByDescriptor(
if( isUnique )
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "UNIQUE " ) );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "INDEX " ) );
- bufferQuoteIdentifier( buf, name );
+ bufferQuoteIdentifier( buf, name, m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " ON " ) );
- bufferQuoteQualifiedIdentifier( buf, m_schemaName, m_tableName );
+ bufferQuoteQualifiedIdentifier( buf, m_schemaName, m_tableName, m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " ( " ) );
@@ -303,7 +303,7 @@ void Indexes::dropByIndex( sal_Int32 index )
OUStringBuffer buf( 128 );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "DROP INDEX " ) );
- bufferQuoteIdentifier( buf, extractStringProperty( set, st.NAME ) );
+ bufferQuoteIdentifier( buf, extractStringProperty( set, st.NAME ), m_pSettings );
m_origin->createStatement()->executeUpdate( buf.makeStringAndClear() );
Container::dropByIndex( index );
diff --git a/connectivity/source/drivers/postgresql/pq_xkeys.cxx b/connectivity/source/drivers/postgresql/pq_xkeys.cxx
index 0fa8f166a743..3abdb901ff8e 100644
--- a/connectivity/source/drivers/postgresql/pq_xkeys.cxx
+++ b/connectivity/source/drivers/postgresql/pq_xkeys.cxx
@@ -300,9 +300,9 @@ void Keys::appendByDescriptor(
OUStringBuffer buf( 128 );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER TABLE " ) );
- bufferQuoteQualifiedIdentifier( buf, m_schemaName, m_tableName );
+ bufferQuoteQualifiedIdentifier( buf, m_schemaName, m_tableName, m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " ADD " ) );
- bufferKey2TableConstraint( buf, descriptor );
+ bufferKey2TableConstraint( buf, descriptor, m_pSettings );
Reference< XStatement > stmt =
m_origin->createStatement();
@@ -334,9 +334,9 @@ void Keys::dropByIndex( sal_Int32 index )
OUStringBuffer buf( 128 );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER TABLE " ) );
- bufferQuoteQualifiedIdentifier( buf, m_schemaName, m_tableName );
+ bufferQuoteQualifiedIdentifier( buf, m_schemaName, m_tableName, m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " DROP CONSTRAINT " ) );
- bufferQuoteIdentifier( buf, extractStringProperty( set , getStatics().NAME ) );
+ bufferQuoteIdentifier( buf, extractStringProperty( set , getStatics().NAME ), m_pSettings );
m_origin->createStatement()->executeUpdate( buf.makeStringAndClear() );
diff --git a/connectivity/source/drivers/postgresql/pq_xtable.cxx b/connectivity/source/drivers/postgresql/pq_xtable.cxx
index 43839ecb0f1c..002abd04e904 100644
--- a/connectivity/source/drivers/postgresql/pq_xtable.cxx
+++ b/connectivity/source/drivers/postgresql/pq_xtable.cxx
@@ -1,3 +1,4 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* $RCSfile: pq_xtable.cxx,v $
@@ -234,9 +235,9 @@ void Table::rename( const ::rtl::OUString& newName )
{
OUStringBuffer buf(128);
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER TABLE" ) );
- bufferQuoteQualifiedIdentifier(buf, schema, oldName );
+ bufferQuoteQualifiedIdentifier(buf, schema, oldName, m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("SET SCHEMA" ) );
- bufferQuoteIdentifier( buf, newSchemaName );
+ bufferQuoteIdentifier( buf, newSchemaName, m_pSettings );
Reference< XStatement > statement = m_conn->createStatement();
statement->executeUpdate( buf.makeStringAndClear() );
setPropertyValue_NoBroadcast_public( st.SCHEMA_NAME, makeAny(newSchemaName) );
@@ -256,9 +257,9 @@ void Table::rename( const ::rtl::OUString& newName )
{
OUStringBuffer buf(128);
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER TABLE" ) );
- bufferQuoteQualifiedIdentifier(buf, schema, oldName );
+ bufferQuoteQualifiedIdentifier(buf, schema, oldName, m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("RENAME TO" ) );
- bufferQuoteIdentifier( buf, newTableName );
+ bufferQuoteIdentifier( buf, newTableName, m_pSettings );
Reference< XStatement > statement = m_conn->createStatement();
statement->executeUpdate( buf.makeStringAndClear() );
disposeNoThrow( statement );
@@ -284,7 +285,7 @@ void Table::alterColumnByName(
::pq_sdbc_driver::alterColumnByDescriptor(
extractStringProperty( this, getStatics().SCHEMA_NAME ),
extractStringProperty( this, getStatics().NAME ),
- m_pSettings->encoding,
+ m_pSettings,
m_conn->createStatement(),
Reference< com::sun::star::beans::XPropertySet>( colums->getByName( colName ), UNO_QUERY) ,
descriptor );
@@ -309,7 +310,7 @@ void Table::alterColumnByIndex(
::pq_sdbc_driver::alterColumnByDescriptor(
extractStringProperty( this, getStatics().SCHEMA_NAME ),
extractStringProperty( this, getStatics().NAME ),
- m_pSettings->encoding,
+ m_pSettings,
m_conn->createStatement(),
column,
descriptor );
diff --git a/connectivity/source/drivers/postgresql/pq_xtables.cxx b/connectivity/source/drivers/postgresql/pq_xtables.cxx
index d487b89085ba..015b5e0a5f75 100644
--- a/connectivity/source/drivers/postgresql/pq_xtables.cxx
+++ b/connectivity/source/drivers/postgresql/pq_xtables.cxx
@@ -52,6 +52,7 @@
* The Initial Developer of the Original Code is: Joerg Budischewski
*
* Copyright: 2000 by Sun Microsystems, Inc.
+ * 2011 by Lionel Elie Mamane <lionel@mamane.lu>
*
* All Rights Reserved.
*
@@ -194,7 +195,7 @@ void Tables::refresh()
static void appendColumnList(
- OUStringBuffer &buf, const Reference< XColumnsSupplier > & columnSupplier, sal_Int32 encoding )
+ OUStringBuffer &buf, const Reference< XColumnsSupplier > & columnSupplier, ConnectionSettings *settings )
{
if( columnSupplier.is() )
{
@@ -221,7 +222,7 @@ static void appendColumnList(
sal_Bool isNullable = extractBoolProperty( column, st.IS_NULLABLE );
sal_Bool isAutoIncrement = extractBoolProperty( column, st.IS_AUTO_INCREMENT );
- bufferQuoteIdentifier( buf, name );
+ bufferQuoteIdentifier( buf, name, settings );
OUString type = sqltype2string( column );
if( isAutoIncrement )
@@ -247,7 +248,7 @@ static void appendColumnList(
}
if( defaultValue.getLength() )
{
- bufferQuoteConstant( buf, defaultValue, encoding );
+ bufferQuoteConstant( buf, defaultValue, settings );
}
if( ! isNullable )
@@ -261,7 +262,7 @@ static void appendColumnList(
}
static void appendKeyList(
- OUStringBuffer & buf, const Reference< XKeysSupplier > &keySupplier )
+ OUStringBuffer & buf, const Reference< XKeysSupplier > &keySupplier, ConnectionSettings *settings )
{
if( keySupplier.is() )
{
@@ -273,7 +274,7 @@ static void appendKeyList(
{
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) );
Reference< XPropertySet > key( xEnum->nextElement(), UNO_QUERY );
- bufferKey2TableConstraint( buf, key );
+ bufferKey2TableConstraint( buf, key, settings );
}
}
}
@@ -298,14 +299,14 @@ void Tables::appendByDescriptor(
OUStringBuffer buf( 128 );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("CREATE TABLE" ) );
- bufferQuoteQualifiedIdentifier( buf, schema, name );
+ bufferQuoteQualifiedIdentifier( buf, schema, name , m_pSettings);
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "(" ) );
// columns
Reference< XColumnsSupplier > supplier( descriptor, UNO_QUERY );
- appendColumnList( buf, supplier, m_pSettings->encoding );
+ appendColumnList( buf, supplier, m_pSettings );
- appendKeyList( buf, Reference< XKeysSupplier >( descriptor, UNO_QUERY ) );
+ appendKeyList( buf, Reference< XKeysSupplier >( descriptor, UNO_QUERY ), m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( ") " ) );
// execute the creation !
@@ -317,9 +318,9 @@ void Tables::appendByDescriptor(
{
buf = OUStringBuffer( 128 );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "COMMENT ON TABLE" ) );
- bufferQuoteQualifiedIdentifier( buf, schema, name );
+ bufferQuoteQualifiedIdentifier( buf, schema, name, m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "IS " ) );
- bufferQuoteConstant( buf, description, m_pSettings->encoding );
+ bufferQuoteConstant( buf, description, m_pSettings);
transaction.executeUpdate( buf.makeStringAndClear() );
}
@@ -342,10 +343,9 @@ void Tables::appendByDescriptor(
buf = OUStringBuffer( 128 );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "COMMENT ON COLUMN " ) );
bufferQuoteQualifiedIdentifier(
- buf, schema, name, extractStringProperty( column, st.NAME ) );
+ buf, schema, name, extractStringProperty( column, st.NAME ), m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "IS " ) );
- bufferQuoteConstant(
- buf, description,m_pSettings->encoding );
+ bufferQuoteConstant( buf, description, m_pSettings );
transaction.executeUpdate( buf.makeStringAndClear() );
}
}
@@ -427,7 +427,7 @@ void Tables::dropByIndex( sal_Int32 index )
update.appendAscii( RTL_CONSTASCII_STRINGPARAM( "VIEW " ) );
else
update.appendAscii( RTL_CONSTASCII_STRINGPARAM( "TABLE " ) );
- bufferQuoteQualifiedIdentifier( update, schema, name );
+ bufferQuoteQualifiedIdentifier( update, schema, name, m_pSettings );
Reference< XStatement > stmt = m_origin->createStatement( );
DisposeGuard dispGuard( stmt );
stmt->executeUpdate( update.makeStringAndClear() );
diff --git a/connectivity/source/drivers/postgresql/pq_xuser.cxx b/connectivity/source/drivers/postgresql/pq_xuser.cxx
index 0fe46f6d8f9b..cd22f1578ff8 100644
--- a/connectivity/source/drivers/postgresql/pq_xuser.cxx
+++ b/connectivity/source/drivers/postgresql/pq_xuser.cxx
@@ -177,9 +177,9 @@ void User::changePassword(
{
rtl::OUStringBuffer buf(128);
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER USER " ) );
- bufferQuoteIdentifier( buf, extractStringProperty( this, getStatics().NAME ) );
+ bufferQuoteIdentifier( buf, extractStringProperty( this, getStatics().NAME ), m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " PASSWORD " ) );
- bufferQuoteConstant( buf, newPassword, m_pSettings->encoding );
+ bufferQuoteConstant( buf, newPassword, m_pSettings );
Reference< XStatement > stmt = m_conn->createStatement();
DisposeGuard guard( stmt );
stmt->executeUpdate( buf.makeStringAndClear() );
diff --git a/connectivity/source/drivers/postgresql/pq_xusers.cxx b/connectivity/source/drivers/postgresql/pq_xusers.cxx
index 31078a7ec47b..db7b00a28d6f 100644
--- a/connectivity/source/drivers/postgresql/pq_xusers.cxx
+++ b/connectivity/source/drivers/postgresql/pq_xusers.cxx
@@ -170,9 +170,9 @@ void Users::appendByDescriptor(
OUStringBuffer update( 128 );
update.appendAscii( RTL_CONSTASCII_STRINGPARAM( "CREATE USER " ) );
- bufferQuoteIdentifier( update, extractStringProperty( descriptor, getStatics().NAME ) );
+ bufferQuoteIdentifier( update, extractStringProperty( descriptor, getStatics().NAME ), m_pSettings );
update.appendAscii( RTL_CONSTASCII_STRINGPARAM( " PASSWORD " ) );
- bufferQuoteConstant( update, extractStringProperty( descriptor, getStatics().PASSWORD ), m_pSettings->encoding );
+ bufferQuoteConstant( update, extractStringProperty( descriptor, getStatics().PASSWORD ), m_pSettings );
Reference< XStatement > stmt = m_origin->createStatement( );
DisposeGuard disposeGuard( stmt );
@@ -223,7 +223,7 @@ void Users::dropByIndex( sal_Int32 index )
OUStringBuffer update( 128 );
update.appendAscii( "DROP USER " );
- bufferQuoteIdentifier( update, name );
+ bufferQuoteIdentifier( update, name, m_pSettings );
Reference< XStatement > stmt = m_origin->createStatement( );
DisposeGuard disposeGuard( stmt );
diff --git a/connectivity/source/drivers/postgresql/pq_xview.cxx b/connectivity/source/drivers/postgresql/pq_xview.cxx
index 3377d972f72b..468788f8775f 100644
--- a/connectivity/source/drivers/postgresql/pq_xview.cxx
+++ b/connectivity/source/drivers/postgresql/pq_xview.cxx
@@ -172,9 +172,9 @@ void View::rename( const ::rtl::OUString& newName )
{
OUStringBuffer buf(128);
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER TABLE" ) );
- bufferQuoteQualifiedIdentifier(buf, schema, oldName );
+ bufferQuoteQualifiedIdentifier(buf, schema, oldName, m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("SET SCHEMA" ) );
- bufferQuoteIdentifier( buf, newSchemaName );
+ bufferQuoteIdentifier( buf, newSchemaName, m_pSettings );
Reference< XStatement > statement = m_conn->createStatement();
statement->executeUpdate( buf.makeStringAndClear() );
setPropertyValue_NoBroadcast_public( st.SCHEMA_NAME, makeAny(newSchemaName) );
@@ -194,9 +194,9 @@ void View::rename( const ::rtl::OUString& newName )
{
OUStringBuffer buf(128);
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER TABLE" ) );
- bufferQuoteQualifiedIdentifier( buf, schema, oldName );
+ bufferQuoteQualifiedIdentifier( buf, schema, oldName, m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("RENAME TO" ) );
- bufferQuoteIdentifier( buf, newTableName );
+ bufferQuoteIdentifier( buf, newTableName, m_pSettings );
Reference< XStatement > statement = m_conn->createStatement();
statement->executeUpdate( buf.makeStringAndClear() );
setPropertyValue_NoBroadcast_public( st.NAME, makeAny(newTableName) );
diff --git a/connectivity/source/drivers/postgresql/pq_xviews.cxx b/connectivity/source/drivers/postgresql/pq_xviews.cxx
index df6c13a02bcc..7f95e6a2deff 100644
--- a/connectivity/source/drivers/postgresql/pq_xviews.cxx
+++ b/connectivity/source/drivers/postgresql/pq_xviews.cxx
@@ -194,7 +194,7 @@ void Views::appendByDescriptor(
OUStringBuffer buf( 128 );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "CREATE VIEW " ) );
- bufferQuoteQualifiedIdentifier( buf, schema, name );
+ bufferQuoteQualifiedIdentifier( buf, schema, name, m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " AS " ) );
buf.append( command );