Skip to content

Commit

Permalink
Fixed CORE-1056 - A query could produce different results, depending …
Browse files Browse the repository at this point in the history
…on the presence of an index
  • Loading branch information
asfernandes committed Dec 16, 2006
1 parent 586ba9e commit ca0de4e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
40 changes: 38 additions & 2 deletions src/jrd/unicode_util.cpp
Expand Up @@ -618,19 +618,26 @@ UnicodeUtil::Utf16Collation* UnicodeUtil::Utf16Collation::create(
else
tt->texttype_flags = TEXTTYPE_DIRECT_MATCH;

USet* contractions = uset_open(0, 0);
ucol_getContractions(partialCollator, contractions, &status);

Utf16Collation* obj = new Utf16Collation();
obj->tt = tt;
obj->attributes = attributes;
obj->compareCollator = compareCollator;
obj->partialCollator = partialCollator;
obj->sortCollator = sortCollator;
obj->contractions = contractions;
obj->contractionsCount = uset_getItemCount(contractions);

return obj;
}


UnicodeUtil::Utf16Collation::~Utf16Collation()
{
uset_close(static_cast<USet*>(contractions));

ucol_close((UCollator*)compareCollator);
ucol_close((UCollator*)partialCollator);
ucol_close((UCollator*)sortCollator);
Expand Down Expand Up @@ -676,8 +683,32 @@ USHORT UnicodeUtil::Utf16Collation::stringToKey(USHORT srcLen, const USHORT* src
switch (key_type)
{
case INTL_KEY_PARTIAL:
{
coll = partialCollator;

// Remove last bytes of key if they are start of a contraction
// to correctly find in the index.
for (int i = 0; i < contractionsCount; ++i)
{
UChar str[10];
UErrorCode status = U_ZERO_ERROR;
int len = uset_getItem(static_cast<USet*>(contractions),
i, NULL, NULL, str, sizeof(str), &status);

if (len > srcLen)
len = srcLen;
else
--len;

if (u_strCompare(str, len, reinterpret_cast<const UChar*>(src) + srcLen - len, len, true) == 0)
{
srcLen -= len;
break;
}
}

break;
}

case INTL_KEY_UNIQUE:
coll = compareCollator;
Expand All @@ -692,8 +723,13 @@ USHORT UnicodeUtil::Utf16Collation::stringToKey(USHORT srcLen, const USHORT* src
return INTL_BAD_KEY_LENGTH;
}

return ucol_getSortKey(static_cast<const UCollator*>(coll),
reinterpret_cast<const UChar*>(src), srcLen, dst, dstLen);
if (srcLen != 0)
{
return ucol_getSortKey(static_cast<const UCollator*>(coll),
reinterpret_cast<const UChar*>(src), srcLen, dst, dstLen);
}
else
return 0;
}


Expand Down
2 changes: 2 additions & 0 deletions src/jrd/unicode_util.h
Expand Up @@ -82,6 +82,8 @@ class UnicodeUtil
void* compareCollator;
void* partialCollator;
void* sortCollator;
void* contractions;
int contractionsCount;
};
};

Expand Down

0 comments on commit ca0de4e

Please sign in to comment.