[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: Re: [soprano/2.9] backends/virtuoso: VirtuosoBackend: Avoid calling SQLGetDescField unnecessarily
From: Sebastian TrĂ¼g <sebastian () trueg ! de>
Date: 2013-07-11 7:36:34
Message-ID: 51DE6082.8090509 () trueg ! de
[Download RAW message or body]
A quick question on this:
On 05/28/2013 05:24 PM, Vishesh Handa wrote:
> Git commit b8fb9056c201ba8ba9645c55d024a4d42b79a20a by Vishesh Handa.
> Committed on 25/05/2013 at 22:00.
> Pushed by vhanda into branch '2.9'.
>
> VirtuosoBackend: Avoid calling SQLGetDescField unnecessarily
>
> When fetching a literal node, it can either have a type or have a
> language. We should not attempt to fetch both the langauge and type and
> then check which one succeded.
>
> Instead we first fetch the type, and only if that fails do we fetch the
> lanaguge. This way we avoid one extra SQLGetDescField call when it is
> not required.
>
> M +24 -11 backends/virtuoso/odbcqueryresult.cpp
>
> http://commits.kde.org/soprano/b8fb9056c201ba8ba9645c55d024a4d42b79a20a
>
> diff --git a/backends/virtuoso/odbcqueryresult.cpp \
> b/backends/virtuoso/odbcqueryresult.cpp index 0440dc9..688b604 100644
> --- a/backends/virtuoso/odbcqueryresult.cpp
> +++ b/backends/virtuoso/odbcqueryresult.cpp
> @@ -180,25 +180,24 @@ Soprano::Node Soprano::ODBC::QueryResult::getData( int colNum \
> ) //
> // Retrieve lang and type strings which are cached in the server for faster lookups
> //
> - SQLCHAR langBuf[100];
> SQLCHAR typeBuf[100];
> - SQLINTEGER langBufLen = 0;
> SQLINTEGER typeBufLen = 0;
> - if ( !SQL_SUCCEEDED( SQLGetDescField( hdesc, colNum, \
> SQL_DESC_COL_LITERAL_LANG, langBuf, sizeof( langBuf ), &langBufLen \
> ) ) ||
> - !SQL_SUCCEEDED( SQLGetDescField( hdesc, colNum, \
> SQL_DESC_COL_LITERAL_TYPE, typeBuf, sizeof( typeBuf ), &typeBufLen ) ) ) {
would it not have been enough to change the "||" to a "&&" to get the
same effect?
> - setError( Virtuoso::convertSqlError( SQL_HANDLE_STMT, d->m_hstmt, \
> QLatin1String( "SQLGetDescField SQL_DESC_COL_LITERAL_* failed" ) ) \
> );
> - return Node();
> - }
> +
> + bool fetchTypeSucceded = SQL_SUCCEEDED( SQLGetDescField( hdesc, \
> colNum, + \
> SQL_DESC_COL_LITERAL_TYPE, + \
> typeBuf, sizeof( typeBuf ), &typeBufLen ) );
> const char* str = reinterpret_cast<const char*>( data );
> - const char* typeStr = reinterpret_cast<const char*>( typeBuf );
>
> - if ( typeBufLen > 0 ) {
> + if( fetchTypeSucceded ) {
> + const char* typeStr = reinterpret_cast<const char*>( typeBuf );
> +
> if ( !qstrncmp( typeStr, Virtuoso::fakeBooleanTypeString(), typeBufLen ) ) {
> node = Node( LiteralValue( !qstrcmp( "true", str ) ) );
> }
> else {
> QUrl type;
> + // FIXME: Disable these checks based on the backend settings!
> if ( !qstrncmp( typeStr, Virtuoso::fakeBase64BinaryTypeString(), typeBufLen ) )
> type = Soprano::Vocabulary::XMLSchema::base64Binary();
> else
> @@ -207,8 +206,22 @@ Soprano::Node Soprano::ODBC::QueryResult::getData( int colNum \
> ) }
> }
> else {
> - QString lang = QString::fromLatin1( reinterpret_cast<const char*>( \
> langBuf ), langBufLen );
> - node = Node( LiteralValue::createPlainLiteral( QString::fromUtf8( \
> str ), lang ) ); + SQLCHAR langBuf[100];
> + SQLINTEGER langBufLen = 0;
> +
> + bool fetchLangSucceded = SQL_SUCCEEDED( SQLGetDescField( hdesc, \
> colNum, + \
> SQL_DESC_COL_LITERAL_LANG, + \
> langBuf, sizeof( langBuf ), &langBufLen ) ); +
> + if( fetchLangSucceded ) {
> + QString lang = QString::fromLatin1( reinterpret_cast<const \
> char*>( langBuf ), langBufLen ); + node = Node( \
> LiteralValue::createPlainLiteral( QString::fromUtf8( str ), lang ) ); + \
> } + else {
> + setError( Virtuoso::convertSqlError( SQL_HANDLE_STMT, \
> d->m_hstmt, + \
> QLatin1String( "SQLGetDescField SQL_DESC_COL_LITERAL_* failed" ) ) ); + \
> return Node(); + }
> }
> break;
> }
>
>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic