summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrzej J.R. Hunt <andrzej@ahunt.org>2013-07-11 10:14:58 +0100
committerAndrzej J.R. Hunt <andrzej@ahunt.org>2013-07-11 10:14:58 +0100
commit8af4693b153a9b5b9469d41d5522cd70d1496d7f (patch)
tree6e865d4e861628ae2ff45a4f22da3617903e6edc
parenta17ed62780f57fcc20814644b5adb8b7ea2b9e0f (diff)
Create new fdb and/or extract from .odb as appropriate.
Change-Id: I99dd3300c2a7e903bc924b15c4fea2fd3ad4abb8
-rw-r--r--connectivity/registry/firebird/org/openoffice/Office/DataAccess/Drivers.xcu48
-rw-r--r--connectivity/source/drivers/firebird/FConnection.cxx24
-rw-r--r--connectivity/source/drivers/firebird/FConnection.hxx5
-rw-r--r--connectivity/source/drivers/firebird/FDatabaseMetaData.cxx3
-rw-r--r--connectivity/source/drivers/firebird/FDriver.cxx107
-rw-r--r--connectivity/source/drivers/firebird/FDriver.hxx4
-rw-r--r--connectivity/source/drivers/firebird/OTypeInfo.hxx100
-rw-r--r--dbaccess/Library_dba.mk6
8 files changed, 182 insertions, 115 deletions
diff --git a/connectivity/registry/firebird/org/openoffice/Office/DataAccess/Drivers.xcu b/connectivity/registry/firebird/org/openoffice/Office/DataAccess/Drivers.xcu
index 003cb03b3a81..527640a19572 100644
--- a/connectivity/registry/firebird/org/openoffice/Office/DataAccess/Drivers.xcu
+++ b/connectivity/registry/firebird/org/openoffice/Office/DataAccess/Drivers.xcu
@@ -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">
<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">
<prop oor:name="Driver">
<value>com.sun.star.comp.sdbc.FirebirdDriver</value>
diff --git a/connectivity/source/drivers/firebird/FConnection.cxx b/connectivity/source/drivers/firebird/FConnection.cxx
index 5efd16562a18..e72b87e42da3 100644
--- a/connectivity/source/drivers/firebird/FConnection.cxx
+++ b/connectivity/source/drivers/firebird/FConnection.cxx
@@ -103,7 +103,9 @@ static int pr_error(const ISC_STATUS* status, char* operation)
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().");
@@ -113,10 +115,22 @@ void OConnection::construct(const ::rtl::OUString& url,const Sequence< PropertyV
ISC_STATUS_ARRAY status; /* status vector */
- if (isc_attach_database(status, 0, "/var/tmp/libo-fb/new.fdb", &m_DBHandler, 0, NULL))
- if (pr_error(status, "attach database"))
- return;
-
+ if (constructNewDatabase)
+ {
+ 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 );
}
// XServiceInfo
diff --git a/connectivity/source/drivers/firebird/FConnection.hxx b/connectivity/source/drivers/firebird/FConnection.hxx
index dc4b62be9144..af2ff6601d62 100644
--- a/connectivity/source/drivers/firebird/FConnection.hxx
+++ b/connectivity/source/drivers/firebird/FConnection.hxx
@@ -107,7 +107,10 @@ namespace connectivity
void buildTypeInfo() throw( ::com::sun::star::sdbc::SQLException);
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);
virtual ~OConnection();
diff --git a/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx b/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx
index dfafff59237c..80c4470bfe10 100644
--- a/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx
+++ b/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx
@@ -571,7 +571,8 @@ sal_Bool SAL_CALL ODatabaseMetaData::supportsANSI92IntermediateSQL( ) throw(SQL
// -------------------------------------------------------------------------
::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;
}
// -------------------------------------------------------------------------
diff --git a/connectivity/source/drivers/firebird/FDriver.cxx b/connectivity/source/drivers/firebird/FDriver.cxx
index 7f7b44a1a362..78280da4749c 100644
--- a/connectivity/source/drivers/firebird/FDriver.cxx
+++ b/connectivity/source/drivers/firebird/FDriver.cxx
@@ -37,12 +37,29 @@
#include "FConnection.hxx"
#include "connectivity/dbexception.hxx"
#include "resource/common_res.hrc"
+#include "resource/hsqldb_res.hrc"
#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::lang;
using namespace com::sun::star::beans;
using namespace com::sun::star::sdbc;
+
using namespace connectivity::firebird;
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 )
{
SAL_INFO("connectivity.firebird", "=> ODriver_BASE::FirebirdDriver_CreateInstance()" );
+ (void) _rxFactory;
return *(new 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(
// --------------------------------------------------------------------------------
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 );
::osl::MutexGuard aGuard( m_aMutex );
@@ -133,10 +226,12 @@ Reference< XConnection > SAL_CALL FirebirdDriver::connect( const ::rtl::OUString
if ( ! acceptsURL(url) )
return NULL;
+ bool bCreateNewFile = mbIsEmbedded&&bIsNewDatabase;
+
// create a new connection with the given properties and append it to our vector
OConnection* pCon = new OConnection(this);
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));
return xCon;
@@ -145,16 +240,12 @@ Reference< XConnection > SAL_CALL FirebirdDriver::connect( const ::rtl::OUString
sal_Bool SAL_CALL FirebirdDriver::acceptsURL( const ::rtl::OUString& url )
throw(SQLException, RuntimeException)
{
- // here we have to look if we support this url format
- // 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");
+ return url.equals("sdbc:embedded:firebird") || url.startsWith("sdbc:firebird:");
}
// --------------------------------------------------------------------------------
Sequence< DriverPropertyInfo > SAL_CALL FirebirdDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
{
+ (void) info;
if ( ! acceptsURL(url) )
{
::connectivity::SharedResources aResources;
diff --git a/connectivity/source/drivers/firebird/FDriver.hxx b/connectivity/source/drivers/firebird/FDriver.hxx
index 005ba0039697..1a259c0baf91 100644
--- a/connectivity/source/drivers/firebird/FDriver.hxx
+++ b/connectivity/source/drivers/firebird/FDriver.hxx
@@ -57,6 +57,10 @@ namespace connectivity
OWeakRefArray m_xConnections; // vector containing a list
// of all the Connection objects
// for this Driver
+ private:
+ bool mbIsEmbedded;
+ OUString mFilePath;
+
public:
FirebirdDriver();
diff --git a/connectivity/source/drivers/firebird/OTypeInfo.hxx b/connectivity/source/drivers/firebird/OTypeInfo.hxx
deleted file mode 100644
index dffe3e68976c..000000000000
--- a/connectivity/source/drivers/firebird/OTypeInfo.hxx
+++ /dev/null
@@ -1,100 +0,0 @@
-/* -*- 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: */
diff --git a/dbaccess/Library_dba.mk b/dbaccess/Library_dba.mk
index bca628df7b87..08d13df38144 100644
--- a/dbaccess/Library_dba.mk
+++ b/dbaccess/Library_dba.mk
@@ -20,6 +20,12 @@ $(eval $(call gb_Library_add_defs,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_sdk_api,dba))