Execute a list of validation expressions.
| 11098 | |
| 11099 | // Execute a list of validation expressions. |
| 11100 | static void validateExpressions(thread_db* tdbb, const Array<ValidateInfo>& validations) |
| 11101 | { |
| 11102 | SET_TDBB(tdbb); |
| 11103 | |
| 11104 | Array<ValidateInfo>::const_iterator end = validations.end(); |
| 11105 | |
| 11106 | for (Array<ValidateInfo>::const_iterator i = validations.begin(); i != end; ++i) |
| 11107 | { |
| 11108 | Request* request = tdbb->getRequest(); |
| 11109 | |
| 11110 | if (!i->boolean->execute(tdbb, request) && !(request->req_flags & req_null)) |
| 11111 | { |
| 11112 | // Validation error -- report result |
| 11113 | const char* value; |
| 11114 | VaryStr<TEMP_STR_LENGTH> temp; |
| 11115 | |
| 11116 | const dsc* desc = EVL_expr(tdbb, request, i->value); |
| 11117 | const USHORT length = (desc && !(request->req_flags & req_null)) ? |
| 11118 | MOV_make_string(tdbb, desc, ttype_dynamic, &value, &temp, sizeof(temp) - 1) : 0; |
| 11119 | |
| 11120 | if (!desc || (request->req_flags & req_null)) |
| 11121 | value = NULL_STRING_MARK; |
| 11122 | else if (!length) |
| 11123 | value = ""; |
| 11124 | else |
| 11125 | const_cast<char*>(value)[length] = 0; // safe cast - data is actually on the stack |
| 11126 | |
| 11127 | string name; |
| 11128 | const FieldNode* fieldNode = nodeAs<FieldNode>(i->value); |
| 11129 | |
| 11130 | if (fieldNode) |
| 11131 | { |
| 11132 | const jrd_rel* relation = request->req_rpb[fieldNode->fieldStream].rpb_relation; |
| 11133 | const vec<jrd_fld*>* vector = relation->rel_fields; |
| 11134 | const jrd_fld* field; |
| 11135 | |
| 11136 | if (vector && fieldNode->fieldId < vector->count() && |
| 11137 | (field = (*vector)[fieldNode->fieldId])) |
| 11138 | { |
| 11139 | if (!relation->rel_name.isEmpty()) |
| 11140 | name.printf("\"%s\".\"%s\"", relation->rel_name.c_str(), field->fld_name.c_str()); |
| 11141 | else |
| 11142 | name.printf("\"%s\"", field->fld_name.c_str()); |
| 11143 | } |
| 11144 | } |
| 11145 | |
| 11146 | if (name.isEmpty()) |
| 11147 | name = UNKNOWN_STRING_MARK; |
| 11148 | |
| 11149 | ERR_post(Arg::Gds(isc_not_valid) << Arg::Str(name) << Arg::Str(value)); |
| 11150 | } |
| 11151 | } |
| 11152 | } |
| 11153 | |
| 11154 | |
| 11155 | } // namespace Jrd |