<> <> <> <> <> <> <> <> DIRECTORY IO, DB, DBCommon, DBModel, DBModelPrivate, DBShow, DBDefs, Rope, SafeStorage; DBShowImpl: CEDAR PROGRAM IMPORTS IO, DB, DBModel, SafeStorage EXPORTS DBShow = BEGIN fh: IO.STREAM; ROPE: TYPE = Rope.ROPE; word: PROC [u: UNSPECIFIED] RETURNS [IO.Value] = <> INLINE {RETURN[[integer[LOOPHOLE[u, INTEGER]]]]}; Show: PUBLIC PROC [huh: REF ANY] RETURNS [ROPE] = { <> ENABLE DB.Error => GOTO GiveUp; ssType: SafeStorage.Type = SafeStorage.GetReferentType[huh]; SELECT TRUE FROM ISTYPE[huh, DBDefs.Entity] => { e: DB.Entity = NARROW[huh]; RETURN[ShowEntity[e]]; }; ISTYPE[huh, DB.Relship] => { relship: DB.Relship = NARROW[huh]; del: BOOL _ FALSE; relation: DB.Relation; relation _ DBModel.RelationOf[ relship ! DB.Error => IF code=NullifiedArgument THEN {del _ TRUE; CONTINUE}]; IF del THEN RETURN["* deleted *"]; RETURN[ShowRelship[relship]]; }; ISTYPE[huh, DB.Domain] => { d: DB.Domain = NARROW[huh]; RETURN[ShowDomain[d]] }; ISTYPE[huh, DB.Relation] => { rel: DB.Relation = NARROW[huh]; RETURN[ShowRelation[rel]] }; ENDCASE => RETURN["Not an entity or a relship or a domain or a relation\n"]; EXITS GiveUp => RETURN["\n***DB.Error - can't display"]; }; ShowEntity: PUBLIC PROC [e: DB.Entity] RETURNS [ROPE] = { <> fh_ IO.ROS[]; WriteEntity[e]; RETURN[FinishOutput[]] }; ShowRelship: PUBLIC PROC [r: DB.Relship] RETURNS [ROPE] = { <> fh_ IO.ROS[]; WriteRelship[r]; RETURN[FinishOutput[]] }; ShowDomain: PUBLIC PROC [d: DB.Domain] RETURNS [ROPE] = { <> e: DB.Entity; count: INT _ 0; es: DB.EntitySet _ DBModel.DomainSubset[d: d, lowName: NIL, highName: NIL, start: First]; fh _ IO.ROS[]; fh.Put[IO.rope["/Domain\\"], IO.rope[d.name], IO.char['\\] ]; fh.Put[IO.rope[" ... domain elements are:\n"] ]; UNTIL DBModel.NullEntity[e _ DBModel.NextEntity[es]] DO WriteEntity[e]; fh.PutF["\n"]; IF (count_count+1)>5 THEN {fh.PutF["...more\n"]; EXIT}; ENDLOOP; DBModel.ReleaseEntitySet[es]; fh.PutF[".................."]; RETURN[FinishOutput[]] }; ShowRelation: PUBLIC PROC [rel: DB.Relation ] RETURNS [ROPE] = { <> t: DB.Relship; count: INT _ 0; rs: DB.RelshipSet _ DBModel.RelationSubset[r: rel, index: NIL, constraint: NIL, start: First]; fh _ IO.ROS[]; fh.Put[IO.rope["/Relation\\"], IO.rope[rel.name], IO.char['\\] ]; fh.Put[IO.rope[" ... relation elements are:\n"]]; UNTIL DBModel.NullRelship[t _ DBModel.NextRelship[rs]] DO WriteRelship[t]; fh.PutF["\n"]; IF (count_count+1)>5 THEN {fh.PutF["...more\n"]; EXIT}; ENDLOOP; DB.ReleaseRelshipSet[rs]; fh.PutF[".................."]; RETURN[FinishOutput[]] }; <> <> <> <> <> <> <> <<>> <>> <> <> <> <> <> <> <> <> <> <> <> <5 THEN {fh.PutF["...more\n"]; EXIT};>> <> <> <> <> <> <<};>> <<>> FinishOutput: PROC RETURNS [ROPE] = {RETURN[IO.RopeFromROS[fh]]}; <> WriteEntity: PROC[e: DB.Entity] = { <> name: ROPE; d: DB.Domain; [name, d] _ DB.EntityInfo[e]; fh.PutF["/%g\\/%g\\", IO.rope[d.name], IO.rope[name]]; <> <> }; WriteRelship: PROC[t: DB.Relship] = { <> ts: DB.Relation _ DB.RelationOf[t]; <> <> fh.PutF["\\%g\\", IO.rope[ts.name] ]; FOR i: CARDINAL IN [0..ts.attributes.count) DO field: REF DBDefs.AttributeObject _ ts.attributes[i]; fh.Put[IO.rope[field.name], IO.rope[": "]]; fh.Put[IO.rope[ValueToRopeRep[DBModel.GetF[t, i]] ], IO.char['\\] ]; ENDLOOP; }; ValueToRopeRep: PROC[val: DBDefs.Value] RETURNS[ROPE] = TRUSTED { WITH v: val SELECT FROM boolean => RETURN[IF v.value THEN "TRUE" ELSE "FALSE"]; integer => RETURN[IO.PutFR["%g", IO.int[v.value]] ]; rope => RETURN[v.value]; time => RETURN[IO.PutFR["%g", IO.time[v.value]]]; entity => RETURN[DBModel.EntityInfo[v.value].name]; ENDCASE => RETURN["Unknown value type"]; }; END.