Kaydet (Commit) cf921921 authored tarafından Javier Fernandez's avatar Javier Fernandez Kaydeden (comit) Andrzej J.R. Hunt

Properly implementing the connection construction.

Change-Id: I6bb114d871697483a1a4246496f73252e5307534
üst 05fb9dca
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <com/sun/star/lang/DisposedException.hpp> #include <com/sun/star/lang/DisposedException.hpp>
using namespace connectivity::firebird; using namespace connectivity::firebird;
using namespace connectivity;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
using namespace com::sun::star::uno; using namespace com::sun::star::uno;
...@@ -62,6 +63,7 @@ OConnection::OConnection(FirebirdDriver* _pDriver) ...@@ -62,6 +63,7 @@ OConnection::OConnection(FirebirdDriver* _pDriver)
m_bUseOldDateFormat(sal_False) m_bUseOldDateFormat(sal_False)
{ {
m_pDriver->acquire(); m_pDriver->acquire();
m_DBHandler = NULL;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
OConnection::~OConnection() OConnection::~OConnection()
...@@ -78,56 +80,40 @@ void SAL_CALL OConnection::release() throw() ...@@ -78,56 +80,40 @@ void SAL_CALL OConnection::release() throw()
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/* Print the status, the SQLCODE, and exit.
* Also, indicate which operation the error occured on.
*/
static int pr_error (long* status, char* operation)
{
printf("[\n");
printf("PROBLEM ON \"%s\".\n", operation);
isc_print_status(status);
printf("SQLCODE:%d\n", isc_sqlcode(status));
printf("]\n");
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) throw(SQLException)
{ {
printf("DEBUG !!! connectivity.firebird", "=> OConnection::construct()" );
osl_atomic_increment( &m_refCount ); osl_atomic_increment( &m_refCount );
// some example code how to get the information out of the sequence // some example code how to get the information out of the sequence
sal_Int32 nLen = url.indexOf(':'); ISC_STATUS_ARRAY status; /* status vector */
nLen = url.indexOf(':',nLen+1); isc_db_handle db = NULL; /* database handle */
::rtl::OUString aDSN("DSN="), aUID, aPWD, aSysDrvSettings;
aDSN += url.copy(nLen+1); if (isc_attach_database(status, 0, "/home/javi/Firebird/test/new.fdb", &db, 0, NULL))
if (pr_error(status, "attach database"))
const char* pUser = "user"; return;
const char* pTimeout = "Timeout";
const char* pSilent = "Silent"; m_DBHandler = db;
const char* pPwd = "password";
const char* pUseCatalog = "UseCatalog";
const char* pSysDrv = "SystemDriverSettings";
sal_Int32 nTimeout = 20;
sal_Bool bSilent = sal_True;
const PropertyValue *pBegin = info.getConstArray();
const PropertyValue *pEnd = pBegin + info.getLength();
for(;pBegin != pEnd;++pBegin)
{
if(!pBegin->Name.compareToAscii(pTimeout))
pBegin->Value >>= nTimeout;
else if(!pBegin->Name.compareToAscii(pSilent))
pBegin->Value >>= bSilent;
else if(!pBegin->Name.compareToAscii(pUser))
{
pBegin->Value >>= aUID;
aDSN = aDSN + ::rtl::OUString(";UID=") + aUID;
}
else if(!pBegin->Name.compareToAscii(pPwd))
{
pBegin->Value >>= aPWD;
aDSN = aDSN + ::rtl::OUString(";PWD=") + aPWD;
}
else if(!pBegin->Name.compareToAscii(pUseCatalog))
{
pBegin->Value >>= m_bUseCatalog;
}
else if(!pBegin->Name.compareToAscii(pSysDrv))
{
pBegin->Value >>= aSysDrvSettings;
aDSN += ::rtl::OUString(";");
aDSN += aSysDrvSettings;
}
}
m_sUser = aUID;
osl_atomic_decrement( &m_refCount ); osl_atomic_decrement( &m_refCount );
} }
......
...@@ -50,6 +50,8 @@ ...@@ -50,6 +50,8 @@
#include <map> #include <map>
#include <ibase.h>
namespace connectivity namespace connectivity
{ {
namespace firebird namespace firebird
...@@ -64,6 +66,7 @@ namespace connectivity ...@@ -64,6 +66,7 @@ namespace connectivity
class FirebirdDriver; class FirebirdDriver;
class ODatabaseMetaData; class ODatabaseMetaData;
typedef OMetaConnection_BASE OConnection_BASE; // implements basics and text encoding typedef OMetaConnection_BASE OConnection_BASE; // implements basics and text encoding
typedef ::std::vector< ::connectivity::OTypeInfo> TTypeInfoVector; typedef ::std::vector< ::connectivity::OTypeInfo> TTypeInfoVector;
typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray; typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray;
...@@ -99,7 +102,7 @@ namespace connectivity ...@@ -99,7 +102,7 @@ namespace connectivity
sal_Bool m_bClosed; sal_Bool m_bClosed;
sal_Bool m_bUseCatalog; // should we use the catalog on filebased databases sal_Bool m_bUseCatalog; // should we use the catalog on filebased databases
sal_Bool m_bUseOldDateFormat; sal_Bool m_bUseOldDateFormat;
isc_db_handle m_DBHandler;
void buildTypeInfo() throw( ::com::sun::star::sdbc::SQLException); void buildTypeInfo() throw( ::com::sun::star::sdbc::SQLException);
...@@ -147,6 +150,7 @@ namespace connectivity ...@@ -147,6 +150,7 @@ namespace connectivity
// should we use the catalog on filebased databases // should we use the catalog on filebased databases
inline sal_Bool isCatalogUsed() const { return m_bUseCatalog; } inline sal_Bool isCatalogUsed() const { return m_bUseCatalog; }
inline ::rtl::OUString getUserName() const { return m_sUser; } inline ::rtl::OUString getUserName() const { return m_sUser; }
inline isc_db_handle getDBHandler() const { return m_DBHandler; }
inline FirebirdDriver* getDriver() const { return m_pDriver;} inline FirebirdDriver* getDriver() const { return m_pDriver;}
inline rtl_TextEncoding getTextEncoding() const { return m_nTextEncoding; } inline rtl_TextEncoding getTextEncoding() const { return m_nTextEncoding; }
}; };
......
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