____________________________________________________________ Parse the SUBSTRING built-in function
| 3116 | // Parse the SUBSTRING built-in function |
| 3117 | // |
| 3118 | static gpre_nod* par_substring(gpre_req* request) |
| 3119 | { |
| 3120 | gpre_nod* node = MSC_node(nod_substring, 3); |
| 3121 | EXP_left_paren(0); |
| 3122 | node->nod_arg[0] = SQE_value(request, false, NULL, NULL); |
| 3123 | if (! MSC_match(KW_FROM)) |
| 3124 | CPR_s_error("FROM"); |
| 3125 | node->nod_arg[1] = EXP_literal(); |
| 3126 | if (! node->nod_arg[1]) |
| 3127 | CPR_s_error("numeric literal"); |
| 3128 | |
| 3129 | const ref* reference = (ref*) node->nod_arg[1]->nod_arg[0]; |
| 3130 | const TEXT* string = reference->ref_value; |
| 3131 | |
| 3132 | if (*string == '"' || *string == '\'') |
| 3133 | CPR_s_error("numeric literal"); |
| 3134 | |
| 3135 | if (MSC_match(KW_FOR)) |
| 3136 | { |
| 3137 | node->nod_arg[2] = EXP_literal(); |
| 3138 | if (! node->nod_arg[2]) |
| 3139 | CPR_s_error("numeric literal"); |
| 3140 | reference = (ref*) node->nod_arg[2]->nod_arg[0]; |
| 3141 | string = reference->ref_value; |
| 3142 | if ((*string == '"') || (*string == '\'')) |
| 3143 | CPR_s_error("numeric literal"); |
| 3144 | } |
| 3145 | else |
| 3146 | { |
| 3147 | // No FOR clause given, fake up a numeric literal of 32767 (the max length |
| 3148 | // of a VarChar) to force copying to end of string. |
| 3149 | ref* reference1 = (ref*) MSC_alloc(REF_LEN); |
| 3150 | node->nod_arg[2] = MSC_unary(nod_literal, (gpre_nod*) reference1); |
| 3151 | string = (TEXT*) MSC_alloc(6); |
| 3152 | MSC_copy("32767", 5, (char*) string); |
| 3153 | reference1->ref_value = string; |
| 3154 | } |
| 3155 | USHORT local_count = 1; |
| 3156 | par_terminating_parens(&local_count, &local_count); |
| 3157 | return node; |
| 3158 | } |
| 3159 | |
| 3160 | //____________________________________________________________ |
| 3161 | // |
no test coverage detected