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

Function get_referred_fields

src/gpre/cmd.cpp:1130–1205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1128//
1129
1130static void get_referred_fields(const act* action, cnstrt* constraint)
1131{
1132 TEXT s[512];
1133 const gpre_rel* relation = (gpre_rel*) action->act_object;
1134
1135 for (gpre_req* req = gpreGlob.requests; req; req = req->req_next)
1136 {
1137 const act* request_action;
1138 const gpre_rel* rel;
1139 if (req->req_type == REQ_ddl && (request_action = req->req_actions) &&
1140 (request_action->act_type == ACT_create_table ||
1141 request_action->act_type == ACT_alter_table) &&
1142 (rel = (gpre_rel*) request_action->act_object) &&
1143 strcmp(rel->rel_symbol->sym_string, constraint->cnstrt_referred_rel->str_string) == 0)
1144 {
1145 for (const cnstrt* cns = rel->rel_constraints; cns; cns = cns->cnstrt_next)
1146 {
1147 if (cns->cnstrt_type == CNSTRT_PRIMARY_KEY)
1148 {
1149 constraint->cnstrt_referred_fields = cns->cnstrt_fields;
1150 break;
1151 }
1152 }
1153 if (!constraint->cnstrt_referred_fields && rel->rel_fields)
1154 for (const cnstrt* cns = rel->rel_fields->fld_constraints; cns; cns = cns->cnstrt_next)
1155 {
1156 if (cns->cnstrt_type == CNSTRT_PRIMARY_KEY)
1157 {
1158 constraint->cnstrt_referred_fields = cns->cnstrt_fields;
1159 break;
1160 }
1161 }
1162 if (constraint->cnstrt_referred_fields)
1163 break;
1164 }
1165 }
1166
1167 if (constraint->cnstrt_referred_fields == NULL)
1168 // Nothing is in memory. Try to find in system tables
1169 constraint->cnstrt_referred_fields =
1170 MET_get_primary_key(relation->rel_database, constraint->cnstrt_referred_rel->str_string);
1171
1172 if (constraint->cnstrt_referred_fields == NULL)
1173 {
1174 // Nothing is in system tables.
1175 sprintf(s,
1176 "\"REFERENCES %s\" without \"(column list)\" requires PRIMARY KEY on referenced table",
1177 constraint->cnstrt_referred_rel->str_string);
1178 CPR_error(s);
1179 }
1180 else
1181 {
1182 // count both primary key and foreign key columns
1183 USHORT prim_key_num_flds = 0, for_key_num_flds = 0;
1184 const gpre_lls* field = constraint->cnstrt_referred_fields;
1185 while (field)
1186 {
1187 prim_key_num_flds++;

Callers 1

create_constraintFunction · 0.85

Calls 2

MET_get_primary_keyFunction · 0.85
CPR_errorFunction · 0.85

Tested by

no test coverage detected