Go to the source code of this file.
Functions | |
FENNEL_BEGIN_NAMESPACE int | SqlStrCat (char *dest, int destStorageBytes, int destLenBytes, char const *const str, int strLenBytes) |
Strcat. | |
int | SqlStrCat (char *dest, int destStorageBytes, char const *const str1, int str1LenBytes, char const *const str2, int str2LenBytes) |
StrCat. | |
int | SqlStrCmp_Bin (char const *const str1, int str1LenBytes, char const *const str2, int str2LenBytes) |
StrCmp. | |
int | SqlStrCpy_Var (char *dest, int destStorageBytes, char const *const str, int strLenBytes) |
StrCpy. | |
int | SqlStrLenBit (int strLenBytes) |
StrLen in bits. | |
int | SqlStrLenOct (int strLenBytes) |
StrLen in octets. |
int SqlStrCat | ( | char * | dest, | |
int | destStorageBytes, | |||
char const *const | str1, | |||
int | str1LenBytes, | |||
char const *const | str2, | |||
int | str2LenBytes | |||
) |
StrCat.
SQL VARCHAR & CHAR. Ascii & UCS2. dest = str1 || str2. Returns new length in bytes.
This is an optimization for creating a concatenated string from two other strings, eliminating a separate string copy. The assumption is that this is the common case with concatenation. Subsequent concatenations may occur with other form.
If either string is variable width, the result is variable width: per SQL99 Part 2 Section 6.27 Syntax Rule 3.a.i. If both strings are fixed width, the result is fixed width, item ii.
Note: CHAR('1 ') || CHAR('2 ') is CHAR('1 2 ') and is not CHAR('12 ').
When used with CHARs, ignore the return value, and set destLenBytes = destStorageBytes
Definition at line 51 of file SqlString.cpp.
00058 { 00059 if (str1LenBytes + str2LenBytes > destStorageBytes) { 00060 // SQL99 Part 2 Section 22.1 22-001 00061 // "String Data Right truncation" 00062 throw "22001"; 00063 } 00064 00065 memcpy(dest, str1, str1LenBytes); 00066 memcpy(dest + str1LenBytes, str2, str2LenBytes); 00067 return str1LenBytes + str2LenBytes; 00068 }
FENNEL_BEGIN_NAMESPACE int SqlStrCat | ( | char * | dest, | |
int | destStorageBytes, | |||
int | destLenBytes, | |||
char const *const | str, | |||
int | strLenBytes | |||
) |
Strcat.
SQL VARCHAR & CHAR. Ascii & UCS2. dest = dest || str. Returns new length in bytes.
If either string is variable width, the result is variable width: per SQL99 Part 2 Section 6.27 Syntax Rule 3.a.i. If both strings are fixed width, the result is fixed width, per item ii.
Note that CHAR('1 ') || CHAR('2 ') = CHAR('1 2 ') and not CHAR('12 ').
When called repeatedly to cat multiple strings together (e.g. A || B || C), the final destLength must be exactly equal to the defined resulting width. (e.g. width of A+B+C) for both VARCHAR & CHAR. Take care that these length semantics are adhered to in the final result, even though intermediate results (say A || B) may not have the correct length.
When used with CHARs, set strLenBytes to strStorageBytes. On intermediate results set destLenBytes = return value of previous call. Final result should/must have return value == destStorage.
Definition at line 33 of file SqlString.cpp.
Referenced by strCatA2(), strCatA3(), SqlStringTest::testSqlStringCat_Fix(), SqlStringTest::testSqlStringCat_Var(), and SqlStringTest::testSqlStringCat_Var2().
00039 { 00040 if (destLenBytes + strLenBytes > destStorageBytes) { 00041 // SQL99 Part 2 Section 22.1 22-001 "String Data Right truncation" 00042 throw "22001"; 00043 } 00044 00045 memcpy(dest + destLenBytes, str, strLenBytes); 00046 return destLenBytes + strLenBytes; 00047 }
int SqlStrCmp_Bin | ( | char const *const | str1, | |
int | str1LenBytes, | |||
char const *const | str2, | |||
int | str2LenBytes | |||
) |
StrCmp.
Binary. See SQL2003 Part 2 Section 4.3.2. As an extension to SQL2003, allow inequalities (>,>=, etc.) Follows byte-wise comparison semantics of memcmp().
Returns -1, 0, 1.
Definition at line 71 of file SqlString.cpp.
Referenced by SqlStrCmp(), strCmpOct(), and SqlStringTest::testSqlStringCmp_Bin_Helper().
00076 { 00077 // First, check for differences in "common" length. If common length 00078 // are contains same values, declare the longer string "larger". 00079 int minLenBytes = 00080 str1LenBytes > str2LenBytes ? str2LenBytes : str1LenBytes; 00081 int memc = memcmp(str1, str2, minLenBytes); 00082 if (memc > 0) { 00083 // Normalize to -1, 0, 1 00084 return 1; 00085 } else if (memc < 0) { 00086 // Normalize to -1, 0, 1 00087 return -1; 00088 } else if (str1LenBytes == str2LenBytes) { 00089 // memc == 0 00090 // Equal length & contain same data -> equal 00091 return 0; 00092 } else if (str1LenBytes > str2LenBytes) { 00093 // Common contains same data, str1 is longer -> str1 > str2 00094 return 1; 00095 } else { 00096 // Common contains same data, str2 is longer -> str2 > str1 00097 return -1; 00098 } 00099 }
int SqlStrCpy_Var | ( | char * | dest, | |
int | destStorageBytes, | |||
char const *const | str, | |||
int | strLenBytes | |||
) |
StrCpy.
String Copy. Variable Width / VARCHAR. Ascii & UCS2. Returns strLenBytes.
This routine may not be compliant with the SQL99 standard.
May be used for Fixed width strings if strLenBytes == destStorageBytes Otherwise use SqlStrCpy_Fix() to get appropriate padding.
Definition at line 102 of file SqlString.cpp.
Referenced by strCpyA(), and SqlStringTest::testSqlStringCpy_Var().
00107 { 00108 if (strLenBytes > destStorageBytes) { 00109 // SQL99 Part 2 Section 22.1 22-001 00110 // "String Data Right truncation" 00111 throw "22001"; 00112 } 00113 memcpy(dest, str, strLenBytes); 00114 return strLenBytes; 00115 }
int SqlStrLenBit | ( | int | strLenBytes | ) |
StrLen in bits.
CHAR/VARCHAR. Ascii & UCS2.
Parameter str is ignored for ascii strings.
Definition at line 118 of file SqlString.cpp.
Referenced by strLenBitA(), and SqlStringTest::testSqlStringLenBit().
int SqlStrLenOct | ( | int | strLenBytes | ) |
StrLen in octets.
CHAR/VARCHAR. Ascii & UCS2.
Parameter str is ignored for ascii strings.
Definition at line 124 of file SqlString.cpp.
Referenced by strLenOctA(), and SqlStringTest::testSqlStringLenOct().