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 "dbase/DDriver.hxx"
27 #include "dbase/DConnection.hxx"
28 #include <com/sun/star/lang/DisposedException.hpp>
29 #include "connectivity/dbexception.hxx"
30 #include "resource/dbase_res.hrc"
31 
32 using namespace connectivity::dbase;
33 using namespace connectivity::file;
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::beans;
36 using namespace ::com::sun::star::sdbcx;
37 using namespace ::com::sun::star::sdbc;
38 using namespace ::com::sun::star::lang;
39 
40 
41 // static ServiceInfo
42 //------------------------------------------------------------------------------
getImplementationName_Static()43 rtl::OUString ODriver::getImplementationName_Static(  ) throw(RuntimeException)
44 {
45 	return rtl::OUString::createFromAscii("com.sun.star.comp.sdbc.dbase.ODriver");
46 }
47 
48 //------------------------------------------------------------------
getImplementationName()49 ::rtl::OUString SAL_CALL ODriver::getImplementationName(  ) throw(RuntimeException)
50 {
51 	return getImplementationName_Static();
52 }
53 
54 //------------------------------------------------------------------
ODriver_CreateInstance(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxFactory)55 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >  SAL_CALL connectivity::dbase::ODriver_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception )
56 {
57 	return *(new ODriver(_rxFactory));
58 }
59 // --------------------------------------------------------------------------------
connect(const::rtl::OUString & url,const Sequence<PropertyValue> & info)60 Reference< XConnection > SAL_CALL ODriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
61 {
62 	::osl::MutexGuard aGuard( m_aMutex );
63 	if (ODriver_BASE::rBHelper.bDisposed)
64 		throw DisposedException();
65 
66 	if ( ! acceptsURL(url) )
67 		return NULL;
68 
69 	ODbaseConnection* pCon = new ODbaseConnection(this);
70 	pCon->construct(url,info);
71     Reference< XConnection > xCon = pCon;
72     m_xConnections.push_back(WeakReferenceHelper(*pCon));
73 
74 	return xCon;
75 }
76 // --------------------------------------------------------------------------------
acceptsURL(const::rtl::OUString & url)77 sal_Bool SAL_CALL ODriver::acceptsURL( const ::rtl::OUString& url ) throw(SQLException, RuntimeException)
78 {
79 	return !url.compareTo(::rtl::OUString::createFromAscii("sdbc:dbase:"),11);
80 }
81 // -----------------------------------------------------------------------------
getPropertyInfo(const::rtl::OUString & url,const Sequence<PropertyValue> &)82 Sequence< DriverPropertyInfo > SAL_CALL ODriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException)
83 {
84 	if ( acceptsURL(url) )
85 	{
86 		::std::vector< DriverPropertyInfo > aDriverInfo;
87 
88 		Sequence< ::rtl::OUString > aBoolean(2);
89 		aBoolean[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"));
90 		aBoolean[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("1"));
91 
92 		aDriverInfo.push_back(DriverPropertyInfo(
93 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet"))
94 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet of the database."))
95 				,sal_False
96 				,::rtl::OUString()
97 				,Sequence< ::rtl::OUString >())
98 				);
99 		aDriverInfo.push_back(DriverPropertyInfo(
100 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowDeleted"))
101 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Display inactive records."))
102 				,sal_False
103 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
104 				,aBoolean)
105 				);
106 		aDriverInfo.push_back(DriverPropertyInfo(
107 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EnableSQL92Check"))
108 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Use SQL92 naming constraints."))
109 				,sal_False
110 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
111 				,aBoolean)
112 				);
113 		return Sequence< DriverPropertyInfo >(&(aDriverInfo[0]),aDriverInfo.size());
114 	}
115 
116 	SharedResources aResources;
117     const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
118 	::dbtools::throwGenericSQLException(sMessage ,*this);
119 	return Sequence< DriverPropertyInfo >();
120 }
121 // -----------------------------------------------------------------------------
122 
123 
124