| 5911 | // |
| 5912 | |
| 5913 | static cnstrt* par_field_constraint( gpre_req* request, gpre_fld* for_field) |
| 5914 | { |
| 5915 | cnstrt* new_constraint = (cnstrt*) MSC_alloc(CNSTRT_LEN); |
| 5916 | |
| 5917 | if (gpreGlob.token_global.tok_keyword == KW_CONSTRAINT) |
| 5918 | { |
| 5919 | PAR_get_token(); |
| 5920 | new_constraint->cnstrt_name = (STR) MSC_alloc(NAME_SIZE + 1); |
| 5921 | SQL_resolve_identifier("<constraint name>", |
| 5922 | new_constraint->cnstrt_name->str_string, NAME_SIZE + 1); |
| 5923 | if (gpreGlob.token_global.tok_length >= NAME_SIZE) |
| 5924 | PAR_error("Constraint name too long"); |
| 5925 | |
| 5926 | PAR_get_token(); |
| 5927 | } |
| 5928 | |
| 5929 | STR field_name; |
| 5930 | const kwwords_t keyword = gpreGlob.token_global.tok_keyword; |
| 5931 | switch (keyword) |
| 5932 | { |
| 5933 | case KW_NOT: |
| 5934 | PAR_get_token(); |
| 5935 | if (!MSC_match(KW_NULL)) |
| 5936 | CPR_s_error("NULL"); |
| 5937 | new_constraint->cnstrt_type = CNSTRT_NOT_NULL; |
| 5938 | for_field->fld_flags |= FLD_not_null; |
| 5939 | break; |
| 5940 | |
| 5941 | case KW_PRIMARY: |
| 5942 | case KW_UNIQUE: |
| 5943 | case KW_REFERENCES: |
| 5944 | PAR_get_token(); |
| 5945 | switch (keyword) |
| 5946 | { |
| 5947 | case KW_PRIMARY: |
| 5948 | if (!MSC_match(KW_KEY)) |
| 5949 | CPR_s_error("KEY"); |
| 5950 | new_constraint->cnstrt_type = CNSTRT_PRIMARY_KEY; |
| 5951 | break; |
| 5952 | case KW_REFERENCES: |
| 5953 | new_constraint->cnstrt_type = CNSTRT_FOREIGN_KEY; |
| 5954 | break; |
| 5955 | default: |
| 5956 | new_constraint->cnstrt_type = CNSTRT_UNIQUE; |
| 5957 | } |
| 5958 | |
| 5959 | // Set field for PRIMARY KEY or FOREIGN KEY or UNIQUE constraint |
| 5960 | |
| 5961 | field_name = (STR) MSC_alloc(NAME_SIZE + 1); |
| 5962 | strcpy(field_name->str_string, for_field->fld_symbol->sym_string); |
| 5963 | MSC_push((gpre_nod*) field_name, &new_constraint->cnstrt_fields); |
| 5964 | |
| 5965 | if (keyword == KW_REFERENCES) |
| 5966 | { |
| 5967 | // Relation name for foreign key |
| 5968 | |
| 5969 | new_constraint->cnstrt_referred_rel = (STR) MSC_alloc(NAME_SIZE + 1); |
| 5970 | SQL_resolve_identifier("referred <table name>", |
no test coverage detected