Kaydet (Commit) 67ff964c authored tarafından Andrzej J.R. Hunt's avatar Andrzej J.R. Hunt

Create new fdb and/or extract from .odb as appropriate.

Change-Id: I99dd3300c2a7e903bc924b15c4fea2fd3ad4abb8
üst 304ab448
...@@ -33,6 +33,54 @@ ...@@ -33,6 +33,54 @@
************************************************************************ --> ************************************************************************ -->
<oor:component-data oor:name="Drivers" oor:package="org.openoffice.Office.DataAccess" xmlns:install="http://openoffice.org/2004/installation" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <oor:component-data oor:name="Drivers" oor:package="org.openoffice.Office.DataAccess" xmlns:install="http://openoffice.org/2004/installation" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<node oor:name="Installed" install:module="firebird"> <node oor:name="Installed" install:module="firebird">
<node oor:name="sdbc:embedded:firebird" oor:op="replace">
<prop oor:name="Driver">
<value>com.sun.star.comp.sdbc.FirebirdDriver</value>
</prop>
<prop oor:name="DriverTypeDisplayName" oor:type="xs:string">
<value xml:lang="en-US">Firebird</value>
</prop>
<node oor:name="Properties">
<!-- Don't use ODBC syntax for date&time literals and (full) outer joins,
as PostgreSQL does not support it,
but supports the _interior_ of these escapes just fine. -->
<node oor:name="EscapeDateTime" oor:op="replace">
<prop oor:name="Value" oor:type="xs:boolean">
<value>false</value>
</prop>
</node>
<!-- Confusingly, this corresponds to "UseBracketedOuterJoinSyntax" in the Features -->
<node oor:name="EnableOuterJoinEscape" oor:op="replace">
<prop oor:name="Value" oor:type="xs:boolean">
<value>false</value>
</prop>
</node>
</node>
<node oor:name="Features">
<!-- These entries enable the "Advanced Settings" UI to change the settings
whose default is set in node "Properties" above;
as this is guaranteed not to work with PostgreSQL,
we don't let people shoot themselves in the foot and don't enable the UI. -->
<!-- <node oor:name="EscapeDateTime" oor:op="replace"> -->
<!-- <prop oor:name="Value" oor:type="xs:boolean"> -->
<!-- <value>false</value> -->
<!-- </prop> -->
<!-- </node> -->
<!-- Confusingly, this corresponds to "EnableOuterJoinEscape" in the Properties -->
<!-- <node oor:name="UseBracketedOuterJoinSyntax" oor:op="replace"> -->
<!-- <prop oor:name="Value" oor:type="xs:boolean"> -->
<!-- <value>false</value> -->
<!-- </prop> -->
<!-- </node> -->
</node>
<node oor:name="MetaData">
<node oor:name="Authentication" oor:op="replace">
<prop oor:name="Value" oor:type="xs:string">
<value>UserPassword</value>
</prop>
</node>
</node>
</node>
<node oor:name="sdbc:firebird:*" oor:op="replace"> <node oor:name="sdbc:firebird:*" oor:op="replace">
<prop oor:name="Driver"> <prop oor:name="Driver">
<value>com.sun.star.comp.sdbc.FirebirdDriver</value> <value>com.sun.star.comp.sdbc.FirebirdDriver</value>
......
...@@ -103,7 +103,9 @@ static int pr_error(const ISC_STATUS* status, char* operation) ...@@ -103,7 +103,9 @@ static int pr_error(const ISC_STATUS* status, char* operation)
return 1; return 1;
} }
void OConnection::construct(const ::rtl::OUString& url,const Sequence< PropertyValue >& info) throw(SQLException) void OConnection::construct(const ::rtl::OUString& url, const Sequence< PropertyValue >& info,
const bool constructNewDatabase)
throw(SQLException)
{ {
SAL_INFO("connectivity.firebird", "=> OConnection::construct()."); SAL_INFO("connectivity.firebird", "=> OConnection::construct().");
...@@ -113,10 +115,22 @@ void OConnection::construct(const ::rtl::OUString& url,const Sequence< PropertyV ...@@ -113,10 +115,22 @@ void OConnection::construct(const ::rtl::OUString& url,const Sequence< PropertyV
ISC_STATUS_ARRAY status; /* status vector */ ISC_STATUS_ARRAY status; /* status vector */
if (isc_attach_database(status, 0, "/var/tmp/libo-fb/new.fdb", &m_DBHandler, 0, NULL)) if (constructNewDatabase)
if (pr_error(status, "attach database")) {
return; if (isc_create_database(status, url.getLength(), OUStringToOString(url, RTL_TEXTENCODING_UTF8).getStr(),
&m_DBHandler, 0, NULL, 0))
{
if(pr_error(status, "create new database"))
return;
}
}
else
{
if (isc_attach_database(status, url.getLength(), OUStringToOString(url, RTL_TEXTENCODING_UTF8).getStr(),
&m_DBHandler, 0, NULL))
if (pr_error(status, "attach database"))
return;
}
osl_atomic_decrement( &m_refCount ); osl_atomic_decrement( &m_refCount );
} }
// XServiceInfo // XServiceInfo
......
...@@ -107,7 +107,10 @@ namespace connectivity ...@@ -107,7 +107,10 @@ namespace connectivity
void buildTypeInfo() throw( ::com::sun::star::sdbc::SQLException); void buildTypeInfo() throw( ::com::sun::star::sdbc::SQLException);
public: public:
virtual void construct( const ::rtl::OUString& url,const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info) throw(::com::sun::star::sdbc::SQLException); virtual void construct( const ::rtl::OUString& url,
const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info,
const bool constructNewDatabase)
throw(::com::sun::star::sdbc::SQLException);
OConnection(FirebirdDriver* _pDriver); OConnection(FirebirdDriver* _pDriver);
virtual ~OConnection(); virtual ~OConnection();
......
...@@ -571,7 +571,8 @@ sal_Bool SAL_CALL ODatabaseMetaData::supportsANSI92IntermediateSQL( ) throw(SQL ...@@ -571,7 +571,8 @@ sal_Bool SAL_CALL ODatabaseMetaData::supportsANSI92IntermediateSQL( ) throw(SQL
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
::rtl::OUString SAL_CALL ODatabaseMetaData::getURL( ) throw(SQLException, RuntimeException) ::rtl::OUString SAL_CALL ODatabaseMetaData::getURL( ) throw(SQLException, RuntimeException)
{ {
::rtl::OUString aValue("sdbc:firebird:"); // TODO: return actual URL as necessary
::rtl::OUString aValue("sdbc:embedded:firebird");
return aValue; return aValue;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
......
...@@ -37,12 +37,29 @@ ...@@ -37,12 +37,29 @@
#include "FConnection.hxx" #include "FConnection.hxx"
#include "connectivity/dbexception.hxx" #include "connectivity/dbexception.hxx"
#include "resource/common_res.hrc" #include "resource/common_res.hrc"
#include "resource/hsqldb_res.hrc"
#include "resource/sharedresources.hxx" #include "resource/sharedresources.hxx"
#include <unotools/tempfile.hxx>
#include <comphelper/processfactory.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <com/sun/star/embed/ElementModes.hpp>
#include <com/sun/star/embed/XStorage.hpp>
#include <com/sun/star/io/TempFile.hpp>
#include <com/sun/star/io/XStream.hpp>
#include <com/sun/star/ucb/SimpleFileAccess.hpp>
#include <com/sun/star/ucb/XSimpleFileAccess2.hpp>
using namespace com::sun::star;
using namespace com::sun::star::embed;
using namespace com::sun::star::io;
using namespace com::sun::star::uno; using namespace com::sun::star::uno;
using namespace com::sun::star::lang; using namespace com::sun::star::lang;
using namespace com::sun::star::beans; using namespace com::sun::star::beans;
using namespace com::sun::star::sdbc; using namespace com::sun::star::sdbc;
using namespace connectivity::firebird; using namespace connectivity::firebird;
namespace connectivity namespace connectivity
...@@ -53,13 +70,16 @@ namespace connectivity ...@@ -53,13 +70,16 @@ namespace connectivity
::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL FirebirdDriver_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception ) ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL FirebirdDriver_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception )
{ {
SAL_INFO("connectivity.firebird", "=> ODriver_BASE::FirebirdDriver_CreateInstance()" ); SAL_INFO("connectivity.firebird", "=> ODriver_BASE::FirebirdDriver_CreateInstance()" );
(void) _rxFactory;
return *(new FirebirdDriver()); return *(new FirebirdDriver());
} }
} }
} }
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
FirebirdDriver::FirebirdDriver() FirebirdDriver::FirebirdDriver()
: ODriver_BASE(m_aMutex) : ODriver_BASE(m_aMutex),
mbIsEmbedded(false),
mFilePath()
{ {
} }
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
...@@ -124,6 +144,79 @@ Sequence< ::rtl::OUString > SAL_CALL FirebirdDriver::getSupportedServiceNames( ...@@ -124,6 +144,79 @@ Sequence< ::rtl::OUString > SAL_CALL FirebirdDriver::getSupportedServiceNames(
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
Reference< XConnection > SAL_CALL FirebirdDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException) Reference< XConnection > SAL_CALL FirebirdDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
{ {
Reference< XConnection > xConnection;
bool bIsNewDatabase = false;
if (url.equals("sdbc:embedded:firebird"))
{
mbIsEmbedded = true;
Reference<XStorage> xStorage;
const PropertyValue* pIter = info.getConstArray();
const PropertyValue* pEnd = pIter + info.getLength();
for (;pIter != pEnd; ++pIter)
{
if ( pIter->Name == "Storage" )
{
xStorage.set(pIter->Value,UNO_QUERY);
}
}
if ( !xStorage.is() )
{
::connectivity::SharedResources aResources;
const OUString sMessage = aResources.getResourceString(STR_NO_STROAGE);
::dbtools::throwGenericSQLException(sMessage ,*this);
}
bIsNewDatabase = !xStorage->hasElements();
const OUString sDBName( "firebird.fdb" ); // Location within .odb container
mFilePath = utl::TempFile::CreateTempName() + ".fdb";
SAL_INFO("connectivity.firebird", "Temporary .fdb location: "
<< OUStringToOString(mFilePath,RTL_TEXTENCODING_UTF8 ).getStr());
if (!bIsNewDatabase)
{
SAL_INFO("connectivity.firebird", "Extracting .fdb from .odb" );
if (!xStorage->isStreamElement(sDBName))
{
::connectivity::SharedResources aResources;
const OUString sMessage = aResources.getResourceString(STR_ERROR_NEW_VERSION);
::dbtools::throwGenericSQLException(sMessage ,*this);
}
Reference< XStream > xDBStream(xStorage->openStreamElement(sDBName,
ElementModes::READ));
SAL_INFO("connectivity.firebird", ".fdb being written to "
<< OUStringToOString(mFilePath,RTL_TEXTENCODING_UTF8 ).getStr());
uno::Reference< ucb::XSimpleFileAccess2 > xFileAccess(
ucb::SimpleFileAccess::create( comphelper::getProcessComponentContext() ),
uno::UNO_QUERY );
if ( !xFileAccess.is() )
{
// TODO: Error
::connectivity::SharedResources aResources;
const OUString sMessage = aResources.getResourceString(STR_ERROR_NEW_VERSION);
::dbtools::throwGenericSQLException(sMessage ,*this);
}
try {
xFileAccess->writeFile(mFilePath,xDBStream->getInputStream());
}
catch (...)
{
// TODO
}
}
if (bIsNewDatabase)
{
}
// Get DB properties from XML
}
SAL_INFO("connectivity.firebird", "=> ODriver_BASE::connect(), URL: " << url ); SAL_INFO("connectivity.firebird", "=> ODriver_BASE::connect(), URL: " << url );
::osl::MutexGuard aGuard( m_aMutex ); ::osl::MutexGuard aGuard( m_aMutex );
...@@ -133,10 +226,12 @@ Reference< XConnection > SAL_CALL FirebirdDriver::connect( const ::rtl::OUString ...@@ -133,10 +226,12 @@ Reference< XConnection > SAL_CALL FirebirdDriver::connect( const ::rtl::OUString
if ( ! acceptsURL(url) ) if ( ! acceptsURL(url) )
return NULL; return NULL;
bool bCreateNewFile = mbIsEmbedded&&bIsNewDatabase;
// create a new connection with the given properties and append it to our vector // create a new connection with the given properties and append it to our vector
OConnection* pCon = new OConnection(this); OConnection* pCon = new OConnection(this);
Reference< XConnection > xCon = pCon; // important here because otherwise the connection could be deleted inside (refcount goes -> 0) Reference< XConnection > xCon = pCon; // important here because otherwise the connection could be deleted inside (refcount goes -> 0)
pCon->construct(url,info); // late constructor call which can throw exception and allows a correct dtor call when so pCon->construct(mFilePath,info,bCreateNewFile); // late constructor call which can throw exception and allows a correct dtor call when so
m_xConnections.push_back(WeakReferenceHelper(*pCon)); m_xConnections.push_back(WeakReferenceHelper(*pCon));
return xCon; return xCon;
...@@ -145,16 +240,12 @@ Reference< XConnection > SAL_CALL FirebirdDriver::connect( const ::rtl::OUString ...@@ -145,16 +240,12 @@ Reference< XConnection > SAL_CALL FirebirdDriver::connect( const ::rtl::OUString
sal_Bool SAL_CALL FirebirdDriver::acceptsURL( const ::rtl::OUString& url ) sal_Bool SAL_CALL FirebirdDriver::acceptsURL( const ::rtl::OUString& url )
throw(SQLException, RuntimeException) throw(SQLException, RuntimeException)
{ {
// here we have to look if we support this url format return url.equals("sdbc:embedded:firebird") || url.startsWith("sdbc:firebird:");
// change the URL format to your needs, but please aware that the first on who accepts the URl wins.
// This could be extended to allow for external dbs using e.g. sdbc:firebird:url
// in addition to embedded dbs.
// return url.startsWith("sdbc:firebird:");
return url.equals("sdbc:embedded:firebird");
} }
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
Sequence< DriverPropertyInfo > SAL_CALL FirebirdDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException) Sequence< DriverPropertyInfo > SAL_CALL FirebirdDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
{ {
(void) info;
if ( ! acceptsURL(url) ) if ( ! acceptsURL(url) )
{ {
::connectivity::SharedResources aResources; ::connectivity::SharedResources aResources;
......
...@@ -57,6 +57,10 @@ namespace connectivity ...@@ -57,6 +57,10 @@ namespace connectivity
OWeakRefArray m_xConnections; // vector containing a list OWeakRefArray m_xConnections; // vector containing a list
// of all the Connection objects // of all the Connection objects
// for this Driver // for this Driver
private:
bool mbIsEmbedded;
OUString mFilePath;
public: public:
FirebirdDriver(); FirebirdDriver();
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* The Contents of this file are made available subject to the terms of
* the BSD license.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Sun Microsystems, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*************************************************************************/
#ifndef _CONNECTIVITY_OTYPEINFO_HXX_
#define _CONNECTIVITY_OTYPEINFO_HXX_
#include <com/sun/star/sdbc/ColumnSearch.hpp>
#include <com/sun/star/sdbc/DataType.hpp>
namespace connectivity
{
struct OTypeInfo
{
::rtl::OUString aTypeName; // Name of the the type in the database
::rtl::OUString aLiteralPrefix; // Prefix for literals
::rtl::OUString aLiteralSuffix; // Suffix for literals
::rtl::OUString aCreateParams; // Parameters to create
::rtl::OUString aLocalTypeName;
sal_Int32 nPrecision; // Length of the types
sal_Int16 nMaximumScale; // Decimal places (precision)
sal_Int16 nMinimumScale; // Min decimal places (precision)
sal_Int16 nType; // Database type
sal_Int16 nSearchType; // Can search for the type
sal_Int16 nNumPrecRadix; // indicating the radix, which is usually 2 or 10
sal_Bool bCurrency : 1, // Currency
bAutoIncrement : 1, // Is this field auto incrementing?
bNullable : 1, // Can this field assume a NULL value?
bCaseSensitive : 1, // Is this type case-sensitive?
bUnsigned : 1, // Is this type unsigned?
bEmpty_1 : 1, // for later use
bEmpty_2 : 1;
OTypeInfo()
:bCurrency(sal_False)
,bAutoIncrement(sal_False)
,bNullable(sal_True)
,bCaseSensitive(sal_False)
,bUnsigned(sal_False)
,nMaximumScale(0)
,nMinimumScale(0)
,nType( ::com::sun::star::sdbc::DataType::OTHER)
,nPrecision(0)
,nSearchType( ::com::sun::star::sdbc::ColumnSearch::FULL)
{}
inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW(())
{ return ::rtl_allocateMemory( nSize ); }
inline static void * SAL_CALL operator new( size_t nSize,void* _pHint ) SAL_THROW(())
{ return _pHint; }
inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW(())
{ ::rtl_freeMemory( pMem ); }
inline static void SAL_CALL operator delete( void * pMem,void* _pHint ) SAL_THROW(())
{ }
sal_Bool operator == (const OTypeInfo& lh) const { return lh.nType == nType; }
sal_Bool operator != (const OTypeInfo& lh) const { return lh.nType != nType; }
inline ::rtl::OUString getDBName() const { return aTypeName; }
};
}
#endif // _CONNECTIVITY_OTYPEINFO_HXX_
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -20,6 +20,12 @@ $(eval $(call gb_Library_add_defs,dba,\ ...@@ -20,6 +20,12 @@ $(eval $(call gb_Library_add_defs,dba,\
-DOOO_DLLIMPLEMENTATION_DBA \ -DOOO_DLLIMPLEMENTATION_DBA \
)) ))
ifeq ($(ENABLE_FIREBIRD_SDBC),TRUE)
$(eval $(call gb_Library_add_defs,dba,\
-DENABLE_FIREBIRD_SDBC \
))
endif
$(eval $(call gb_Library_use_external,dba,boost_headers)) $(eval $(call gb_Library_use_external,dba,boost_headers))
$(eval $(call gb_Library_use_sdk_api,dba)) $(eval $(call gb_Library_use_sdk_api,dba))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment