if (!query.exec()) {
logger.log(logger.EXTREME, "NoteResources SQL select has failed.");
logger.log(logger.MEDIUM, query.lastError());
return null;
}
Resource r = null;
if (query.next()) {
r = new Resource();
r.setGuid(query.valueString(0)); // Resource Guid
r.setNoteGuid(query.valueString(1)); // note Guid
r.setMime(query.valueString(2)); // Mime Type
r.setWidth(new Short(query.valueString(3))); // Width
r.setHeight(new Short(query.valueString(4))); // Height
r.setDuration(new Short(query.valueString(5))); // Duration
r.setActive(new Boolean(query.valueString(6))); // active
r.setUpdateSequenceNum(new Integer(query.valueString(7))); // update sequence number
Data d = new Data();
byte[] h = query.valueString(8).getBytes(); // data hash
QByteArray hData = new QByteArray(h);
QByteArray bData = new QByteArray(QByteArray.fromHex(hData));
d.setBodyHash(bData.toByteArray());
d.setSize(new Integer(query.valueString(9)));
r.setData(d);
Data rec = new Data();
if (query.valueObject(10) != null)
rec.setBodyHash(query.valueString(10).getBytes()); // Recognition Hash
if (query.valueObject(11) != null)
rec.setSize(new Integer(query.valueString(11)));
else
rec.setSize(0);
r.setRecognition(rec);
ResourceAttributes a = new ResourceAttributes();
if (!query.valueString(12).equals("")) // Latitude
a.setLatitude(new Float(query.valueString(12)));
if (!query.valueString(13).equals("")) // Longitude
a.setLongitude(new Float(query.valueString(13)));
if (!query.valueString(14).equals("")) // Altitude
a.setAltitude(new Float(query.valueString(14)));
a.setCameraMake(stringValue(query.valueString(15))); // Camera Make
a.setCameraModel(stringValue(query.valueString(16)));
a.setClientWillIndex(booleanValue(query.valueString(17).toString(),false)); // Camera Model
a.setRecoType(stringValue(query.valueString(18))); // Recognition Type
a.setFileName(stringValue(query.valueString(19))); // File Name
a.setAttachment(booleanValue(query.valueString(20).toString(),false));
a.setSourceURL(query.valueString(21));
r.setAttributes(a);
if (withBinary) {
query.prepare("Select dataBinary from NoteResources where guid=:guid");
query.bindValue(":guid", r.getGuid());
query.exec();
if (query.next()) {
byte[] b = query.getBlob(0);
r.getData().setBody(b);
}
}
}
return r;
}