Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / postgresql / pq_updateableresultset.hxx
blob6afc1dd3da08dd22fca5d497a008f6c349e1ee4e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * Effective License of whole file:
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License version 2.1, as published by the Free Software Foundation.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18 * MA 02111-1307 USA
20 * Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
22 * The Contents of this file are made available subject to the terms of
23 * the GNU Lesser General Public License Version 2.1
25 * Copyright: 200? by Sun Microsystems, Inc.
27 * Contributor(s): Joerg Budischewski
29 * All parts contributed on or after August 2011:
31 * This Source Code Form is subject to the terms of the Mozilla Public
32 * License, v. 2.0. If a copy of the MPL was not distributed with this
33 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
35 ************************************************************************/
37 #include "pq_sequenceresultset.hxx"
38 #include "pq_resultsetmetadata.hxx"
40 #include <com/sun/star/sdbc/FetchDirection.hpp>
41 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
42 #include <com/sun/star/sdbc/ResultSetType.hpp>
43 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
44 #include <com/sun/star/sdbc/XRowUpdate.hpp>
46 namespace pq_sdbc_driver
49 struct UpdateableField
51 UpdateableField( )
52 : isTouched(false)
54 com::sun::star::uno::Any value;
55 bool isTouched;
58 typedef ::std::vector< UpdateableField > UpdateableFieldVector;
60 class UpdateableResultSet :
61 public SequenceResultSet,
62 public com::sun::star::sdbc::XResultSetUpdate,
63 public com::sun::star::sdbc::XRowUpdate
65 ConnectionSettings **m_ppSettings;
66 OUString m_schema;
67 OUString m_table;
68 com::sun::star::uno::Sequence< OUString > m_primaryKey;
69 UpdateableFieldVector m_updateableField;
70 com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSetMetaData > m_meta;
71 bool m_insertRow;
73 protected:
74 UpdateableResultSet(
75 const ::rtl::Reference< RefCountedMutex > & mutex,
76 const com::sun::star::uno::Reference< com::sun::star::uno::XInterface > &owner,
77 const com::sun::star::uno::Sequence< OUString > &colNames,
78 const com::sun::star::uno::Sequence< com::sun::star::uno::Sequence< com::sun::star::uno::Any > > &data,
79 ConnectionSettings **ppSettings,
80 const OUString &schema,
81 const OUString &table,
82 const com::sun::star::uno::Sequence< OUString > &primaryKey)
83 : SequenceResultSet( mutex, owner, colNames, data, (*ppSettings)->tc ),
84 m_ppSettings( ppSettings ),
85 m_schema( schema ),
86 m_table( table ),
87 m_primaryKey( primaryKey ),
88 m_insertRow( false )
90 // LEM TODO: this duplicates code in pq_resultset.cxx, except for different value
91 // of ResultSetConcurrency. Baaad.
92 // Why is an updatable ResultSet a sequenceresultset in the first place?
93 // This seems to imply that the whole data is fetched once and kept in memory. BAAAAD.
94 // LEM TODO: shouldn't these things be inherited from the statement or something like that?
95 sal_Bool b = sal_False;
96 // Positioned update/delete not supported, so no cursor name
97 // Fetch direction and size are cursor-specific things, so not used now.
98 // Fetch size not set
99 m_props[ BASERESULTSET_FETCH_DIRECTION ] = com::sun::star::uno::makeAny(
100 com::sun::star::sdbc::FetchDirection::UNKNOWN);
101 // No escape processing for now
102 m_props[ BASERESULTSET_ESCAPE_PROCESSING ] = com::sun::star::uno::Any( &b, getBooleanCppuType() );
103 // Bookmarks not implemented for now
104 m_props[ BASERESULTSET_IS_BOOKMARKABLE ] = com::sun::star::uno::Any( &b, getBooleanCppuType() );
105 m_props[ BASERESULTSET_RESULT_SET_CONCURRENCY ] = com::sun::star::uno::makeAny(
106 com::sun::star::sdbc::ResultSetConcurrency::UPDATABLE );
107 m_props[ BASERESULTSET_RESULT_SET_TYPE ] = com::sun::star::uno::makeAny(
108 com::sun::star::sdbc::ResultSetType::SCROLL_INSENSITIVE );
111 OUString buildWhereClause();
112 void checkUpdate( sal_Int32 column );
114 public:
115 static com::sun::star::uno::Reference< com::sun::star::sdbc::XCloseable > createFromPGResultSet(
116 const ::rtl::Reference< RefCountedMutex > & mutex,
117 const com::sun::star::uno::Reference< com::sun::star::uno::XInterface > &owner,
118 ConnectionSettings **ppSettings,
119 PGresult *result,
120 const OUString &schema,
121 const OUString &table,
122 const com::sun::star::uno::Sequence< OUString > &primaryKey );
124 public: // XInterface
125 virtual void SAL_CALL acquire() throw() SAL_OVERRIDE { SequenceResultSet::acquire(); }
126 virtual void SAL_CALL release() throw() SAL_OVERRIDE { SequenceResultSet::release(); }
127 virtual com::sun::star::uno::Any SAL_CALL queryInterface(
128 const com::sun::star::uno::Type & reqType )
129 throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
131 public: // XTypeProvider
132 virtual com::sun::star::uno::Sequence< com::sun::star::uno::Type > SAL_CALL getTypes()
133 throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
134 virtual com::sun::star::uno::Sequence< sal_Int8> SAL_CALL getImplementationId()
135 throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
137 public: // XResultSetUpdate
138 virtual void SAL_CALL insertRow( ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
139 virtual void SAL_CALL updateRow( ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
140 virtual void SAL_CALL deleteRow( ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
141 virtual void SAL_CALL cancelRowUpdates( ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
142 virtual void SAL_CALL moveToInsertRow( ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
143 virtual void SAL_CALL moveToCurrentRow( ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
145 public: // XRowUpdate
146 virtual void SAL_CALL updateNull( sal_Int32 columnIndex ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
147 virtual void SAL_CALL updateBoolean( sal_Int32 columnIndex, sal_Bool x ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
148 virtual void SAL_CALL updateByte( sal_Int32 columnIndex, sal_Int8 x ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
149 virtual void SAL_CALL updateShort( sal_Int32 columnIndex, sal_Int16 x ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
150 virtual void SAL_CALL updateInt( sal_Int32 columnIndex, sal_Int32 x ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
151 virtual void SAL_CALL updateLong( sal_Int32 columnIndex, sal_Int64 x ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
152 virtual void SAL_CALL updateFloat( sal_Int32 columnIndex, float x ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
153 virtual void SAL_CALL updateDouble( sal_Int32 columnIndex, double x ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
154 virtual void SAL_CALL updateString( sal_Int32 columnIndex, const OUString& x ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
155 virtual void SAL_CALL updateBytes( sal_Int32 columnIndex, const ::com::sun::star::uno::Sequence< sal_Int8 >& x ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
156 virtual void SAL_CALL updateDate( sal_Int32 columnIndex, const ::com::sun::star::util::Date& x ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
157 virtual void SAL_CALL updateTime( sal_Int32 columnIndex, const ::com::sun::star::util::Time& x ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
158 virtual void SAL_CALL updateTimestamp( sal_Int32 columnIndex, const ::com::sun::star::util::DateTime& x ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
159 virtual void SAL_CALL updateBinaryStream( sal_Int32 columnIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
160 virtual void SAL_CALL updateCharacterStream( sal_Int32 columnIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
161 virtual void SAL_CALL updateObject( sal_Int32 columnIndex, const ::com::sun::star::uno::Any& x ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
162 virtual void SAL_CALL updateNumericObject( sal_Int32 columnIndex, const ::com::sun::star::uno::Any& x, sal_Int32 scale ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
164 public: // XResultSetMetaDataSupplier
165 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData > SAL_CALL getMetaData( )
166 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
169 static com::sun::star::uno::Sequence< com::sun::star::uno::Type > getStaticTypes( bool updateable )
170 throw( com::sun::star::uno::RuntimeException );
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */