Demo: Typed Quantites with Units
Date: 5 Nov 2004 15:05:44 -0800
Message-ID: <4b45d3ad.0411051505.8e49c30_at_posting.google.com>
The XDb2 script listed below creates a 2kg dog named fido and a 2.2kg cat named miffy. Each mass (2kg and 2.2kg) has a quantity (2 and 2.2) and units (kg). In addition, the quantities (2 and 2.2) are typed as integer or float in the db. See www.xdb2.com/Example/Ex110.asp for details.
// Create necessary classes
CREATE2 *mass.cls = thing; CREATE2 *qty.cls = thing; CREATE2 *unit.cls = thing; CREATE2 *type.cls = thing;
// Create qty 2 and type it as an integer
CREATE2 *;
CREATE2 it.name = +'2'; CREATE2 it.cls = qty; CREATE2 it.type = +integer;
// Create qty 2.2 and type it as a float
CREATE2 *;
CREATE2 it.name = +'2.2'; CREATE2 it.cls = qty; CREATE2 it.type = +float;
// Create mass 2kg
CREATE2 *;
CREATE2 it.cls = mass; CREATE2 it.qty = (%.cls=qty & %.name='2'); CREATE2 it.unit = +kg;
// Create mass 2.2kg
CREATE2 *;
CREATE2 it.cls = mass; CREATE2 it.qty = (%.cls=qty & %.name='2.2'); CREATE2 it.unit = +kg;
// Create a dog named fido and set his mass to 2kg
CREATE2 *dog.cls = thing;
CREATE2 *fido.cls = dog;
CREATE2 fido.mass = (%.cls=mass & %.qty=2 & %.unit=kg);
// Create a cat named miffy and set her mass to 2kg
CREATE2 *cat.cls = thing;
CREATE2 *miffy.cls = cat;
CREATE2 miffy.mass = (%.cls=mass & %.qty=2.2 & %.unit=kg);
// Query to find things whose mass is in units of kg
// Finds fido and miffy
SELECT2 %.mass=(%.cls=mass & %.unit=kg);
// Query to find mass instances whose qty is typed as float
// Finds 2.2 kg
SELECT2 %.cls=mass & %.qty=(%.type=float);
Received on Sat Nov 06 2004 - 00:05:44 CET