| 5421 | |
| 5422 | |
| 5423 | dsc* evlMakeDbkey(Jrd::thread_db* tdbb, const SysFunction* function, const NestValueArray& args, Jrd::impure_value* impure) |
| 5424 | { |
| 5425 | // MAKE_DBKEY ( REL_NAME | REL_ID, RECNUM [, DPNUM [, PPNUM] ] ) |
| 5426 | |
| 5427 | Database* const dbb = tdbb->getDatabase(); |
| 5428 | Request* const request = tdbb->getRequest(); |
| 5429 | |
| 5430 | fb_assert(args.getCount() >= 2 && args.getCount() <= 4); |
| 5431 | |
| 5432 | dsc* argDsc = EVL_expr(tdbb, request, args[0]); |
| 5433 | if (request->req_flags & req_null) // return NULL if relation is NULL |
| 5434 | return NULL; |
| 5435 | |
| 5436 | USHORT relId; |
| 5437 | |
| 5438 | if (argDsc->isText()) |
| 5439 | { |
| 5440 | MetaName relName; |
| 5441 | CVT2_make_metaname(argDsc, relName, tdbb->getAttachment()->att_dec_status); |
| 5442 | |
| 5443 | const jrd_rel* const relation = MET_lookup_relation(tdbb, relName); |
| 5444 | if (!relation) |
| 5445 | (Arg::Gds(isc_relnotdef) << Arg::Str(relName)).raise(); |
| 5446 | |
| 5447 | relId = relation->rel_id; |
| 5448 | } |
| 5449 | else |
| 5450 | { |
| 5451 | const SLONG value = MOV_get_long(tdbb, argDsc, 0); |
| 5452 | if (value < 0 || value > MAX_USHORT) // return NULL if the provided ID is too long |
| 5453 | return NULL; |
| 5454 | |
| 5455 | relId = (USHORT) value; |
| 5456 | } |
| 5457 | |
| 5458 | argDsc = EVL_expr(tdbb, request, args[1]); |
| 5459 | if (request->req_flags & req_null) |
| 5460 | return NULL; |
| 5461 | |
| 5462 | SINT64 recNo = MOV_get_int64(tdbb, argDsc, 0); |
| 5463 | |
| 5464 | SINT64 dpNum = 0, ppNum = 0; |
| 5465 | |
| 5466 | if (args.getCount() > 2) |
| 5467 | { |
| 5468 | argDsc = EVL_expr(tdbb, request, args[2]); |
| 5469 | if (request->req_flags & req_null) |
| 5470 | return NULL; |
| 5471 | |
| 5472 | dpNum = MOV_get_int64(tdbb, argDsc, 0); |
| 5473 | if (dpNum > MAX_ULONG) |
| 5474 | return NULL; |
| 5475 | } |
| 5476 | |
| 5477 | if (args.getCount() > 3) |
| 5478 | { |
| 5479 | argDsc = EVL_expr(tdbb, request, args[3]); |
| 5480 | if (request->req_flags & req_null) |
nothing calls this directly
no test coverage detected