diff options
author | Javier Fernandez <jfernandez@igalia.com> | 2013-05-22 08:56:23 +0000 |
---|---|---|
committer | Andrzej J.R. Hunt <andrzej@ahunt.org> | 2013-07-16 16:40:04 +0200 |
commit | d6855a708cac757127e8d529083402761d1fe2ac (patch) | |
tree | c5db0f86466d9fb329895c6a32ec02b0ebac681b | |
parent | aa5b1bb3f263c433a78f34e7066e5a3c4ed97ae9 (diff) |
Debug info and some API methods implementation.
* getTypeInfo
* getTables
* prepared statements.
Change-Id: I549f4a9468b5346e22479363fe0fb81039bc6665
5 files changed, 305 insertions, 7 deletions
diff --git a/connectivity/source/drivers/firebird/FConnection.cxx b/connectivity/source/drivers/firebird/FConnection.cxx index 671a2403d659..d4948295e0dc 100644 --- a/connectivity/source/drivers/firebird/FConnection.cxx +++ b/connectivity/source/drivers/firebird/FConnection.cxx @@ -138,6 +138,8 @@ IMPLEMENT_SERVICE_INFO(OConnection, "com.sun.star.sdbc.drivers.firebird.OConnect // -------------------------------------------------------------------------------- Reference< XStatement > SAL_CALL OConnection::createStatement( ) throw(SQLException, RuntimeException) { + printf("DEBUG !!! connectivity.firebird => OConnection::createStatement got called \n"); + ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OConnection_BASE::rBHelper.bDisposed); @@ -150,6 +152,9 @@ Reference< XStatement > SAL_CALL OConnection::createStatement( ) throw(SQLExcep // -------------------------------------------------------------------------------- Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement( const ::rtl::OUString& _sSql ) throw(SQLException, RuntimeException) { + printf("DEBUG !!! connectivity.firebird => OConnection::prepareStatement got called with sql: %s \n", + OUStringToOString(_sSql , RTL_TEXTENCODING_ASCII_US ).getStr()); + ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OConnection_BASE::rBHelper.bDisposed); @@ -157,10 +162,15 @@ Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement( const :: if(m_aTypeInfo.empty()) buildTypeInfo(); + printf("DEBUG !!! connectivity.firebird => OConnection::prepareStatement Creating prepared statement. \n"); + // create a statement // the statement can only be executed more than once Reference< XPreparedStatement > xReturn = new OPreparedStatement(this,m_aTypeInfo,_sSql); m_aStatements.push_back(WeakReferenceHelper(xReturn)); + + printf("DEBUG !!! connectivity.firebird => OConnection::prepareStatement Prepared Statement created. \n"); + return xReturn; } // -------------------------------------------------------------------------------- @@ -225,6 +235,8 @@ sal_Bool SAL_CALL OConnection::isClosed( ) throw(SQLException, RuntimeException // -------------------------------------------------------------------------------- Reference< XDatabaseMetaData > SAL_CALL OConnection::getMetaData( ) throw(SQLException, RuntimeException) { + printf ("DEBUG !!! __ OConnection::getMetaData() __ \n"); + ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OConnection_BASE::rBHelper.bDisposed); @@ -335,6 +347,8 @@ void SAL_CALL OConnection::clearWarnings( ) throw(SQLException, RuntimeExceptio //-------------------------------------------------------------------- void OConnection::buildTypeInfo() throw( SQLException) { + printf("DEBUG !!! connectivity.firebird => OConnection::buildTypeInfo() got called \n"); + ::osl::MutexGuard aGuard( m_aMutex ); Reference< XResultSet> xRs = getMetaData ()->getTypeInfo (); @@ -372,10 +386,14 @@ void OConnection::buildTypeInfo() throw( SQLException) m_aTypeInfo.push_back(aInfo); } + printf("DEBUG !!! connectivity.firebird => OConnection::buildTypeInfo() type info built. \n"); + // Close the result set/statement. Reference< XCloseable> xClose(xRs,UNO_QUERY); xClose->close(); + + printf("DEBUG !!! connectivity.firebird => OConnection::buildTypeInfo() closed. \n"); } //------------------------------------------------------------------------------ void OConnection::disposing() diff --git a/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx b/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx index 64466febc588..0225f12b6b9f 100644 --- a/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx +++ b/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx @@ -34,10 +34,13 @@ *************************************************************************/ #include "FDatabaseMetaData.hxx" +#include "FDatabaseMetaDataResultSet.hxx" #include <com/sun/star/sdbc/DataType.hpp> #include <com/sun/star/sdbc/ResultSetType.hpp> #include <com/sun/star/sdbc/ResultSetConcurrency.hpp> #include <com/sun/star/sdbc/TransactionIsolation.hpp> +#include <com/sun/star/sdbc/XParameters.hpp> +#include <com/sun/star/sdbc/XRow.hpp> using namespace connectivity::firebird; using namespace com::sun::star::uno; @@ -45,6 +48,17 @@ using namespace com::sun::star::lang; using namespace com::sun::star::beans; using namespace com::sun::star::sdbc; +namespace connectivity +{ + namespace firebird + { + static sal_Int32 const s_nCOLUMN_SIZE = 256; + static sal_Int32 const s_nDECIMAL_DIGITS = 0; + static sal_Int32 const s_nNULLABLE = 1; + static sal_Int32 const s_nCHAR_OCTET_LENGTH = 65535; + } +} + ODatabaseMetaData::ODatabaseMetaData(OConnection* _pCon) : m_pConnection(_pCon) , m_bUseCatalog(sal_True) @@ -776,7 +790,44 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTableTypes( ) throw(SQLE // ------------------------------------------------------------------------- Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo( ) throw(SQLException, RuntimeException) { - return NULL; + printf("DEBUG !!! connectivity.firebird => ODatabaseMetaData::getTypeInfo got called \n"); + + // this returns an empty resultset where the column-names are already set + // in special the metadata of the resultset already returns the right columns + ODatabaseMetaDataResultSet* pResultSet = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTypeInfo); + Reference< XResultSet > xResultSet = pResultSet; + static ODatabaseMetaDataResultSet::ORows aRows; + + if(aRows.empty()) + { + ODatabaseMetaDataResultSet::ORow aRow; + aRow.reserve(19); + aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); + aRow.push_back(new ORowSetValueDecorator(OUString("VARCHAR"))); + aRow.push_back(new ORowSetValueDecorator(DataType::VARCHAR)); + aRow.push_back(new ORowSetValueDecorator((sal_Int32)s_nCHAR_OCTET_LENGTH)); + aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue()); + aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue()); + aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); + // aRow.push_back(new ORowSetValueDecorator((sal_Int32)ColumnValue::NULLABLE)); + aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); + aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); + aRow.push_back(new ORowSetValueDecorator((sal_Int32)ColumnSearch::CHAR)); + aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); + aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); + aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); + aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); + aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); + aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); + aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); + aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); + aRow.push_back(new ORowSetValueDecorator((sal_Int32)10)); + + aRows.push_back(aRow); + + } + pResultSet->setRows(aRows); + return xResultSet; } // ------------------------------------------------------------------------- Reference< XResultSet > SAL_CALL ODatabaseMetaData::getCatalogs( ) throw(SQLException, RuntimeException) @@ -807,7 +858,86 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables( const Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& tableNamePattern, const Sequence< ::rtl::OUString >& types ) throw(SQLException, RuntimeException) { - return NULL; + printf("DEBUG !!! connectivity.firebird => ODatabaseMetaData::getTables() got called with schemaPattern: %s and tableNamePattern: %s \n", + OUStringToOString( schemaPattern, RTL_TEXTENCODING_ASCII_US ).getStr(), + OUStringToOString( tableNamePattern, RTL_TEXTENCODING_ASCII_US ).getStr()); + + ODatabaseMetaDataResultSet* pResultSet = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTables); + Reference< XResultSet > xResultSet = pResultSet; + + /* + Reference< XPreparedStatement > statement = m_pConnection->prepareStatement( + "SELECT " + "'schema' as schema, RDB$RELATION_NAME, RDB$SYSTEM_FLAG, RDB$RELATION_TYPE, 'description' as description " // avoid duplicates + "FROM RDB$RELATIONS " + "WHERE (RDB$RELATION_TYPE = 0 OR RDB$RELATION_TYPE = 1) " + "AND 'schema' LIKE ? " + "AND RDB$RELATION_NAME LIKE ? "); + */ + Reference< XPreparedStatement > statement = m_pConnection->prepareStatement( + "SELECT " + "RDB$RELATION_NAME " // avoid duplicates + "FROM RDB$RELATIONS " + "WHERE (RDB$RELATION_TYPE = 0 OR RDB$RELATION_TYPE = 1) "); + + printf("DEBUG !!! connectivity.firebird => ODatabaseMetaData::getTables() Setting query parameters. \n"); + + Reference< XParameters > parameters( statement, UNO_QUERY_THROW ); + parameters->setString( 1 , schemaPattern ); + parameters->setString( 2 , tableNamePattern ); + + printf("DEBUG !!! connectivity.firebird => ODatabaseMetaData::getTables() About to execute the query. \n"); + + Reference< XResultSet > rs = statement->executeQuery(); + Reference< XRow > xRow( rs, UNO_QUERY_THROW ); + ODatabaseMetaDataResultSet::ORows aRows; + while( rs->next() ) + { + ODatabaseMetaDataResultSet::ORow aRow(3); + OUString aTableName = xRow->getString( 2 ); + + printf("DEBUG !!! connectivity.firebird => TableName: %s \n", + OUStringToOString( aTableName, RTL_TEXTENCODING_ASCII_US ).getStr()); + + OUString type = xRow->getString(3); + OUString aTableType; + if( 0 == type.compareToAscii( "1" ) ) + { + aTableType = OUString::createFromAscii("SYSTEM TABLE"); + + } else { + + if( 0 == xRow->getString(4).compareToAscii( "0" ) ) + { + aTableType = OUString::createFromAscii("TABLE"); + } + else + { + aTableType = OUString::createFromAscii("VIEW"); + } + } + + printf("DEBUG !!! connectivity.firebird => TableType: %s \n", + OUStringToOString( aTableType, RTL_TEXTENCODING_ASCII_US ).getStr()); + + aRow.push_back( new ORowSetValueDecorator( aTableName ) ); // Table name + aRow.push_back( new ORowSetValueDecorator( aTableType ) ); // Table type + aRow.push_back( ODatabaseMetaDataResultSet::getEmptyValue() ); // Remarks + aRows.push_back(aRow); + } + + pResultSet->setRows( aRows ); + + try + { + Reference< XRow > xCurrentRow( xResultSet, UNO_QUERY_THROW ); + } + catch (const Exception&) + { + printf("DEBUG !!! connectivity.firebird => getTables thrown an Exception. \n"); + } + + return xResultSet; } // ------------------------------------------------------------------------- Reference< XResultSet > SAL_CALL ODatabaseMetaData::getProcedureColumns( diff --git a/connectivity/source/drivers/firebird/FPreparedStatement.cxx b/connectivity/source/drivers/firebird/FPreparedStatement.cxx index b597c65cd931..59bd67936752 100644 --- a/connectivity/source/drivers/firebird/FPreparedStatement.cxx +++ b/connectivity/source/drivers/firebird/FPreparedStatement.cxx @@ -42,6 +42,8 @@ #include <com/sun/star/lang/DisposedException.hpp> #include "propertyids.hxx" +#include <ibase.h> + using namespace connectivity::firebird; using namespace com::sun::star::uno; using namespace com::sun::star::lang; @@ -160,15 +162,83 @@ Reference< XConnection > SAL_CALL OPreparedStatement::getConnection( ) throw(SQ } // ------------------------------------------------------------------------- +/* + * 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; +} + Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery( ) throw(SQLException, RuntimeException) { + char sqlStr[128]; + strcpy(sqlStr, OUStringToOString( m_sSqlStatement, RTL_TEXTENCODING_ASCII_US ).getStr()); + printf("DEBUG !!! connectivity.firebird => OPreparedStatement::executeQuery() got called with sql: %s \n", sqlStr); + ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OStatement_BASE::rBHelper.bDisposed); - Reference< XResultSet > rs = NULL; - - - return rs; + Reference< XResultSet > xRS = NULL; + // create a resultset as result of executing the sql statement + // you have to here something :-) + + ISC_STATUS_ARRAY status; /* status vector */ + isc_db_handle db = NULL; /* database handle */ + isc_tr_handle trans = NULL; /* transaction handle */ + isc_stmt_handle stmt = NULL; /* prepared statement handle */ + XSQLDA * sel_sqlda; + int CURRENLEN = 10; + char orig_name[CURRENLEN + 1]; + + if (isc_attach_database(status, 0, "/home/javi/Firebird/test/new.fdb", &db, 0, NULL)) + if (pr_error(status, "attach database")) + return xRS; + + if (isc_start_transaction(status, &trans, 1, &db, 0, NULL)) + if (pr_error(status, "start transaction")) + return xRS; + + sel_sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(1)); + sel_sqlda->sqln = 1; + sel_sqlda->version = 1; + + if (isc_dsql_allocate_statement(status, &db, &stmt)) + if (pr_error(status, "allocate statement")) + return xRS; + if (isc_dsql_prepare(status, &trans, &stmt, 0, sqlStr, 1, sel_sqlda)) + if (pr_error(status, "prepare statement")) + return xRS; + + sel_sqlda->sqlvar[0].sqldata = orig_name; + sel_sqlda->sqlvar[0].sqltype = SQL_TEXT; + sel_sqlda->sqlvar[0].sqllen = CURRENLEN; + + if (isc_dsql_execute(status, &trans, &stmt, 1, NULL)) + if (pr_error(status, "execute query")) + return xRS; + if (isc_dsql_fetch(status, &stmt, 1, sel_sqlda)) + if (pr_error(status, "fetch data")) + return xRS; + + if (isc_commit_transaction (status, &trans)) + isc_print_status(status); + printf("DEBuG !!! connectivity.firebird => OPreparedStatement::executeQuery() Changes committed.\n"); + + orig_name[CURRENLEN] = '\0'; + printf("Modifying currency string: %s\n", orig_name); + + return xRS; } // ------------------------------------------------------------------------- diff --git a/connectivity/source/drivers/firebird/FStatement.cxx b/connectivity/source/drivers/firebird/FStatement.cxx index 153b99352818..53452703850b 100644 --- a/connectivity/source/drivers/firebird/FStatement.cxx +++ b/connectivity/source/drivers/firebird/FStatement.cxx @@ -46,6 +46,8 @@ #include <cppuhelper/typeprovider.hxx> #include "propertyids.hxx" +#include <ibase.h> + using namespace connectivity::firebird; //------------------------------------------------------------------------------ using namespace com::sun::star::uno; @@ -151,18 +153,84 @@ sal_Bool SAL_CALL OStatement_Base::execute( const ::rtl::OUString& sql ) throw(S } // ------------------------------------------------------------------------- +/* + * 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; +} + Reference< XResultSet > SAL_CALL OStatement_Base::executeQuery( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) { + char sqlStr[128]; + strcpy(sqlStr, OUStringToOString( sql, RTL_TEXTENCODING_ASCII_US ).getStr()); + printf("DEBUG !!! connectivity.firebird => OStatement_Base::executeQuery() got called with sql: %s \n", sqlStr); + ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OStatement_BASE::rBHelper.bDisposed); - Reference< XResultSet > xRS = NULL; // create a resultset as result of executing the sql statement // you have to here something :-) + + ISC_STATUS_ARRAY status; /* status vector */ + isc_db_handle db = NULL; /* database handle */ + isc_tr_handle trans = NULL; /* transaction handle */ + isc_stmt_handle stmt = NULL; /* prepared statement handle */ + XSQLDA * sel_sqlda; + int CURRENLEN = 10; + char orig_name[CURRENLEN + 1]; + + if (isc_attach_database(status, 0, "new.fdb", &db, 0, NULL)) + if (pr_error(status, "attach database")) + return xRS; + + if (isc_start_transaction(status, &trans, 1, &db, 0, NULL)) + if (pr_error(status, "start transaction")) + return xRS; + + sel_sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(1)); + sel_sqlda->sqln = 1; + sel_sqlda->version = 1; + + if (isc_dsql_allocate_statement(status, &db, &stmt)) + if (pr_error(status, "allocate statement")) + return xRS; + if (isc_dsql_prepare(status, &trans, &stmt, 0, sqlStr, 1, sel_sqlda)) + if (pr_error(status, "prepare statement")) + return xRS; + + sel_sqlda->sqlvar[0].sqldata = orig_name; + sel_sqlda->sqlvar[0].sqltype = SQL_TEXT; + sel_sqlda->sqlvar[0].sqllen = CURRENLEN; + + if (isc_dsql_execute(status, &trans, &stmt, 1, NULL)) + if (pr_error(status, "execute query")) + return xRS; + if (isc_dsql_fetch(status, &stmt, 1, sel_sqlda)) + if (pr_error(status, "fetch data")) + return xRS; + + if (isc_commit_transaction (status, &trans)) + isc_print_status(status); + printf("DEBuG !!! connectivity.firebird => OStatement_Base::executeQuery() Changes committed.\n"); + m_xResultSet = xRS; // we nedd a reference to it for later use return xRS; } + + // ------------------------------------------------------------------------- Reference< XConnection > SAL_CALL OStatement_Base::getConnection( ) throw(SQLException, RuntimeException) diff --git a/dbaccess/source/core/api/FilteredContainer.cxx b/dbaccess/source/core/api/FilteredContainer.cxx index 3f405b27114f..448a405671e6 100644 --- a/dbaccess/source/core/api/FilteredContainer.cxx +++ b/dbaccess/source/core/api/FilteredContainer.cxx @@ -305,9 +305,13 @@ sal_Int32 createWildCardVector(Sequence< OUString >& _rTableFilter, ::std::vecto try { + printf ("DEBUG !!! __ OFilteredContainer::construct __ getting metadata ... \n"); + Reference< XConnection > xCon( m_xConnection, UNO_SET_THROW ); m_xMetaData.set( xCon->getMetaData(), UNO_SET_THROW ); + printf ("DEBUG !!! __ OFilteredContainer::construct __ metadata got \n"); + // create a table table filter suitable for the XDatabaseMetaData::getTables call, // taking into account both the externally-provided table type filter, and any // table type restriction which is inherent to the container @@ -315,6 +319,8 @@ sal_Int32 createWildCardVector(Sequence< OUString >& _rTableFilter, ::std::vecto OUString sInherentTableTypeRestriction( getTableTypeRestriction() ); if ( !sInherentTableTypeRestriction.isEmpty() ) { + printf ("DEBUG !!! __ OFilteredContainer::construct __ NOT InherentTableTypeRestriction \n"); + if ( _rTableTypeFilter.getLength() != 0 ) { const OUString* tableType = _rTableTypeFilter.getConstArray(); @@ -336,6 +342,8 @@ sal_Int32 createWildCardVector(Sequence< OUString >& _rTableFilter, ::std::vecto } else { + printf ("DEBUG !!! __ OFilteredContainer::construct __ InherentTableTypeRestriction \n"); + // no container-inherent restriction for the table types if ( _rTableTypeFilter.getLength() == 0 ) { // no externally-provided table type filter => use the default filter @@ -347,10 +355,14 @@ sal_Int32 createWildCardVector(Sequence< OUString >& _rTableFilter, ::std::vecto } } + printf ("DEBUG !!! __ OFilteredContainer::construct __ getting tables ... \n"); + static const OUString sAll("%"); Reference< XResultSet > xTables = m_xMetaData->getTables( Any(), sAll, sAll, aTableTypeFilter ); Reference< XRow > xCurrentRow( xTables, UNO_QUERY_THROW ); + printf ("DEBUG !!! __ OFilteredContainer::construct __ tables got \n"); + TableInfos aUnfilteredTables; OUString sCatalog, sSchema, sName, sType; |