| 583 | |
| 584 | |
| 585 | int INTL_compare(thread_db* tdbb, const dsc* pText1, const dsc* pText2, ErrorFunction err) |
| 586 | { |
| 587 | /************************************** |
| 588 | * |
| 589 | * I N T L _ c o m p a r e |
| 590 | * |
| 591 | ************************************** |
| 592 | * |
| 593 | * Functional description |
| 594 | * Compare two pieces of international text. |
| 595 | * |
| 596 | **************************************/ |
| 597 | SET_TDBB(tdbb); |
| 598 | |
| 599 | fb_assert(pText1 != NULL); |
| 600 | fb_assert(pText2 != NULL); |
| 601 | fb_assert(IS_TEXT(pText1) && IS_TEXT(pText2)); |
| 602 | fb_assert(INTL_data_or_binary(pText1) || INTL_data_or_binary(pText2)); |
| 603 | fb_assert(err); |
| 604 | |
| 605 | // normal compare routine from CVT_compare |
| 606 | // trailing spaces in strings are ignored for comparision |
| 607 | |
| 608 | UCHAR* p1; |
| 609 | USHORT t1; |
| 610 | ULONG length1 = CVT_get_string_ptr(pText1, &t1, &p1, NULL, 0, tdbb->getAttachment()->att_dec_status, err); |
| 611 | |
| 612 | UCHAR* p2; |
| 613 | USHORT t2; |
| 614 | ULONG length2 = CVT_get_string_ptr(pText2, &t2, &p2, NULL, 0, tdbb->getAttachment()->att_dec_status, err); |
| 615 | |
| 616 | // YYY - by SQL II compare_type must be explicit in the |
| 617 | // SQL statement if there is any doubt |
| 618 | |
| 619 | USHORT compare_type = MAX(t1, t2); // YYY |
| 620 | HalfStaticArray<UCHAR, BUFFER_XLARGE> buffer; |
| 621 | |
| 622 | if (t1 != t2) |
| 623 | { |
| 624 | CHARSET_ID cs1 = INTL_charset(tdbb, t1); |
| 625 | CHARSET_ID cs2 = INTL_charset(tdbb, t2); |
| 626 | if (cs1 != cs2) |
| 627 | { |
| 628 | if (compare_type != t2) |
| 629 | { |
| 630 | // convert pText2 to pText1's type, if possible |
| 631 | /* YYY - should failure to convert really return |
| 632 | an error here? |
| 633 | Support joining a 437 & Latin1 Column, and we |
| 634 | pick the compare_type as 437, still only want the |
| 635 | equal values.... |
| 636 | But then, what about < operations, which make no |
| 637 | sense if the string cannot be expressed... |
| 638 | */ |
| 639 | |
| 640 | UCHAR* p = buffer.getBuffer(INTL_convert_bytes(tdbb, cs1, NULL, 0, |
| 641 | cs2, p2, length2, err)); |
| 642 | length2 = INTL_convert_bytes(tdbb, cs1, p, (ULONG) buffer.getCount(), |
no test coverage detected