| 1765 | |
| 1766 | |
| 1767 | void makeReplace(DataTypeUtilBase* dataTypeUtil, const SysFunction* function, dsc* result, |
| 1768 | int argsCount, const dsc** args) |
| 1769 | { |
| 1770 | fb_assert(argsCount >= function->minArgCount); |
| 1771 | |
| 1772 | bool isNullable = false; |
| 1773 | const dsc* firstBlob = NULL; |
| 1774 | |
| 1775 | for (int i = 0; i < argsCount; ++i) |
| 1776 | { |
| 1777 | if (args[i]->isNull()) |
| 1778 | { |
| 1779 | result->makeNullString(); |
| 1780 | return; |
| 1781 | } |
| 1782 | |
| 1783 | if (args[i]->isNullable()) |
| 1784 | isNullable = true; |
| 1785 | |
| 1786 | if (!firstBlob && args[i]->isBlob()) |
| 1787 | firstBlob = args[i]; |
| 1788 | } |
| 1789 | |
| 1790 | const dsc* searched = args[0]; |
| 1791 | const dsc* find = args[1]; |
| 1792 | const dsc* replacement = args[2]; |
| 1793 | |
| 1794 | if (firstBlob) |
| 1795 | *result = *firstBlob; |
| 1796 | else |
| 1797 | { |
| 1798 | result->clear(); |
| 1799 | result->dsc_dtype = dtype_varying; |
| 1800 | } |
| 1801 | |
| 1802 | result->setBlobSubType(dataTypeUtil->getResultBlobSubType(searched, find)); |
| 1803 | result->setBlobSubType(dataTypeUtil->getResultBlobSubType(result, replacement)); |
| 1804 | |
| 1805 | result->setTextType(dataTypeUtil->getResultTextType(searched, find)); |
| 1806 | result->setTextType(dataTypeUtil->getResultTextType(result, replacement)); |
| 1807 | |
| 1808 | if (!firstBlob) |
| 1809 | { |
| 1810 | const int searchedLen = dataTypeUtil->convertLength(searched, result); |
| 1811 | const int findLen = dataTypeUtil->convertLength(find, result); |
| 1812 | const int replacementLen = dataTypeUtil->convertLength(replacement, result); |
| 1813 | |
| 1814 | if (findLen == 0) |
| 1815 | result->dsc_length = dataTypeUtil->fixLength(result, searchedLen) + static_cast<USHORT>(sizeof(USHORT)); |
| 1816 | else |
| 1817 | { |
| 1818 | result->dsc_length = dataTypeUtil->fixLength(result, |
| 1819 | MAX(searchedLen, searchedLen + (searchedLen / findLen) * (replacementLen - findLen))) + |
| 1820 | static_cast<USHORT>(sizeof(USHORT)); |
| 1821 | } |
| 1822 | } |
| 1823 | |
| 1824 | result->setNullable(isNullable); |
nothing calls this directly
no test coverage detected