MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / par_table_constraint

Function par_table_constraint

src/gpre/sql.cpp:6217–6351  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6215//
6216
6217static 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));

Callers 2

act_alter_tableFunction · 0.85
act_create_tableFunction · 0.85

Calls 14

MSC_allocFunction · 0.85
PAR_get_tokenFunction · 0.85
SQL_resolve_identifierFunction · 0.85
MSC_matchFunction · 0.85
CPR_s_errorFunction · 0.85
EXP_left_parenFunction · 0.85
MSC_pushFunction · 0.85
CPR_tokenFunction · 0.85
EXP_match_parenFunction · 0.85
par_fkey_extensionFunction · 0.85
CPR_start_textFunction · 0.85
SQE_booleanFunction · 0.85

Tested by

no test coverage detected