Kaydet (Commit) 2511e662 authored tarafından David Ostrovsky's avatar David Ostrovsky

mork driver: refactoring query engine

Change-Id: Ia8dd0c29b4624601d8cb85cece0fcb2842c2d2f9
üst f188ca44
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include <string> #include <string>
#include <string.h> #include <string.h>
#include "resource/mork_res.hrc"
#include "resource/common_res.hrc"
#include <connectivity/dbexception.hxx> #include <connectivity/dbexception.hxx>
...@@ -80,6 +82,7 @@ MQueryHelper::MQueryHelper(const OColumnAlias& _ca) ...@@ -80,6 +82,7 @@ MQueryHelper::MQueryHelper(const OColumnAlias& _ca)
,m_bHasMore( sal_True ) ,m_bHasMore( sal_True )
,m_bAtEnd( sal_False ) ,m_bAtEnd( sal_False )
,m_rColumnAlias( _ca ) ,m_rColumnAlias( _ca )
,m_aError()
{ {
m_aResults.clear(); m_aResults.clear();
} }
...@@ -141,6 +144,7 @@ void MQueryHelper::reset() ...@@ -141,6 +144,7 @@ void MQueryHelper::reset()
m_bHasMore = sal_True; m_bHasMore = sal_True;
m_bAtEnd = sal_False; m_bAtEnd = sal_False;
clear_results(); clear_results();
m_aError.reset();
} }
MQueryHelperResultEntry* MQueryHelper::next() MQueryHelperResultEntry* MQueryHelper::next()
...@@ -290,97 +294,55 @@ sal_Int32 MQueryHelper::executeQuery(OConnection* xConnection) ...@@ -290,97 +294,55 @@ sal_Int32 MQueryHelper::executeQuery(OConnection* xConnection)
{ {
if ( (*evIter)->isStringExpr() ) { if ( (*evIter)->isStringExpr() ) {
MQueryExpressionString* evStr = static_cast<MQueryExpressionString*> (*evIter); MQueryExpressionString* evStr = static_cast<MQueryExpressionString*> (*evIter);
// Set the 'name' property of the boolString. // Set the 'name' property of the boolString.
// Check if it's an alias first...
rtl::OString attrName = _aQuery->getColumnAlias().getProgrammaticNameOrFallbackToUTF8Alias( evStr->getName() ); rtl::OString attrName = _aQuery->getColumnAlias().getProgrammaticNameOrFallbackToUTF8Alias( evStr->getName() );
//OSL_TRACE("Name = %s ;", attrName.getStr() );
SAL_INFO("connectivity.mork", "Name = " << attrName.getStr()); SAL_INFO("connectivity.mork", "Name = " << attrName.getStr());
// Set the 'matchType' property of the boolString. Check for equal length.
sal_Bool requiresValue = sal_True; sal_Bool requiresValue = sal_True;
switch(evStr->getCond()) {
case MQueryOp::Exists:
SAL_INFO("connectivity.mork", "MQueryOp::Exists; done");
//boolString->SetCondition(nsIAbBooleanConditionTypes::Exists);
requiresValue = sal_False;
break;
case MQueryOp::DoesNotExist:
SAL_INFO("connectivity.mork", "MQueryOp::DoesNotExist; done");
//boolString->SetCondition(nsIAbBooleanConditionTypes::DoesNotExist);
requiresValue = sal_False;
break;
case MQueryOp::Contains:
SAL_INFO("connectivity.mork", "MQueryOp::Contains; done");
//boolString->SetCondition(nsIAbBooleanConditionTypes::Contains);
break;
case MQueryOp::DoesNotContain:
SAL_INFO("connectivity.mork", "MQueryOp::DoesNotContain; done");
//boolString->SetCondition(nsIAbBooleanConditionTypes::DoesNotContain);
break;
case MQueryOp::Is:
SAL_INFO("connectivity.mork", "MQueryOp::Is; done");
//boolString->SetCondition(nsIAbBooleanConditionTypes::Is);
break;
case MQueryOp::IsNot:
SAL_INFO("connectivity.mork", "MQueryOp::IsNot; done");
//boolString->SetCondition(nsIAbBooleanConditionTypes::IsNot);
break;
case MQueryOp::BeginsWith:
SAL_INFO("connectivity.mork", "MQueryOp::BeginsWith; done");
//boolString->SetCondition(nsIAbBooleanConditionTypes::BeginsWith);
break;
case MQueryOp::EndsWith:
SAL_INFO("connectivity.mork", "MQueryOp::EndsWith; done");
//boolString->SetCondition(nsIAbBooleanConditionTypes::EndsWith);
break;
case MQueryOp::SoundsLike:
SAL_INFO("connectivity.mork", "MQueryOp::SoundsLike; TODO");
//boolString->SetCondition(nsIAbBooleanConditionTypes::SoundsLike);
break;
case MQueryOp::RegExp:
SAL_INFO("connectivity.mork", "MQueryOp::RegExp; TODO");
//boolString->SetCondition(nsIAbBooleanConditionTypes::RegExp);
break;
default:
SAL_INFO("connectivity.mork", "(default) MQueryOp::Is; ");
//boolString->SetCondition(nsIAbBooleanConditionTypes::Is);
break;
}
rtl::OUString currentValue = entry->getValue(attrName); rtl::OUString currentValue = entry->getValue(attrName);
// Set the 'matchValue' property of the boolString. Value returned in unicode. if (evStr->getCond() == MQueryOp::Exists || evStr->getCond() == MQueryOp::DoesNotExist)
if ( requiresValue ) {
requiresValue = sal_False;
}
if (requiresValue)
{ {
SAL_INFO("connectivity.mork", "Value = " << evStr->getValue() ); SAL_INFO("connectivity.mork", "Value = " << evStr->getValue() );
rtl::OUString searchedValue = evStr->getValue(); rtl::OUString searchedValue = evStr->getValue();
if (evStr->getCond() == MQueryOp::Is) { if (evStr->getCond() == MQueryOp::Is) {
SAL_INFO("connectivity.mork", "MQueryOp::Is; done");
resultVector.push_back((currentValue == searchedValue) ? sal_True : sal_False); resultVector.push_back((currentValue == searchedValue) ? sal_True : sal_False);
} else if (evStr->getCond() == MQueryOp::IsNot) { } else if (evStr->getCond() == MQueryOp::IsNot) {
SAL_INFO("connectivity.mork", "MQueryOp::IsNot; done");
resultVector.push_back((currentValue == searchedValue) ? sal_False : sal_True); resultVector.push_back((currentValue == searchedValue) ? sal_False : sal_True);
} else if (evStr->getCond() == MQueryOp::EndsWith) { } else if (evStr->getCond() == MQueryOp::EndsWith) {
SAL_INFO("connectivity.mork", "MQueryOp::EndsWith; done");
resultVector.push_back((currentValue.endsWith(searchedValue)) ? sal_True : sal_False); resultVector.push_back((currentValue.endsWith(searchedValue)) ? sal_True : sal_False);
} else if (evStr->getCond() == MQueryOp::BeginsWith) { } else if (evStr->getCond() == MQueryOp::BeginsWith) {
SAL_INFO("connectivity.mork", "MQueryOp::BeginsWith; done");
resultVector.push_back((currentValue.indexOf(searchedValue) == 0) ? sal_True : sal_False); resultVector.push_back((currentValue.indexOf(searchedValue) == 0) ? sal_True : sal_False);
} else if (evStr->getCond() == MQueryOp::Contains) { } else if (evStr->getCond() == MQueryOp::Contains) {
SAL_INFO("connectivity.mork", "MQueryOp::Contains; done");
resultVector.push_back((currentValue.indexOf(searchedValue) == -1) ? sal_False : sal_True); resultVector.push_back((currentValue.indexOf(searchedValue) == -1) ? sal_False : sal_True);
} else if (evStr->getCond() == MQueryOp::DoesNotContain) { } else if (evStr->getCond() == MQueryOp::DoesNotContain) {
SAL_INFO("connectivity.mork", "MQueryOp::DoesNotContain; done");
resultVector.push_back((currentValue.indexOf(searchedValue) == -1) ? sal_True : sal_False); resultVector.push_back((currentValue.indexOf(searchedValue) == -1) ? sal_True : sal_False);
} else { } else if (evStr->getCond() == MQueryOp::RegExp) {
OSL_FAIL("not yet implemented"); SAL_WARN("connectivity.mork", "MQueryOp::RegExp; TODO");
OSL_FAIL("regexp criterion is not yet implemented");
_aQuery->getError().setResId(STR_ERROR_GET_ROW);
} }
} } else if (evStr->getCond() == MQueryOp::Exists) {
SAL_INFO("connectivity.mork", "MQueryOp::Exists; done");
// Find it and change it ;-) resultVector.push_back((currentValue.isEmpty()) ? sal_False : sal_True);
// class rtl::OUString "has no element named" isEmtpy
if (evStr->getCond() == MQueryOp::Exists) {
resultVector.push_back((currentValue.getLength() == 0) ? sal_False : sal_True);
} else if (evStr->getCond() == MQueryOp::DoesNotExist) { } else if (evStr->getCond() == MQueryOp::DoesNotExist) {
resultVector.push_back((currentValue.getLength() == 0) ? sal_True : sal_False); SAL_INFO("connectivity.mork", "MQueryOp::DoesNotExist; done");
resultVector.push_back((currentValue.isEmpty()) ? sal_True : sal_False);
} }
} }
else if ( (*evIter)->isExpr() ) { else if ( (*evIter)->isExpr() ) {
SAL_INFO("connectivity.mork", "Appending Subquery Expression"); SAL_INFO("connectivity.mork", "Appending Subquery Expression");
MQueryExpression* queryExpression = static_cast<MQueryExpression*> (*evIter); MQueryExpression* queryExpression = static_cast<MQueryExpression*> (*evIter);
::std::vector<sal_Bool> subquery_result = entryMatchedByExpression(_aQuery, queryExpression, entry); // recursive call
::std::vector<sal_Bool> subquery_result = entryMatchedByExpression(_aQuery, queryExpression, entry);
MQueryExpression::bool_cond condition = queryExpression->getExpressionCondition(); MQueryExpression::bool_cond condition = queryExpression->getExpressionCondition();
if (condition == MQueryExpression::OR) { if (condition == MQueryExpression::OR) {
sal_Bool result = sal_False; sal_Bool result = sal_False;
...@@ -400,8 +362,8 @@ sal_Int32 MQueryHelper::executeQuery(OConnection* xConnection) ...@@ -400,8 +362,8 @@ sal_Int32 MQueryHelper::executeQuery(OConnection* xConnection)
} }
else { else {
// Should never see this... // Should never see this...
// OSL_FAIL("Unknown Expression Type!");
SAL_WARN("connectivity.mork", "Unknown Expression Type!"); SAL_WARN("connectivity.mork", "Unknown Expression Type!");
_aQuery->getError().setResId(STR_ERROR_GET_ROW);
return resultVector; return resultVector;
} }
} }
......
...@@ -50,8 +50,7 @@ namespace connectivity ...@@ -50,8 +50,7 @@ namespace connectivity
IsNot = 5, IsNot = 5,
BeginsWith = 6, BeginsWith = 6,
EndsWith = 7, EndsWith = 7,
SoundsLike = 8, RegExp = 8
RegExp = 9
} cond_type; } cond_type;
} }
...@@ -201,7 +200,7 @@ namespace connectivity ...@@ -201,7 +200,7 @@ namespace connectivity
sal_Int32 executeQuery(OConnection* xConnection); sal_Int32 executeQuery(OConnection* xConnection);
const OColumnAlias& getColumnAlias() const { return m_rColumnAlias; } const OColumnAlias& getColumnAlias() const { return m_rColumnAlias; }
bool hadError() const { return m_aError.is(); } bool hadError() const { return m_aError.is(); }
inline const ErrorDescriptor& getError() const { return m_aError; } inline ErrorDescriptor& getError() { return m_aError; }
void setAddressbook( ::rtl::OUString&); void setAddressbook( ::rtl::OUString&);
void setExpression( MQueryExpression &_expr ); void setExpression( MQueryExpression &_expr );
......
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