--- a/contentstorage/castorage/src/casqlquerycreator.cpp Tue Mar 23 23:55:55 2010 +0200
+++ b/contentstorage/castorage/src/casqlquerycreator.cpp Wed Mar 24 03:15:43 2010 +0200
@@ -668,26 +668,115 @@
&typeNameWhereStatement );
CleanupStack::PopAndDestroy( &typeNameWhereStatement );
}
+
+ if( aQuery->GetAttributes().Count() )
+ {
+ RBuf whereAttributes;
+ whereAttributes.CleanupClosePushL();
+ whereAttributes.CreateL( KEmpty );
+
+ for( TInt j=1; j <= aQuery->GetAttributes().Count(); j++ )
+ {
+ // at1.AT_NAME = 'Attribute_Name_1' AND at1.AT_VALUE = 'Attribute_VALUE_1'
+ TPtrC atrName( aQuery->GetAttributes().operator [](j-1)->Name() );
+ TPtrC atrValue( aQuery->GetAttributes().operator [](j-1)->Value() );
+
+ whereAttributes.ReAllocL( whereAttributes.Length() + 2 * KAnd().Length() +
+ 4 * KSingleQuotes().Length() +
+ 2 * KMaxIntNumLength +
+ 2 * KAt().Length() + 2 * KDot().Length() + 2 * KEqual().Length() +
+ KColumnAttrName().Length() + KColumnAttrValue().Length() +
+ atrName.Length() + atrValue.Length() );
+
+ whereAttributes.Append( KAnd );
+
+ whereAttributes.Append( KAt );
+ whereAttributes.AppendNum( j );
+ whereAttributes.Append( KDot );
+ whereAttributes.Append( KColumnAttrName );
+ whereAttributes.Append( KEqual );
+ whereAttributes.Append( KSingleQuotes );
+ whereAttributes.Append( atrName );
+ whereAttributes.Append( KSingleQuotes );
+
+ whereAttributes.Append( KAnd );
+
+ whereAttributes.Append( KAt );
+ whereAttributes.AppendNum( j );
+ whereAttributes.Append( KDot );
+ whereAttributes.Append( KColumnAttrValue );
+ whereAttributes.Append( KEqual );
+ whereAttributes.Append( KSingleQuotes );
+ whereAttributes.Append( atrValue );
+ whereAttributes.Append( KSingleQuotes );
+
+ }
+
+ whereStatement.ReAllocL( whereStatement.Length() + whereAttributes.Length() );
+ whereStatement.Append( whereAttributes );
+
+ CleanupStack::PopAndDestroy( &whereAttributes );
+ }
+
+ RBuf leftJoins;
+ leftJoins.CleanupClosePushL();
+ leftJoins.CreateL( KEmpty );
+ if( aQuery->GetAttributes().Count() )
+ {
+ for( TInt j=1; j <= aQuery->GetAttributes().Count(); j++ )
+ {
+ // LEFT JOIN CA_ATTRIBUTE as at1 ON ENTRY_ID = at1.AT_ENTRY_ID
+ leftJoins.ReAllocL( leftJoins.Length() +
+ KLeftJoinCaAttrubute1().Length() + KMaxIntNumLength +
+ KLeftJoinCaAttrubute2().Length() + KMaxIntNumLength +
+ KLeftJoinCaAttrubute3().Length()
+ );
+
+ leftJoins.Append( KLeftJoinCaAttrubute1 );
+ leftJoins.AppendNum( j );
+ leftJoins.Append( KLeftJoinCaAttrubute2 );
+ leftJoins.AppendNum( j );
+ leftJoins.Append( KLeftJoinCaAttrubute3 );
+ }
+ }
+
+
+ whereStatement.ReAllocL( whereStatement.Length() +
+ KGroupBy().Length() + KColumnEntryId().Length() );
+ whereStatement.Append( KGroupBy );
+ whereStatement.Append( KColumnEntryId );
TInt groupId = aQuery->GetParentId();
RBuf query;
query.CleanupClosePushL();
if( groupId > 0 )
{
- query.CreateL( KSQLGetListByParentId().Length()
- + whereStatement.Length() - 2 );
- query.AppendFormat( KSQLGetListByParentId, &whereStatement );
+ RBuf getListByParentId2withWhere;
+ getListByParentId2withWhere.CleanupClosePushL();
+ getListByParentId2withWhere.CreateL( KSQLGetListByParentId2().Length() + whereStatement.Length() );
+ getListByParentId2withWhere.AppendFormat( KSQLGetListByParentId2, &whereStatement );
+
+ query.ReAllocL( KSQLGetListByParentId1().Length() + leftJoins.Length() +
+ getListByParentId2withWhere.Length() );
+ query.Append( KSQLGetListByParentId1 );
+ query.Append( leftJoins );
+ query.Append( getListByParentId2withWhere );
+ CleanupStack::PopAndDestroy( &getListByParentId2withWhere );
}
else
{
- query.CreateL( KSQLGetList().Length() );
- query.Append( KSQLGetList );
+ query.CreateL( KSQLGetList1().Length() );
+ query.Append( KSQLGetList1 );
+ query.ReAllocL( query.Length() + leftJoins.Length() + KSQLGetList2().Length() );
+ query.Append( leftJoins );
+ query.Append( KSQLGetList2 );
if( whereStatement.Length() >= KAnd().Length() )
{
TPtrC ptrWhereStatement( whereStatement.Right(
whereStatement.Length() - KAnd().Length() ) );
- query.ReAllocL( KSQLGetList().Length() + KWhere().Length()
+ query.ReAllocL( query.Length() + KWhere().Length()
+ ptrWhereStatement.Length() );
+
query.Append( KWhere );
query.Append( ptrWhereStatement );
}
@@ -707,6 +796,7 @@
aSqlQuery->SetQueryL( query );
CleanupStack::PopAndDestroy( &query );
+ CleanupStack::PopAndDestroy( &leftJoins );
CleanupStack::PopAndDestroy( &whereStatement );
}