- // srw'fy number of returned records
- sru_res->num_records
- = pr->records->u.databaseOrSurDiagnostics->num_records;
-
- sru_res->records
- = (Z_SRW_record *)
- odr_malloc(odr_en,
- sru_res->num_records *sizeof(Z_SRW_record));
-
- for (int i = 0; i < sru_res->num_records; i++)
- {
- Z_NamePlusRecord *npr
- = pr->records->u.databaseOrSurDiagnostics->records[i];
-
- sru_res->records[i].recordPosition
- = odr_intdup(odr_en, i + *(apdu->u.presentRequest->resultSetStartPoint));
-
- sru_res->records[i].recordPacking = record_packing;
-
- if (npr->which != Z_NamePlusRecord_databaseRecord)
- {
- sru_res->records[i].recordSchema = "diagnostic";
- sru_res->records[i].recordData_buf = "67";
- sru_res->records[i].recordData_len = 2;
- }
- else
- {
- Z_External *r = npr->u.databaseRecord;
- oident *ent = oid_getentbyoid(r->direct_reference);
- if (r->which == Z_External_octet
- && ent->value == VAL_TEXT_XML)
- {
- sru_res->records[i].recordSchema = "dc";
- sru_res->records[i].recordData_buf
- = odr_strdupn(odr_en,
- (const char *)r->u.octet_aligned->buf,
- r->u.octet_aligned->len);
- sru_res->records[i].recordData_len
- = r->u.octet_aligned->len;
- }
- else
- {
- sru_res->records[i].recordSchema = "diagnostic";
- sru_res->records[i].recordData_buf = "67";
- sru_res->records[i].recordData_len = 2;
- }
- }
-
- }
-
-
+ // got XML record back
+ Z_External *r = npr->u.databaseRecord;
+ sru_res->records[i].recordPosition =
+ odr_intdup(odr_en, position);
+ sru_res->records[i].recordSchema = sr_req->recordSchema;
+ sru_res->records[i].recordData_buf
+ = odr_strdupn(odr_en,
+ (const char *)r->u.octet_aligned->buf,
+ r->u.octet_aligned->len);
+ sru_res->records[i].recordData_len
+ = r->u.octet_aligned->len;
+ }
+ else
+ {
+ // not XML or no database record at all
+ yaz_mk_sru_surrogate(
+ odr_en, sru_res->records + i, position,
+ YAZ_SRW_RECORD_NOT_AVAILABLE_IN_THIS_SCHEMA, 0);