39#include <rtl/ustrbuf.hxx>
43#include <com/sun/star/sdbc/SQLException.hpp>
44#include <com/sun/star/sdbc/XGeneratedResultSet.hpp>
60using com::sun::star::uno::UNO_QUERY;
61using com::sun::star::uno::Any;
62using com::sun::star::uno::Type;
64using com::sun::star::sdbc::XGeneratedResultSet;
65using com::sun::star::sdbc::XResultSetMetaDataSupplier;
66using com::sun::star::sdbc::SQLException;
67using com::sun::star::sdbc::XResultSet;
68using com::sun::star::sdbc::XCloseable;
69using com::sun::star::sdbc::XColumnLocate;
70using com::sun::star::sdbc::XResultSetUpdate;
71using com::sun::star::sdbc::XRowUpdate;
72using com::sun::star::sdbc::XRow;
73using com::sun::star::sdbc::XStatement;
75using com::sun::star::beans::XFastPropertySet;
77using com::sun::star::beans::XMultiPropertySet;
86 const ::rtl::Reference< comphelper::RefCountedMutex > & mutex,
87 const css::uno::Reference< css::uno::XInterface > &owner,
90 const OUString &schema,
91 const OUString &table,
92 std::vector< OUString > && primaryKey )
94 sal_Int32 columnCount = PQnfields(
result );
95 sal_Int32 rowCount = PQntuples(
result );
96 std::vector< OUString > columnNames( columnCount );
97 for(
int i = 0 ;
i < columnCount ;
i ++ )
102 std::vector< std::vector< Any > > data( rowCount );
106 for(
int row = 0 ; row < rowCount ; row ++ )
108 std::vector< Any > aRow( columnCount );
109 for(
int col = 0 ;
col < columnCount ;
col ++ )
113 char * val = PQgetvalue(
result, row,
col );
123 mutex, owner, std::move(columnNames), std::move(data), ppSettings, schema,
table, std::move(primaryKey) );
133 const css::uno::Type & reqType )
136 if( ! ret.hasValue() )
137 ret = ::cppu::queryInterface(
139 static_cast< XResultSetUpdate *
> (
this ),
140 static_cast< XRowUpdate *
> (
this ) );
158 return css::uno::Sequence<sal_Int8>();
166 OUStringBuffer buf( 128 );
167 buf.append(
" WHERE " );
171 buf.append(
" AND " );
177 ret = buf.makeStringAndClear();
185 MutexGuard guard(
m_xMutex->GetMutex() );
186 SAL_INFO(
"connectivity.postgresql",
"UpdateableResultSet::insertRow() got called");
190 "pq_resultset.insertRow: moveToInsertRow has not been called !",
191 *
this, OUString(), 1,
Any() );
193 OUStringBuffer buf( 128 );
194 buf.append(
"INSERT INTO " );
209 buf.append(
" ) VALUES ( " );
233 stmt->executeUpdate( buf.makeStringAndClear() );
243 if( rs.is() && rs->next() )
277 MutexGuard guard(
m_xMutex->GetMutex() );
278 SAL_INFO(
"connectivity.postgresql",
"UpdateableResultSet::updateRow() got called");
282 "pq_resultset.updateRow: moveToCurrentRow has not been called !",
283 *
this, OUString(), 1,
Any() );
285 OUStringBuffer buf( 128 );
286 buf.append(
"UPDATE " );
288 buf.append(
"SET " );
312 stmt->executeUpdate( buf.makeStringAndClear() );
325 SAL_INFO(
"connectivity.postgresql",
"UpdateableResultSet::deleteRow() got called");
329 "pq_resultset.deleteRow: deleteRow cannot be called when on insert row !",
330 *
this, OUString(), 1,
Any() );
335 "deleteRow cannot be called on invalid row ("
336 + OUString::number(
m_row) +
")",
337 *
this, OUString(), 0,
Any() );
342 OUStringBuffer buf( 128 );
343 buf.append(
"DELETE FROM " );
348 stmt->executeUpdate( buf.makeStringAndClear() );
361 MutexGuard guard(
m_xMutex->GetMutex() );
385 MutexGuard guard(
m_xMutex->GetMutex() );
393 MutexGuard guard(
m_xMutex->GetMutex() );
425 MutexGuard guard(
m_xMutex->GetMutex() );
439 MutexGuard guard(
m_xMutex->GetMutex() );
448 MutexGuard guard(
m_xMutex->GetMutex() );
457 MutexGuard guard(
m_xMutex->GetMutex() );
466 MutexGuard guard(
m_xMutex->GetMutex() );
471 unsigned char * escapedString =
472 PQescapeBytea(
reinterpret_cast<unsigned char const *
>(
x.getConstArray()),
x.getLength(), &len);
473 if( ! escapedString )
476 "pq_preparedstatement.setBytes: Error during converting bytesequence to an SQL conform string",
477 *
this, OUString(), 1,
Any() );
482 OUString(
reinterpret_cast<char*
>(escapedString), len, RTL_TEXTENCODING_ASCII_US );
483 PQfreemem( escapedString );
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
css::uno::Reference< css::uno::XInterface > m_owner
::rtl::Reference< comphelper::RefCountedMutex > m_xMutex
void checkColumnIndex(sal_Int32 index)
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &reqType) override
virtual OUString SAL_CALL getString(sal_Int32 columnIndex) override
std::vector< std::vector< css::uno::Any > > m_data
virtual void checkClosed() override
mutex should be locked before called
virtual sal_Int32 SAL_CALL findColumn(const OUString &columnName) override
std::vector< OUString > m_columnNames
static css::uno::Reference< css::sdbc::XCloseable > createFromPGResultSet(const ::rtl::Reference< comphelper::RefCountedMutex > &mutex, const css::uno::Reference< css::uno::XInterface > &owner, ConnectionSettings **ppSettings, PGresult *result, const OUString &schema, const OUString &table, std::vector< OUString > &&primaryKey)
virtual void SAL_CALL updateString(sal_Int32 columnIndex, const OUString &x) override
ConnectionSettings ** m_ppSettings
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &reqType) override
void checkUpdate(sal_Int32 column)
virtual void SAL_CALL updateDouble(sal_Int32 columnIndex, double x) override
virtual void SAL_CALL updateRow() override
virtual void SAL_CALL updateNumericObject(sal_Int32 columnIndex, const css::uno::Any &x, sal_Int32 scale) override
virtual void SAL_CALL moveToCurrentRow() override
UpdateableResultSet(const ::rtl::Reference< comphelper::RefCountedMutex > &mutex, const css::uno::Reference< css::uno::XInterface > &owner, std::vector< OUString > &&colNames, std::vector< std::vector< css::uno::Any > > &&data, ConnectionSettings **ppSettings, OUString schema, OUString table, std::vector< OUString > &&primaryKey)
virtual void SAL_CALL updateByte(sal_Int32 columnIndex, sal_Int8 x) override
static css::uno::Sequence< css::uno::Type > getStaticTypes(bool updateable)
virtual void SAL_CALL updateTimestamp(sal_Int32 columnIndex, const css::util::DateTime &x) override
virtual void SAL_CALL updateCharacterStream(sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream > &x, sal_Int32 length) override
virtual void SAL_CALL updateObject(sal_Int32 columnIndex, const css::uno::Any &x) override
virtual void SAL_CALL deleteRow() override
virtual void SAL_CALL cancelRowUpdates() override
virtual void SAL_CALL updateDate(sal_Int32 columnIndex, const css::util::Date &x) override
virtual void SAL_CALL updateBoolean(sal_Int32 columnIndex, sal_Bool x) override
virtual void SAL_CALL updateInt(sal_Int32 columnIndex, sal_Int32 x) override
virtual void SAL_CALL insertRow() override
OUString buildWhereClause()
UpdateableFieldVector m_updateableField
virtual void SAL_CALL updateLong(sal_Int32 columnIndex, sal_Int64 x) override
virtual void SAL_CALL updateFloat(sal_Int32 columnIndex, float x) override
virtual void SAL_CALL updateShort(sal_Int32 columnIndex, sal_Int16 x) override
std::vector< OUString > m_primaryKey
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual void SAL_CALL moveToInsertRow() override
virtual void SAL_CALL updateBinaryStream(sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream > &x, sal_Int32 length) override
virtual void SAL_CALL updateTime(sal_Int32 columnIndex, const css::util::Time &x) override
virtual void SAL_CALL updateNull(sal_Int32 columnIndex) override
virtual void SAL_CALL updateBytes(sal_Int32 columnIndex, const css::uno::Sequence< sal_Int8 > &x) override
#define SAL_INFO(area, stream)
RttiCompleteObjectLocator col
class SAL_NO_VTABLE XPropertySet
void bufferQuoteConstant(OUStringBuffer &buf, std::u16string_view value, ConnectionSettings *settings)
void bufferQuoteQualifiedIdentifier(OUStringBuffer &buf, std::u16string_view schema, std::u16string_view table, ConnectionSettings *settings)
std::vector< UpdateableField > UpdateableFieldVector
void bufferQuoteAnyConstant(OUStringBuffer &buf, const Any &val, ConnectionSettings *settings)
Reference< XConnection > extractConnectionFromStatement(const Reference< XInterface > &stmt)
void bufferQuoteIdentifier(OUStringBuffer &buf, std::u16string_view toQuote, ConnectionSettings *settings)
static const rtl_TextEncoding encoding