1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26 #include "file/FDriver.hxx"
27 #include "file/FConnection.hxx"
28 #include "file/fcode.hxx"
29 #include <com/sun/star/lang/DisposedException.hpp>
30 #include <comphelper/types.hxx>
31 #include "connectivity/dbexception.hxx"
32 #include "resource/common_res.hrc"
33 #include "resource/sharedresources.hxx"
34 #include <rtl/logfile.hxx>
35 
36 
37 using namespace connectivity::file;
38 using namespace com::sun::star::uno;
39 using namespace com::sun::star::lang;
40 using namespace com::sun::star::beans;
41 using namespace com::sun::star::sdbc;
42 using namespace com::sun::star::sdbcx;
43 using namespace com::sun::star::container;
44 // --------------------------------------------------------------------------------
OFileDriver(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxFactory)45 OFileDriver::OFileDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory)
46 	: ODriver_BASE(m_aMutex)
47 	,m_xFactory(_rxFactory)
48 {
49     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::OFileDriver" );
50 }
51 // --------------------------------------------------------------------------------
disposing()52 void OFileDriver::disposing()
53 {
54     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::disposing" );
55 	::osl::MutexGuard aGuard(m_aMutex);
56 
57 
58 	for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
59 	{
60         Reference< XComponent > xComp(i->get(), UNO_QUERY);
61 		if (xComp.is())
62 			xComp->dispose();
63 	}
64 	m_xConnections.clear();
65 
66 	ODriver_BASE::disposing();
67 }
68 
69 // static ServiceInfo
70 //------------------------------------------------------------------------------
getImplementationName_Static()71 rtl::OUString OFileDriver::getImplementationName_Static(  ) throw(RuntimeException)
72 {
73 	return rtl::OUString::createFromAscii("com.sun.star.sdbc.driver.file.Driver");
74 }
75 //------------------------------------------------------------------------------
getSupportedServiceNames_Static()76 Sequence< ::rtl::OUString > OFileDriver::getSupportedServiceNames_Static(  ) throw (RuntimeException)
77 {
78     Sequence< ::rtl::OUString > aSNS( 2 );
79 	aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver");
80 	aSNS[1] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Driver");
81 	return aSNS;
82 }
83 
84 //------------------------------------------------------------------
getImplementationName()85 ::rtl::OUString SAL_CALL OFileDriver::getImplementationName(  ) throw(RuntimeException)
86 {
87 	return getImplementationName_Static();
88 }
89 
90 //------------------------------------------------------------------
supportsService(const::rtl::OUString & _rServiceName)91 sal_Bool SAL_CALL OFileDriver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
92 {
93     Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
94 	const ::rtl::OUString* pSupported = aSupported.getConstArray();
95 	const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
96 	for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
97 		;
98 
99 	return pSupported != pEnd;
100 }
101 
102 //------------------------------------------------------------------
getSupportedServiceNames()103 Sequence< ::rtl::OUString > SAL_CALL OFileDriver::getSupportedServiceNames(  ) throw(RuntimeException)
104 {
105 	return getSupportedServiceNames_Static();
106 }
107 
108 // --------------------------------------------------------------------------------
connect(const::rtl::OUString & url,const Sequence<PropertyValue> & info)109 Reference< XConnection > SAL_CALL OFileDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
110 {
111     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::connect" );
112 	::osl::MutexGuard aGuard( m_aMutex );
113 	checkDisposed(ODriver_BASE::rBHelper.bDisposed);
114 
115 	OConnection* pCon = new OConnection(this);
116 	Reference< XConnection > xCon = pCon;
117 	pCon->construct(url,info);
118     m_xConnections.push_back(WeakReferenceHelper(*pCon));
119 
120 	return xCon;
121 }
122 // --------------------------------------------------------------------------------
acceptsURL(const::rtl::OUString & url)123 sal_Bool SAL_CALL OFileDriver::acceptsURL( const ::rtl::OUString& url )
124                 throw(SQLException, RuntimeException)
125 {
126     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::acceptsURL" );
127 	return (!url.compareTo(::rtl::OUString::createFromAscii("sdbc:file:"),10));
128 }
129 // --------------------------------------------------------------------------------
getPropertyInfo(const::rtl::OUString & url,const Sequence<PropertyValue> &)130 Sequence< DriverPropertyInfo > SAL_CALL OFileDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException)
131 {
132     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::getPropertyInfo" );
133 	if ( acceptsURL(url) )
134 	{
135 		::std::vector< DriverPropertyInfo > aDriverInfo;
136 
137 		Sequence< ::rtl::OUString > aBoolean(2);
138 		aBoolean[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"));
139 		aBoolean[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("1"));
140 
141 		aDriverInfo.push_back(DriverPropertyInfo(
142 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet"))
143 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet of the database."))
144 				,sal_False
145 				,::rtl::OUString()
146 				,Sequence< ::rtl::OUString >())
147 				);
148 		aDriverInfo.push_back(DriverPropertyInfo(
149 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Extension"))
150 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Extension of the file format."))
151 				,sal_False
152 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".*"))
153 				,Sequence< ::rtl::OUString >())
154 				);
155 		aDriverInfo.push_back(DriverPropertyInfo(
156 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowDeleted"))
157 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Display inactive records."))
158 				,sal_False
159 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
160 				,aBoolean)
161 				);
162 		aDriverInfo.push_back(DriverPropertyInfo(
163 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EnableSQL92Check"))
164 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Use SQL92 naming constraints."))
165 				,sal_False
166 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
167 				,aBoolean)
168 				);
169         aDriverInfo.push_back(DriverPropertyInfo(
170 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseRelativePath"))
171 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Handle the connection url as relative path."))
172 				,sal_False
173 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
174 				,aBoolean)
175 				);
176         aDriverInfo.push_back(DriverPropertyInfo(
177 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("URL"))
178 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("The URL of the database document which is used to create an absolute path."))
179 				,sal_False
180 				,::rtl::OUString()
181 				,Sequence< ::rtl::OUString >())
182 				);
183 		return Sequence< DriverPropertyInfo >(&(aDriverInfo[0]),aDriverInfo.size());
184 	} // if ( acceptsURL(url) )
185     {
186         ::connectivity::SharedResources aResources;
187         const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
188 		::dbtools::throwGenericSQLException(sMessage ,*this);
189     } // if ( ! acceptsURL(url) )
190 	return Sequence< DriverPropertyInfo >();
191 }
192 // --------------------------------------------------------------------------------
getMajorVersion()193 sal_Int32 SAL_CALL OFileDriver::getMajorVersion(  ) throw(RuntimeException)
194 {
195     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::getMajorVersion" );
196 	return 1;
197 }
198 // --------------------------------------------------------------------------------
getMinorVersion()199 sal_Int32 SAL_CALL OFileDriver::getMinorVersion(  ) throw(RuntimeException)
200 {
201     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::getMinorVersion" );
202 	return 0;
203 }
204 // --------------------------------------------------------------------------------
205 // --------------------------------------------------------------------------------
206 // XDataDefinitionSupplier
getDataDefinitionByConnection(const Reference<::com::sun::star::sdbc::XConnection> & connection)207 Reference< XTablesSupplier > SAL_CALL OFileDriver::getDataDefinitionByConnection( const Reference< ::com::sun::star::sdbc::XConnection >& connection ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
208 {
209     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::getDataDefinitionByConnection" );
210 	::osl::MutexGuard aGuard( m_aMutex );
211 	checkDisposed(ODriver_BASE::rBHelper.bDisposed);
212 
213 	Reference< XTablesSupplier > xTab = NULL;
214 	Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(connection,UNO_QUERY);
215 	if(xTunnel.is())
216 	{
217 		OConnection* pSearchConnection = reinterpret_cast< OConnection* >( xTunnel->getSomething(OConnection::getUnoTunnelImplementationId()) );
218 		OConnection* pConnection = NULL;
219 		for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
220 		{
221 			if ((OConnection*) Reference< XConnection >::query(i->get().get()).get() == pSearchConnection)
222 			{
223 				pConnection = pSearchConnection;
224 				break;
225 			}
226 		}
227 
228 		if(pConnection)
229 			xTab = pConnection->createCatalog();
230 	}
231 	return xTab;
232 }
233 
234 // --------------------------------------------------------------------------------
getDataDefinitionByURL(const::rtl::OUString & url,const Sequence<PropertyValue> & info)235 Reference< XTablesSupplier > SAL_CALL OFileDriver::getDataDefinitionByURL( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
236 {
237     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::getDataDefinitionByURL" );
238 	if ( ! acceptsURL(url) )
239     {
240 		::connectivity::SharedResources aResources;
241         const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
242 		::dbtools::throwGenericSQLException(sMessage ,*this);
243     }
244 	return getDataDefinitionByConnection(connect(url,info));
245 }
246 // -----------------------------------------------------------------------------
describe(const Reference<XPropertySet> & rColumn,::vos::ORef<connectivity::OSQLColumns> rParameterColumns)247 void OOperandParam::describe(const Reference< XPropertySet>& rColumn, ::vos::ORef<connectivity::OSQLColumns> rParameterColumns)
248 {
249 	// den alten namen beibehalten
250 
251 	OSL_ENSURE(getRowPos() < rParameterColumns->get().size(),"Invalid index for orderkey values!");
252 
253 	Reference< XPropertySet> xColumn = (rParameterColumns->get())[getRowPos()];
254 
255 	try
256 	{
257 		xColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME),rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)));
258 		xColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE),rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE)));
259 		xColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION),rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)));
260 		xColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)));
261 		xColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE),rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)));
262 		xColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE),rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE)));
263 		xColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT),rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)));
264 	}
265 	catch(const Exception&)
266 	{
267 	}
268 
269 	m_eDBType = ::comphelper::getINT32(rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)));
270 }
271 // -----------------------------------------------------------------------------
OOperandAttr(sal_uInt16 _nPos,const Reference<XPropertySet> & _xColumn)272 OOperandAttr::OOperandAttr(sal_uInt16 _nPos,const Reference< XPropertySet>& _xColumn)
273 	: OOperandRow(_nPos,::comphelper::getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))))
274 	, m_xColumn(_xColumn)
275 {
276 }
277 // -----------------------------------------------------------------------------
278 
279 
280 
281 
282