| 6215 | // |
| 6216 | |
| 6217 | static cnstrt* par_table_constraint( gpre_req* request) |
| 6218 | { |
| 6219 | cnstrt* constraint = (cnstrt*) MSC_alloc(CNSTRT_LEN); |
| 6220 | |
| 6221 | if (gpreGlob.token_global.tok_keyword == KW_CONSTRAINT) |
| 6222 | { |
| 6223 | PAR_get_token(); |
| 6224 | constraint->cnstrt_name = (STR) MSC_alloc(NAME_SIZE + 1); |
| 6225 | SQL_resolve_identifier("<constraint name>", |
| 6226 | constraint->cnstrt_name->str_string, NAME_SIZE + 1); |
| 6227 | if (gpreGlob.token_global.tok_length >= NAME_SIZE) |
| 6228 | PAR_error("Constraint name too long"); |
| 6229 | |
| 6230 | PAR_get_token(); |
| 6231 | } |
| 6232 | |
| 6233 | gpre_lls** fields; |
| 6234 | USHORT num_for_key_flds = 0, num_prim_key_flds = 0; |
| 6235 | |
| 6236 | const kwwords_t keyword = gpreGlob.token_global.tok_keyword; |
| 6237 | switch (keyword) |
| 6238 | { |
| 6239 | case KW_PRIMARY: |
| 6240 | case KW_UNIQUE: |
| 6241 | case KW_FOREIGN: |
| 6242 | PAR_get_token(); |
| 6243 | switch (keyword) |
| 6244 | { |
| 6245 | case KW_PRIMARY: |
| 6246 | if (!MSC_match(KW_KEY)) |
| 6247 | CPR_s_error("KEY"); |
| 6248 | constraint->cnstrt_type = CNSTRT_PRIMARY_KEY; |
| 6249 | break; |
| 6250 | case KW_FOREIGN: |
| 6251 | if (!MSC_match(KW_KEY)) |
| 6252 | CPR_s_error("KEY"); |
| 6253 | constraint->cnstrt_type = CNSTRT_FOREIGN_KEY; |
| 6254 | break; |
| 6255 | default: |
| 6256 | constraint->cnstrt_type = CNSTRT_UNIQUE; |
| 6257 | } |
| 6258 | |
| 6259 | EXP_left_paren(0); |
| 6260 | |
| 6261 | // Get list of fields for PRIMARY KEY or FOREIGN KEY or UNIQUE constraint |
| 6262 | |
| 6263 | fields = &constraint->cnstrt_fields; |
| 6264 | do { |
| 6265 | STR field_name = (STR) MSC_alloc(NAME_SIZE + 1); |
| 6266 | SQL_resolve_identifier("<column name>", field_name->str_string, NAME_SIZE + 1); |
| 6267 | if (gpreGlob.token_global.tok_length >= NAME_SIZE) |
| 6268 | PAR_error("Field name too long"); |
| 6269 | |
| 6270 | MSC_push((gpre_nod*) field_name, fields); |
| 6271 | fields = &(*fields)->lls_next; |
| 6272 | ++num_for_key_flds; |
| 6273 | CPR_token(); |
| 6274 | } while (MSC_match(KW_COMMA)); |
no test coverage detected