tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / forms / source / component / cachedrowset.cxx
bloba2cfaf252903a42ab6c2e61b44484b01a8cd1e9a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "cachedrowset.hxx"
22 #include <frm_strings.hxx>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
26 #include <com/sun/star/sdbc/SQLException.hpp>
27 #include <com/sun/star/sdbc/ResultSetType.hpp>
29 #include <comphelper/diagnose_ex.hxx>
32 namespace frm
36 using ::com::sun::star::uno::Reference;
37 using ::com::sun::star::uno::UNO_QUERY_THROW;
38 using ::com::sun::star::uno::UNO_SET_THROW;
39 using ::com::sun::star::uno::Exception;
40 using ::com::sun::star::sdbc::XConnection;
41 using ::com::sun::star::beans::XPropertySet;
42 using ::com::sun::star::uno::Any;
43 using ::com::sun::star::sdbc::SQLException;
44 using ::com::sun::star::sdb::XQueriesSupplier;
45 using ::com::sun::star::container::XNameAccess;
46 using ::com::sun::star::sdbc::XResultSet;
47 using ::com::sun::star::sdbc::XStatement;
49 namespace ResultSetType = ::com::sun::star::sdbc::ResultSetType;
51 struct CachedRowSet_Data
53 OUString sCommand;
54 bool bEscapeProcessing;
55 Reference< XConnection > xConnection;
57 bool bStatementDirty;
59 CachedRowSet_Data()
60 :bEscapeProcessing( false )
61 ,bStatementDirty( true )
66 CachedRowSet::CachedRowSet()
67 :m_pData( new CachedRowSet_Data )
72 CachedRowSet::~CachedRowSet()
74 dispose();
78 void CachedRowSet::setCommand( const OUString& _rCommand )
80 if ( m_pData->sCommand == _rCommand )
81 return;
83 m_pData->sCommand = _rCommand;
84 m_pData->bStatementDirty = true;
88 void CachedRowSet::setCommandFromQuery( const OUString& _rQueryName )
90 Reference< XQueriesSupplier > xSupplyQueries( m_pData->xConnection, UNO_QUERY_THROW );
91 Reference< XNameAccess > xQueries ( xSupplyQueries->getQueries(), UNO_SET_THROW );
92 Reference< XPropertySet > xQuery ( xQueries->getByName( _rQueryName ), UNO_QUERY_THROW );
94 bool bEscapeProcessing( false );
95 OSL_VERIFY( xQuery->getPropertyValue( PROPERTY_ESCAPE_PROCESSING ) >>= bEscapeProcessing );
96 setEscapeProcessing( bEscapeProcessing );
98 OUString sCommand;
99 OSL_VERIFY( xQuery->getPropertyValue( PROPERTY_COMMAND ) >>= sCommand );
100 setCommand( sCommand );
104 void CachedRowSet::setEscapeProcessing ( const bool _bEscapeProcessing )
106 if ( m_pData->bEscapeProcessing == _bEscapeProcessing )
107 return;
109 m_pData->bEscapeProcessing = _bEscapeProcessing;
110 m_pData->bStatementDirty = true;
114 void CachedRowSet::setConnection( const Reference< XConnection >& _rxConnection )
116 if ( m_pData->xConnection == _rxConnection )
117 return;
119 m_pData->xConnection = _rxConnection;
120 m_pData->bStatementDirty = true;
124 Reference< XResultSet > CachedRowSet::execute()
126 Reference< XResultSet > xResult;
129 OSL_PRECOND( m_pData->xConnection.is(), "CachedRowSet::execute: how am I expected to do this without a connection?" );
130 if ( !m_pData->xConnection.is() )
131 return xResult;
133 Reference< XStatement > xStatement( m_pData->xConnection->createStatement(), UNO_SET_THROW );
134 Reference< XPropertySet > xStatementProps( xStatement, UNO_QUERY_THROW );
135 xStatementProps->setPropertyValue( PROPERTY_ESCAPE_PROCESSING, Any( m_pData->bEscapeProcessing ) );
136 xStatementProps->setPropertyValue( PROPERTY_RESULTSET_TYPE, Any( ResultSetType::FORWARD_ONLY ) );
138 xResult.set( xStatement->executeQuery( m_pData->sCommand ), UNO_SET_THROW );
139 m_pData->bStatementDirty = false;
141 catch( const SQLException& )
143 throw;
145 catch( const Exception& )
147 DBG_UNHANDLED_EXCEPTION("forms.component");
149 return xResult;
153 bool CachedRowSet::isDirty() const
155 return m_pData->bStatementDirty;
159 void CachedRowSet::dispose()
163 m_pData.reset( new CachedRowSet_Data );
165 catch( const Exception& )
167 DBG_UNHANDLED_EXCEPTION("forms.component");
172 } // namespace frm
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */