summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVishesh Handa <me@vhanda.in>2013-05-25 20:00:54 (GMT)
committerVishesh Handa <me@vhanda.in>2013-05-25 20:00:54 (GMT)
commitb8fb9056c201ba8ba9645c55d024a4d42b79a20a (patch)
tree36e1ea0e2a4818cbf99c037a9e64a332f353b31a
parentdda25ad5818ef41832a141267f1b614a8dbc6b99 (diff)
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.
-rw-r--r--backends/virtuoso/odbcqueryresult.cpp35
1 files changed, 24 insertions, 11 deletions
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 ) ) ) {
- 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;
}