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,
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 ************************************************************************/
39 #include "pq_sequenceresultset.hxx"
40 #include "pq_resultsetmetadata.hxx"
42 #include <com/sun/star/sdbc/FetchDirection.hpp>
43 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
44 #include <com/sun/star/sdbc/ResultSetType.hpp>
45 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
46 #include <com/sun/star/sdbc/XRowUpdate.hpp>
49 namespace pq_sdbc_driver
52 struct UpdateableField
61 typedef std::vector
< UpdateableField
> UpdateableFieldVector
;
63 class UpdateableResultSet final
:
64 public SequenceResultSet
,
65 public css::sdbc::XResultSetUpdate
,
66 public css::sdbc::XRowUpdate
68 ConnectionSettings
**m_ppSettings
;
71 std::vector
< OUString
> m_primaryKey
;
72 UpdateableFieldVector m_updateableField
;
77 const ::rtl::Reference
< comphelper::RefCountedMutex
> & mutex
,
78 const css::uno::Reference
< css::uno::XInterface
> &owner
,
79 std::vector
< OUString
>&& colNames
,
80 std::vector
< std::vector
< css::uno::Any
> >&& data
,
81 ConnectionSettings
**ppSettings
,
84 std::vector
< OUString
>&& primaryKey
)
85 : SequenceResultSet( mutex
, owner
, std::move(colNames
), std::move(data
), (*ppSettings
)->tc
),
86 m_ppSettings( ppSettings
),
87 m_schema(std::move( schema
)),
88 m_table(std::move( table
)),
89 m_primaryKey( std::move(primaryKey
) ),
92 // LEM TODO: this duplicates code in pq_resultset.cxx, except for different value
93 // of ResultSetConcurrency. Baaad.
94 // Why is an updatable ResultSet a sequenceresultset in the first place?
95 // This seems to imply that the whole data is fetched once and kept in memory. BAAAAD.
96 // LEM TODO: shouldn't these things be inherited from the statement or something like that?
97 // Positioned update/delete not supported, so no cursor name
98 // Fetch direction and size are cursor-specific things, so not used now.
100 m_props
[ BASERESULTSET_FETCH_DIRECTION
] <<= css::sdbc::FetchDirection::UNKNOWN
;
101 // No escape processing for now
102 m_props
[ BASERESULTSET_ESCAPE_PROCESSING
] <<= false;
103 // Bookmarks not implemented for now
104 m_props
[ BASERESULTSET_IS_BOOKMARKABLE
] <<= false;
105 m_props
[ BASERESULTSET_RESULT_SET_CONCURRENCY
] <<=
106 css::sdbc::ResultSetConcurrency::UPDATABLE
;
107 m_props
[ BASERESULTSET_RESULT_SET_TYPE
] <<=
108 css::sdbc::ResultSetType::SCROLL_INSENSITIVE
;
111 OUString
buildWhereClause();
112 void checkUpdate( sal_Int32 column
);
115 static css::uno::Reference
< css::sdbc::XCloseable
> createFromPGResultSet(
116 const ::rtl::Reference
< comphelper::RefCountedMutex
> & mutex
,
117 const css::uno::Reference
< css::uno::XInterface
> &owner
,
118 ConnectionSettings
**ppSettings
,
120 const OUString
&schema
,
121 const OUString
&table
,
122 std::vector
< OUString
> && primaryKey
);
124 public: // XInterface
125 virtual void SAL_CALL
acquire() noexcept override
{ SequenceResultSet::acquire(); }
126 virtual void SAL_CALL
release() noexcept override
{ SequenceResultSet::release(); }
127 virtual css::uno::Any SAL_CALL
queryInterface(
128 const css::uno::Type
& reqType
) override
;
130 public: // XTypeProvider
131 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes() override
;
132 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId() override
;
134 public: // XResultSetUpdate
135 virtual void SAL_CALL
insertRow( ) override
;
136 virtual void SAL_CALL
updateRow( ) override
;
137 virtual void SAL_CALL
deleteRow( ) override
;
138 virtual void SAL_CALL
cancelRowUpdates( ) override
;
139 virtual void SAL_CALL
moveToInsertRow( ) override
;
140 virtual void SAL_CALL
moveToCurrentRow( ) override
;
142 public: // XRowUpdate
143 virtual void SAL_CALL
updateNull( sal_Int32 columnIndex
) override
;
144 virtual void SAL_CALL
updateBoolean( sal_Int32 columnIndex
, sal_Bool x
) override
;
145 virtual void SAL_CALL
updateByte( sal_Int32 columnIndex
, sal_Int8 x
) override
;
146 virtual void SAL_CALL
updateShort( sal_Int32 columnIndex
, sal_Int16 x
) override
;
147 virtual void SAL_CALL
updateInt( sal_Int32 columnIndex
, sal_Int32 x
) override
;
148 virtual void SAL_CALL
updateLong( sal_Int32 columnIndex
, sal_Int64 x
) override
;
149 virtual void SAL_CALL
updateFloat( sal_Int32 columnIndex
, float x
) override
;
150 virtual void SAL_CALL
updateDouble( sal_Int32 columnIndex
, double x
) override
;
151 virtual void SAL_CALL
updateString( sal_Int32 columnIndex
, const OUString
& x
) override
;
152 virtual void SAL_CALL
updateBytes( sal_Int32 columnIndex
, const css::uno::Sequence
< sal_Int8
>& x
) override
;
153 virtual void SAL_CALL
updateDate( sal_Int32 columnIndex
, const css::util::Date
& x
) override
;
154 virtual void SAL_CALL
updateTime( sal_Int32 columnIndex
, const css::util::Time
& x
) override
;
155 virtual void SAL_CALL
updateTimestamp( sal_Int32 columnIndex
, const css::util::DateTime
& x
) override
;
156 virtual void SAL_CALL
updateBinaryStream( sal_Int32 columnIndex
, const css::uno::Reference
< css::io::XInputStream
>& x
, sal_Int32 length
) override
;
157 virtual void SAL_CALL
updateCharacterStream( sal_Int32 columnIndex
, const css::uno::Reference
< css::io::XInputStream
>& x
, sal_Int32 length
) override
;
158 virtual void SAL_CALL
updateObject( sal_Int32 columnIndex
, const css::uno::Any
& x
) override
;
159 virtual void SAL_CALL
updateNumericObject( sal_Int32 columnIndex
, const css::uno::Any
& x
, sal_Int32 scale
) override
;
162 /// @throws css::uno::RuntimeException
163 static css::uno::Sequence
< css::uno::Type
> getStaticTypes( bool updateable
);
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */