1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  *  The Contents of this file are made available subject to the terms of
4*cdf0e10cSrcweir  *  the BSD license.
5*cdf0e10cSrcweir  *
6*cdf0e10cSrcweir  *  Copyright 2000, 2010 Oracle and/or its affiliates.
7*cdf0e10cSrcweir  *  All rights reserved.
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  *  Redistribution and use in source and binary forms, with or without
10*cdf0e10cSrcweir  *  modification, are permitted provided that the following conditions
11*cdf0e10cSrcweir  *  are met:
12*cdf0e10cSrcweir  *  1. Redistributions of source code must retain the above copyright
13*cdf0e10cSrcweir  *     notice, this list of conditions and the following disclaimer.
14*cdf0e10cSrcweir  *  2. Redistributions in binary form must reproduce the above copyright
15*cdf0e10cSrcweir  *     notice, this list of conditions and the following disclaimer in the
16*cdf0e10cSrcweir  *     documentation and/or other materials provided with the distribution.
17*cdf0e10cSrcweir  *  3. Neither the name of Sun Microsystems, Inc. nor the names of its
18*cdf0e10cSrcweir  *     contributors may be used to endorse or promote products derived
19*cdf0e10cSrcweir  *     from this software without specific prior written permission.
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22*cdf0e10cSrcweir  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23*cdf0e10cSrcweir  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24*cdf0e10cSrcweir  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25*cdf0e10cSrcweir  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26*cdf0e10cSrcweir  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27*cdf0e10cSrcweir  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28*cdf0e10cSrcweir  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29*cdf0e10cSrcweir  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30*cdf0e10cSrcweir  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31*cdf0e10cSrcweir  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32*cdf0e10cSrcweir  *
33*cdf0e10cSrcweir  *************************************************************************/
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include "SConnection.hxx"
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include "SDatabaseMetaData.hxx"
38*cdf0e10cSrcweir #include "SDriver.hxx"
39*cdf0e10cSrcweir #include "SStatement.hxx"
40*cdf0e10cSrcweir #include "SPreparedStatement.hxx"
41*cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnValue.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/sdbc/TransactionIsolation.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir using namespace connectivity::skeleton;
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir //------------------------------------------------------------------------------
49*cdf0e10cSrcweir using namespace com::sun::star::uno;
50*cdf0e10cSrcweir using namespace com::sun::star::lang;
51*cdf0e10cSrcweir using namespace com::sun::star::beans;
52*cdf0e10cSrcweir using namespace com::sun::star::sdbc;
53*cdf0e10cSrcweir // --------------------------------------------------------------------------------
54*cdf0e10cSrcweir OConnection::OConnection(SkeletonDriver*	_pDriver)
55*cdf0e10cSrcweir 						 : OSubComponent<OConnection, OConnection_BASE>((::cppu::OWeakObject*)_pDriver, this),
56*cdf0e10cSrcweir 						 OMetaConnection_BASE(m_aMutex),
57*cdf0e10cSrcweir 						 m_pDriver(_pDriver),
58*cdf0e10cSrcweir 						 m_bClosed(sal_False),
59*cdf0e10cSrcweir 						 m_xMetaData(NULL),
60*cdf0e10cSrcweir 						 m_bUseCatalog(sal_False),
61*cdf0e10cSrcweir 						 m_bUseOldDateFormat(sal_False)
62*cdf0e10cSrcweir {
63*cdf0e10cSrcweir 	m_pDriver->acquire();
64*cdf0e10cSrcweir }
65*cdf0e10cSrcweir //-----------------------------------------------------------------------------
66*cdf0e10cSrcweir OConnection::~OConnection()
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir 	if(!isClosed())
69*cdf0e10cSrcweir 		close();
70*cdf0e10cSrcweir 	m_pDriver->release();
71*cdf0e10cSrcweir 	m_pDriver = NULL;
72*cdf0e10cSrcweir }
73*cdf0e10cSrcweir //-----------------------------------------------------------------------------
74*cdf0e10cSrcweir void SAL_CALL OConnection::release() throw()
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir 	relase_ChildImpl();
77*cdf0e10cSrcweir }
78*cdf0e10cSrcweir // -----------------------------------------------------------------------------
79*cdf0e10cSrcweir //-----------------------------------------------------------------------------
80*cdf0e10cSrcweir void OConnection::construct(const ::rtl::OUString& url,const Sequence< PropertyValue >& info)  throw(SQLException)
81*cdf0e10cSrcweir {
82*cdf0e10cSrcweir 	osl_incrementInterlockedCount( &m_refCount );
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 	// some example code how to get the information out of the sequence
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir 	sal_Int32 nLen = url.indexOf(':');
87*cdf0e10cSrcweir 	nLen = url.indexOf(':',nLen+1);
88*cdf0e10cSrcweir 	::rtl::OUString aDSN(RTL_CONSTASCII_USTRINGPARAM("DSN=")), aUID, aPWD, aSysDrvSettings;
89*cdf0e10cSrcweir 	aDSN += url.copy(nLen+1);
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 	const char* pUser		= "user";
92*cdf0e10cSrcweir 	const char* pTimeout	= "Timeout";
93*cdf0e10cSrcweir 	const char* pSilent		= "Silent";
94*cdf0e10cSrcweir 	const char* pPwd		= "password";
95*cdf0e10cSrcweir 	const char* pUseCatalog = "UseCatalog";
96*cdf0e10cSrcweir 	const char* pSysDrv		= "SystemDriverSettings";
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 	sal_Int32 nTimeout = 20;
99*cdf0e10cSrcweir 	sal_Bool bSilent = sal_True;
100*cdf0e10cSrcweir 	const PropertyValue *pBegin	= info.getConstArray();
101*cdf0e10cSrcweir 	const PropertyValue *pEnd	= pBegin + info.getLength();
102*cdf0e10cSrcweir 	for(;pBegin != pEnd;++pBegin)
103*cdf0e10cSrcweir 	{
104*cdf0e10cSrcweir 		if(!pBegin->Name.compareToAscii(pTimeout))
105*cdf0e10cSrcweir 			pBegin->Value >>= nTimeout;
106*cdf0e10cSrcweir 		else if(!pBegin->Name.compareToAscii(pSilent))
107*cdf0e10cSrcweir 			pBegin->Value >>= bSilent;
108*cdf0e10cSrcweir 		else if(!pBegin->Name.compareToAscii(pUser))
109*cdf0e10cSrcweir 		{
110*cdf0e10cSrcweir 			pBegin->Value >>= aUID;
111*cdf0e10cSrcweir 			aDSN = aDSN + ::rtl::OUString::createFromAscii(";UID=") + aUID;
112*cdf0e10cSrcweir 		}
113*cdf0e10cSrcweir 		else if(!pBegin->Name.compareToAscii(pPwd))
114*cdf0e10cSrcweir 		{
115*cdf0e10cSrcweir 			pBegin->Value >>= aPWD;
116*cdf0e10cSrcweir 			aDSN = aDSN + ::rtl::OUString::createFromAscii(";PWD=") + aPWD;
117*cdf0e10cSrcweir 		}
118*cdf0e10cSrcweir 		else if(!pBegin->Name.compareToAscii(pUseCatalog))
119*cdf0e10cSrcweir 		{
120*cdf0e10cSrcweir 			pBegin->Value >>= m_bUseCatalog;
121*cdf0e10cSrcweir 		}
122*cdf0e10cSrcweir 		else if(!pBegin->Name.compareToAscii(pSysDrv))
123*cdf0e10cSrcweir 		{
124*cdf0e10cSrcweir 			pBegin->Value >>= aSysDrvSettings;
125*cdf0e10cSrcweir 			aDSN += ::rtl::OUString::createFromAscii(";");
126*cdf0e10cSrcweir 			aDSN += aSysDrvSettings;
127*cdf0e10cSrcweir 		}
128*cdf0e10cSrcweir 	}
129*cdf0e10cSrcweir 	m_sUser = aUID;
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 	osl_decrementInterlockedCount( &m_refCount );
132*cdf0e10cSrcweir }
133*cdf0e10cSrcweir // XServiceInfo
134*cdf0e10cSrcweir // --------------------------------------------------------------------------------
135*cdf0e10cSrcweir IMPLEMENT_SERVICE_INFO(OConnection, "com.sun.star.sdbc.drivers.skeleton.OConnection", "com.sun.star.sdbc.Connection")
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir // --------------------------------------------------------------------------------
138*cdf0e10cSrcweir Reference< XStatement > SAL_CALL OConnection::createStatement(  ) throw(SQLException, RuntimeException)
139*cdf0e10cSrcweir {
140*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
141*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir 	// create a statement
144*cdf0e10cSrcweir 	// the statement can only be executed once
145*cdf0e10cSrcweir 	Reference< XStatement > xReturn = new OStatement(this);
146*cdf0e10cSrcweir 	m_aStatements.push_back(WeakReferenceHelper(xReturn));
147*cdf0e10cSrcweir 	return xReturn;
148*cdf0e10cSrcweir }
149*cdf0e10cSrcweir // --------------------------------------------------------------------------------
150*cdf0e10cSrcweir Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement( const ::rtl::OUString& _sSql ) throw(SQLException, RuntimeException)
151*cdf0e10cSrcweir {
152*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
153*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 	// the pre
156*cdf0e10cSrcweir 	if(m_aTypeInfo.empty())
157*cdf0e10cSrcweir 		buildTypeInfo();
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 	// create a statement
160*cdf0e10cSrcweir 	// the statement can only be executed more than once
161*cdf0e10cSrcweir 	Reference< XPreparedStatement > xReturn = new OPreparedStatement(this,m_aTypeInfo,_sSql);
162*cdf0e10cSrcweir 	m_aStatements.push_back(WeakReferenceHelper(xReturn));
163*cdf0e10cSrcweir 	return xReturn;
164*cdf0e10cSrcweir }
165*cdf0e10cSrcweir // --------------------------------------------------------------------------------
166*cdf0e10cSrcweir Reference< XPreparedStatement > SAL_CALL OConnection::prepareCall( const ::rtl::OUString& _sSql ) throw(SQLException, RuntimeException)
167*cdf0e10cSrcweir {
168*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
169*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 	// not implemented yet :-) a task to do
172*cdf0e10cSrcweir 	return NULL;
173*cdf0e10cSrcweir }
174*cdf0e10cSrcweir // --------------------------------------------------------------------------------
175*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OConnection::nativeSQL( const ::rtl::OUString& _sSql ) throw(SQLException, RuntimeException)
176*cdf0e10cSrcweir {
177*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
178*cdf0e10cSrcweir 	// when you need to transform SQL92 to you driver specific you can do it here
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir 	return _sSql;
181*cdf0e10cSrcweir }
182*cdf0e10cSrcweir // --------------------------------------------------------------------------------
183*cdf0e10cSrcweir void SAL_CALL OConnection::setAutoCommit( sal_Bool autoCommit ) throw(SQLException, RuntimeException)
184*cdf0e10cSrcweir {
185*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
186*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
187*cdf0e10cSrcweir 	// here you  have to set your commit mode please have a look at the jdbc documentation to get a clear explanation
188*cdf0e10cSrcweir }
189*cdf0e10cSrcweir // --------------------------------------------------------------------------------
190*cdf0e10cSrcweir sal_Bool SAL_CALL OConnection::getAutoCommit(  ) throw(SQLException, RuntimeException)
191*cdf0e10cSrcweir {
192*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
193*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
194*cdf0e10cSrcweir 	// you have to distinguish which if you are in autocommit mode or not
195*cdf0e10cSrcweir 	// at normal case true should be fine here
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 	return sal_True;
198*cdf0e10cSrcweir }
199*cdf0e10cSrcweir // --------------------------------------------------------------------------------
200*cdf0e10cSrcweir void SAL_CALL OConnection::commit(  ) throw(SQLException, RuntimeException)
201*cdf0e10cSrcweir {
202*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
203*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir 	// when you database does support transactions you should commit here
206*cdf0e10cSrcweir }
207*cdf0e10cSrcweir // --------------------------------------------------------------------------------
208*cdf0e10cSrcweir void SAL_CALL OConnection::rollback(  ) throw(SQLException, RuntimeException)
209*cdf0e10cSrcweir {
210*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
211*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir 	// same as commit but for the other case
215*cdf0e10cSrcweir }
216*cdf0e10cSrcweir // --------------------------------------------------------------------------------
217*cdf0e10cSrcweir sal_Bool SAL_CALL OConnection::isClosed(  ) throw(SQLException, RuntimeException)
218*cdf0e10cSrcweir {
219*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 	// just simple -> we are close when we are disposed taht means someone called dispose(); (XComponent)
222*cdf0e10cSrcweir 	return OConnection_BASE::rBHelper.bDisposed;
223*cdf0e10cSrcweir }
224*cdf0e10cSrcweir // --------------------------------------------------------------------------------
225*cdf0e10cSrcweir Reference< XDatabaseMetaData > SAL_CALL OConnection::getMetaData(  ) throw(SQLException, RuntimeException)
226*cdf0e10cSrcweir {
227*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
228*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir 	// here we have to create the class with biggest interface
231*cdf0e10cSrcweir 	// The answer is 42 :-)
232*cdf0e10cSrcweir 	Reference< XDatabaseMetaData > xMetaData = m_xMetaData;
233*cdf0e10cSrcweir 	if(!xMetaData.is())
234*cdf0e10cSrcweir 	{
235*cdf0e10cSrcweir 		xMetaData = new ODatabaseMetaData(this); // need the connection because it can return it
236*cdf0e10cSrcweir 		m_xMetaData = xMetaData;
237*cdf0e10cSrcweir 	}
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir 	return xMetaData;
240*cdf0e10cSrcweir }
241*cdf0e10cSrcweir // --------------------------------------------------------------------------------
242*cdf0e10cSrcweir void SAL_CALL OConnection::setReadOnly( sal_Bool readOnly ) throw(SQLException, RuntimeException)
243*cdf0e10cSrcweir {
244*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
245*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 	// set you connection to readonly
248*cdf0e10cSrcweir }
249*cdf0e10cSrcweir // --------------------------------------------------------------------------------
250*cdf0e10cSrcweir sal_Bool SAL_CALL OConnection::isReadOnly(  ) throw(SQLException, RuntimeException)
251*cdf0e10cSrcweir {
252*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
253*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir 	// return if your connection to readonly
256*cdf0e10cSrcweir 	return sal_False;
257*cdf0e10cSrcweir }
258*cdf0e10cSrcweir // --------------------------------------------------------------------------------
259*cdf0e10cSrcweir void SAL_CALL OConnection::setCatalog( const ::rtl::OUString& catalog ) throw(SQLException, RuntimeException)
260*cdf0e10cSrcweir {
261*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
262*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 	// if your database doesn't work with catalogs you go to next method otherwise you kjnow what to do
265*cdf0e10cSrcweir }
266*cdf0e10cSrcweir // --------------------------------------------------------------------------------
267*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OConnection::getCatalog(  ) throw(SQLException, RuntimeException)
268*cdf0e10cSrcweir {
269*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
270*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 	// return your current catalog
274*cdf0e10cSrcweir 	return ::rtl::OUString();
275*cdf0e10cSrcweir }
276*cdf0e10cSrcweir // --------------------------------------------------------------------------------
277*cdf0e10cSrcweir void SAL_CALL OConnection::setTransactionIsolation( sal_Int32 level ) throw(SQLException, RuntimeException)
278*cdf0e10cSrcweir {
279*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
280*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir 	// set your isolation level
283*cdf0e10cSrcweir 	// please have a look at @see com.sun.star.sdbc.TransactionIsolation
284*cdf0e10cSrcweir }
285*cdf0e10cSrcweir // --------------------------------------------------------------------------------
286*cdf0e10cSrcweir sal_Int32 SAL_CALL OConnection::getTransactionIsolation(  ) throw(SQLException, RuntimeException)
287*cdf0e10cSrcweir {
288*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
289*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir 	// please have a look at @see com.sun.star.sdbc.TransactionIsolation
293*cdf0e10cSrcweir 	return TransactionIsolation::NONE;
294*cdf0e10cSrcweir }
295*cdf0e10cSrcweir // --------------------------------------------------------------------------------
296*cdf0e10cSrcweir Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OConnection::getTypeMap(  ) throw(SQLException, RuntimeException)
297*cdf0e10cSrcweir {
298*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
299*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir 	// if your driver has special database types you can return it here
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir 	return NULL;
304*cdf0e10cSrcweir }
305*cdf0e10cSrcweir // --------------------------------------------------------------------------------
306*cdf0e10cSrcweir void SAL_CALL OConnection::setTypeMap( const Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(SQLException, RuntimeException)
307*cdf0e10cSrcweir {
308*cdf0e10cSrcweir 	// the other way around
309*cdf0e10cSrcweir }
310*cdf0e10cSrcweir // --------------------------------------------------------------------------------
311*cdf0e10cSrcweir // XCloseable
312*cdf0e10cSrcweir void SAL_CALL OConnection::close(  ) throw(SQLException, RuntimeException)
313*cdf0e10cSrcweir {
314*cdf0e10cSrcweir 	// we just dispose us
315*cdf0e10cSrcweir 	{
316*cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
317*cdf0e10cSrcweir 		checkDisposed(OConnection_BASE::rBHelper.bDisposed);
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir 	}
320*cdf0e10cSrcweir 	dispose();
321*cdf0e10cSrcweir }
322*cdf0e10cSrcweir // --------------------------------------------------------------------------------
323*cdf0e10cSrcweir // XWarningsSupplier
324*cdf0e10cSrcweir Any SAL_CALL OConnection::getWarnings(  ) throw(SQLException, RuntimeException)
325*cdf0e10cSrcweir {
326*cdf0e10cSrcweir 	// when you collected some warnings -> return it
327*cdf0e10cSrcweir 	return Any();
328*cdf0e10cSrcweir }
329*cdf0e10cSrcweir // --------------------------------------------------------------------------------
330*cdf0e10cSrcweir void SAL_CALL OConnection::clearWarnings(  ) throw(SQLException, RuntimeException)
331*cdf0e10cSrcweir {
332*cdf0e10cSrcweir 	// you should clear your collected warnings here
333*cdf0e10cSrcweir }
334*cdf0e10cSrcweir //--------------------------------------------------------------------
335*cdf0e10cSrcweir void OConnection::buildTypeInfo() throw( SQLException)
336*cdf0e10cSrcweir {
337*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir 	Reference< XResultSet> xRs = getMetaData ()->getTypeInfo ();
340*cdf0e10cSrcweir 	Reference< XRow> xRow(xRs,UNO_QUERY);
341*cdf0e10cSrcweir 	// Information for a single SQL type
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir 	// Loop on the result set until we reach end of file
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir 	while (xRs->next ())
346*cdf0e10cSrcweir 	{
347*cdf0e10cSrcweir 		OTypeInfo aInfo;
348*cdf0e10cSrcweir 		aInfo.aTypeName			= xRow->getString	(1);
349*cdf0e10cSrcweir 		aInfo.nType				= xRow->getShort	(2);
350*cdf0e10cSrcweir 		aInfo.nPrecision		= xRow->getInt		(3);
351*cdf0e10cSrcweir 		aInfo.aLiteralPrefix	= xRow->getString	(4);
352*cdf0e10cSrcweir 		aInfo.aLiteralSuffix	= xRow->getString	(5);
353*cdf0e10cSrcweir 		aInfo.aCreateParams		= xRow->getString	(6);
354*cdf0e10cSrcweir 		aInfo.bNullable			= xRow->getBoolean	(7) == ColumnValue::NULLABLE;
355*cdf0e10cSrcweir 		aInfo.bCaseSensitive	= xRow->getBoolean	(8);
356*cdf0e10cSrcweir 		aInfo.nSearchType		= xRow->getShort	(9);
357*cdf0e10cSrcweir 		aInfo.bUnsigned			= xRow->getBoolean	(10);
358*cdf0e10cSrcweir 		aInfo.bCurrency			= xRow->getBoolean	(11);
359*cdf0e10cSrcweir 		aInfo.bAutoIncrement	= xRow->getBoolean	(12);
360*cdf0e10cSrcweir 		aInfo.aLocalTypeName	= xRow->getString	(13);
361*cdf0e10cSrcweir 		aInfo.nMinimumScale		= xRow->getShort	(14);
362*cdf0e10cSrcweir 		aInfo.nMaximumScale		= xRow->getShort	(15);
363*cdf0e10cSrcweir 		aInfo.nNumPrecRadix		= (sal_Int16)xRow->getInt(18);
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir 		// Now that we have the type info, save it
368*cdf0e10cSrcweir 		// in the Hashtable if we don't already have an
369*cdf0e10cSrcweir 		// entry for this SQL type.
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir 		m_aTypeInfo.push_back(aInfo);
372*cdf0e10cSrcweir 	}
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir 	// Close the result set/statement.
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir 	Reference< XCloseable> xClose(xRs,UNO_QUERY);
377*cdf0e10cSrcweir 	xClose->close();
378*cdf0e10cSrcweir }
379*cdf0e10cSrcweir //------------------------------------------------------------------------------
380*cdf0e10cSrcweir void OConnection::disposing()
381*cdf0e10cSrcweir {
382*cdf0e10cSrcweir 	// we noticed that we should be destroied in near future so we have to dispose our statements
383*cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir 	for (OWeakRefArray::iterator i = m_aStatements.begin(); m_aStatements.end() != i; ++i)
386*cdf0e10cSrcweir 	{
387*cdf0e10cSrcweir 		Reference< XComponent > xComp(i->get(), UNO_QUERY);
388*cdf0e10cSrcweir 		if (xComp.is())
389*cdf0e10cSrcweir 			xComp->dispose();
390*cdf0e10cSrcweir 	}
391*cdf0e10cSrcweir 	m_aStatements.clear();
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir 	m_bClosed	= sal_True;
394*cdf0e10cSrcweir 	m_xMetaData = ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDatabaseMetaData>();
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir 	dispose_ChildImpl();
397*cdf0e10cSrcweir 	OConnection_BASE::disposing();
398*cdf0e10cSrcweir }
399*cdf0e10cSrcweir // -----------------------------------------------------------------------------
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir 
403