File: DBShowImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Contents: Procs to print out entities and tuples
Last edited by:
Rick Cattell on November 4, 1983 11:27 am
Willie-Sue, February 15, 1985 6:11:12 pm PST
Donahue, September 5, 1985 3:54:54 pm PDT
Widom, September 5, 1985 8:55:34 pm PDT
DIRECTORY
IO,
DB, 
DBCommon,
DBModel,
DBModelPrivate,
DBModelSchema,
DBShow,
DBDefs,
Rope,
AMTypes;
DBShowImpl: CEDAR PROGRAM
IMPORTS
IO, DB, DBModelSchema, DBModel, DBModelPrivate, AMTypes
EXPORTS DBShow =
BEGIN OPEN DB, DBCommon, DBDefs, DBModelPrivate, DBModel, IO;
fh: IO.STREAM;
es: EntitySet ← NEW[DBDefs.EntitySetObject];
rs: RelshipSet ← NEW[DBDefs.RelshipSetObject];
word: PROC [u: UNSPECIFIED] RETURNS [IO.Value] =
temporary kluge for output of UNSPECIFIED to IO
INLINE {RETURN[[integer[LOOPHOLE[u, INTEGER]]]]};
Show: PUBLIC PROC [huh: REF ANY] RETURNS [ROPE] =
displays an entity, relship, domain, or relation
BEGIN ENABLE DB.InternalError => GOTO GiveUp;
d: Domain; r: Relation; flag: BOOL; t: TupleHandle;
t← NARROW[huh ! AMTypes.Error => IF reason=typeFault THEN {t← NIL; CONTINUE}];
IF t=NIL THEN RETURN["* not a relship or entity *"];
flag← FALSE;
d← GetCachedEntityInfo[SegmentOf[t], t !
DB.Error => IF code=IllegalEntity THEN {flag← TRUE; CONTINUE}].domain;
IF flag THEN
BEGIN
flag← FALSE; r← QRelationOf[t
! DB.Error => IF code=NullifiedArgument THEN {flag← TRUE; CONTINUE}];
IF flag THEN RETURN["* deleted *"];
RETURN[ShowRelship[t]];
END;
SELECT d FROM
DomainDomain => RETURN[ShowDomain[t]];
RelationDomain => RETURN[ShowRelation[t]];
AttributeDomain => RETURN[ShowAttribute[t]]
ENDCASE => RETURN[ShowEntity[t]];
EXITS
GiveUp => RETURN["**Internal error, cannot display**"]
END;
ShowEntity: PUBLIC PROC [e: Entity] RETURNS [ROPE] =
displays the domain and name of an entity
BEGIN
fh← IO.ROS[];
WriteEntity[e];
RETURN[FinishOutput[]]
END;
ShowRelship: PUBLIC PROC [r: Relship] RETURNS [ROPE] =
displays a relship and its fields
BEGIN
fh← IO.ROS[];
WriteRelship[r];
RETURN[FinishOutput[]]
END;
ShowDomain: PUBLIC PROC [d: TupleHandle] RETURNS [ROPE] =
displays all elements of a domain
BEGIN
e: Entity;
count: INT← 0;
fh← IO.ROS[];
WriteSystemEntity[d]; fh.Put[rope[" ... domain elements are:\n"]];
es← QDomainSubset[d: DBModelSchema.TupleToDomain[d], es: es];
UNTIL NullEntity[e← QNextEntity[es]] DO
WriteEntity[e]; fh.PutF["\n"];
IF (count𡤌ount+1)>5 THEN {fh.PutF["...more\n"]; EXIT};
ENDLOOP;
QReleaseEntitySet[es];
fh.PutF[".................."];
RETURN[FinishOutput[]]
END;
ShowRelation: PUBLIC PROC [r: TupleHandle] RETURNS [ROPE] =
displays all elements of a relation
BEGIN
t: Relship;
count: INT← 0;
fh← IO.ROS[];
WriteSystemEntity[r]; fh.Put[rope[" ... relation elements are:\n"]];
rs← QRelationSubset[r: DBModelSchema.TupleToRelation[r], rs: rs];
UNTIL NullRelship[t← QNextRelship[rs]] DO
WriteRelship[t]; fh.PutF["\n"];
IF (count𡤌ount+1)>5 THEN {fh.PutF["...more\n"]; EXIT};
ENDLOOP;
QReleaseRelshipSet[rs];
fh.PutF[".................."];
RETURN[FinishOutput[]]
END;
ShowAttribute: PROC [a: Entity] RETURNS [ROPE] =
BEGIN
fh← IO.ROS[];
WriteSystemEntity[a];
RETURN[FinishOutput[]]
END;
ShowAll: PUBLIC PROC [huh: REF ANY] RETURNS [ROPE] =
Displays an entity and its referencing relships
BEGIN
count: INT← 0;
e: Entity;
t: Relship;
r: Relation;
al: LIST OF Attribute;
e← NARROW[huh ! AMTypes.Error =>
TRUSTED {IF reason=typeFault THEN {e← NIL; CONTINUE}}];
IF e=NIL THEN RETURN["* not an entity *"];
al← QGetAllRefAttributes[e];
fh← IO.ROS[];
WriteEntity[e];
fh.PutF[" ... tuples referencing:\n"];
FOR alT: LIST OF Attribute← al, alT.rest UNTIL alT=NIL DO
r← alT.first.relation;
rs← QRelationSubset[r, LIST[[alT.first, E2V[e]]], First, rs];
UNTIL NullRelship[t← QNextRelship[rs]] DO
IF (count𡤌ount+1)>5 THEN {fh.PutF["...more\n"]; EXIT};
WriteRelship[t]; fh.Put[char[CR]] ENDLOOP;
QReleaseRelshipSet[rs];
ENDLOOP;
fh.PutF["....................."];
RETURN[FinishOutput[]]
END;
FinishOutput: PROC RETURNS [ROPE] =
{RETURN[IO.RopeFromROS[fh]]};
The following procedures were stolen from DBDump:
WriteEntity: PROC[e: Entity] =
Prints an entity in ascii dump form: /domain\name\
BEGIN
name: ROPE; d: Domain;
[name, d] ← GetCachedEntityInfo[SegmentOf[e], e];
fh.Put[char['/], rope[d.name], char['\\]];
fh.Put[rope[name], char['\\]];
END;
WriteRelship: PROC[t: Relship] =
Prints a relship in ascii dump form: \relation\a1:v1\...\aN:vN\
BEGIN
ts: Relation ← QRelationOf[t];
fh.Put[char['\\], rope[ts.name]];
fh.Put[char['\\]];
FOR al: LIST OF Attribute ← ts.attributes, al.rest UNTIL al=NIL DO
field: Attribute ← al.first;
fh.Put[rope[field.name], char[':]];
fh.Put[rope[QGetFS[t, field]], char['\\] ];
ENDLOOP;
END;
WriteSystemEntity: PROC [e: Entity] =
Will print a domain, relation, or attribute and any
associated properties that are needed to recreate it.
BEGIN
name: ROPE; type: Domain;
[name, type] ← GetCachedEntityInfo[SegmentOf[e], e];
SELECT type FROM
DomainDomain =>
fh.Put[rope["/Domain\\"], rope[name], char['\\]];
RelationDomain => fh.Put[
rope["/Relation\\"], rope[name], char['\\] ];
AttributeDomain => {
fh.Put[rope["/Attribute\\"], rope[QEntityInfo[V2E[QGetP[e, aRelationIs]]].name], char['\\]];
fh.Put[rope[name], char['\\]];
fh.Put[rope[QEntityInfo[V2E[QGetP[e, aTypeIs]]].name], char['\\]];
fh.Put[word[V2U[QGetP[e, aUniquenessIs]]], char['\\]];
fh.Put[int[V2I[QGetP[e, aLengthIs]]], char['\\]] };
ENDCASE;
fh.Put[char[CR]];
END;
END.