Backup defines virtual relvar in advance of dependent real

This forum is to report technical problems with Rel.
Post Reply
HughDarwen
Posts: 121
Joined: Sat May 24, 2008 4:49 pm

Backup defines virtual relvar in advance of dependent real

Post by HughDarwen »

In the backup shown below the virtual relvar teacher is defined in advance of the real relvar staff, so loading it and executing it gives an error. Find "var teacher", then "var staff" to see what I mean.

Hugh

/*** Rel Database Backup ***/

// Created in Rel Version 1.0.4 Beta
// Using DatabaseToScript version 0.3.3

BEGIN TRANSACTION;

ANNOUNCE 'operator IS_DIGITS';
OPERATOR IS_DIGITS(s CHARACTER) RETURNS BOOLEAN Java FOREIGN
String sbuf = s.stringValue();
for (int i=0; i<sbuf.length(); i++)
if (!Character.isDigit(sbuf.charAt(i)))
return ValueBoolean.select(context.getGenerator(), false);
return ValueBoolean.select(context.getGenerator(), true);
END OPERATOR;

ANNOUNCE 'operator LENGTH';
OPERATOR LENGTH(s CHARACTER) RETURNS INTEGER Java FOREIGN
return ValueInteger.select(context.getGenerator(), s.stringValue().length());
END OPERATOR;

ANNOUNCE 'operator SUBSTRING';
OPERATOR SUBSTRING(s CHARACTER, index INTEGER) RETURNS CHARACTER Java FOREIGN
// Substring, 0 based
return ValueCharacter.select(context.getGenerator(), s.stringValue().substring((int)index.longValue()));
END OPERATOR;

ANNOUNCE 'operator SUBSTRING';
OPERATOR SUBSTRING(s CHARACTER, beginindex INTEGER, endindex INTEGER) RETURNS CHARACTER Java FOREIGN
// Substring, 0 based
return ValueCharacter.select(context.getGenerator(), s.stringValue().substring((int)beginindex.longValue(), (int)endindex.longValue()));
END OPERATOR;

ANNOUNCE 'operator COMPARE_TO';
OPERATOR COMPARE_TO(s CHARACTER, anotherString CHARACTER) RETURNS INTEGER Java FOREIGN
// Compares two strings lexicographically.
return ValueInteger.select(context.getGenerator(), s.stringValue().compareTo(anotherString.stringValue()));
END OPERATOR;

ANNOUNCE 'operator COMPARE_TO_IGNORE_CASE';
OPERATOR COMPARE_TO_IGNORE_CASE(s CHARACTER, str CHARACTER) RETURNS INTEGER Java FOREIGN
// Compares two strings lexicographically, ignoring case differences.
return ValueInteger.select(context.getGenerator(), s.stringValue().compareToIgnoreCase(str.stringValue()));
END OPERATOR;

ANNOUNCE 'operator ENDS_WITH';
OPERATOR ENDS_WITH(s CHARACTER, suffx CHARACTER) RETURNS BOOLEAN Java FOREIGN
return ValueBoolean.select(context.getGenerator(), s.stringValue().endsWith(suffx.stringValue()));
END OPERATOR;

ANNOUNCE 'operator EQUALS_IGNORE_CASE';
OPERATOR EQUALS_IGNORE_CASE(s CHARACTER, anotherString CHARACTER) RETURNS BOOLEAN Java FOREIGN
// Compares this String to another String, ignoring case considerations.
return ValueBoolean.select(context.getGenerator(), s.stringValue().equalsIgnoreCase(anotherString.stringValue()));
END OPERATOR;

ANNOUNCE 'operator INDEX_OF';
OPERATOR INDEX_OF(s CHARACTER, str CHARACTER) RETURNS INTEGER Java FOREIGN
// Returns the index within this string of the first occurrence of the specified substring.
return ValueInteger.select(context.getGenerator(), s.stringValue().indexOf(str.stringValue()));
END OPERATOR;

ANNOUNCE 'operator INDEX_OF';
OPERATOR INDEX_OF(s CHARACTER, str CHARACTER, fromIndex INTEGER) RETURNS INTEGER Java FOREIGN
// Returns the index within this string of the first occurrence of the
// specified substring, starting at the specified index.
return ValueInteger.select(context.getGenerator(), s.stringValue().indexOf(str.stringValue(), (int)fromIndex.longValue()));
END OPERATOR;

ANNOUNCE 'operator LAST_INDEX_OF';
OPERATOR LAST_INDEX_OF(s CHARACTER, str CHARACTER) RETURNS INTEGER Java FOREIGN
// Returns the index within this string of the rightmost occurrence of the specified substring.
return ValueInteger.select(context.getGenerator(), s.stringValue().lastIndexOf(str.stringValue()));
END OPERATOR;

ANNOUNCE 'operator LAST_INDEX_OF';
OPERATOR LAST_INDEX_OF(s CHARACTER, str CHARACTER, fromIndex INTEGER) RETURNS INTEGER Java FOREIGN
// Returns the index within this string of the last occurrence of
// the specified substring, searching backward starting at the specified index.
return ValueInteger.select(context.getGenerator(), s.stringValue().lastIndexOf(str.stringValue(), (int)fromIndex.longValue()));
END OPERATOR;

ANNOUNCE 'operator MATCHES';
OPERATOR MATCHES(s CHARACTER, regex CHARACTER) RETURNS BOOLEAN Java FOREIGN
// Tells whether or not this string matches the given regular expression.
return ValueBoolean.select(context.getGenerator(), s.stringValue().matches(regex.stringValue()));
END OPERATOR;

ANNOUNCE 'operator REGION_MATCHES';
OPERATOR REGION_MATCHES(s CHARACTER, ignoreCase BOOLEAN, toffset INTEGER, other CHARACTER, ooffset INTEGER, len INTEGER) RETURNS BOOLEAN Java FOREIGN
// Tests if two string regions are equal.
return ValueBoolean.select(context.getGenerator(), s.stringValue().regionMatches(ignoreCase.booleanValue(),
(int)toffset.longValue(),
other.stringValue(),
(int)ooffset.longValue(),
(int)len.longValue()));
END OPERATOR;

ANNOUNCE 'operator REPLACE_ALL';
OPERATOR REPLACE_ALL(s CHARACTER, regex CHARACTER, replacement CHARACTER) RETURNS CHARACTER Java FOREIGN
// Replaces each substring of this string that matches the given regular expression with the given replacement.
return ValueCharacter.select(context.getGenerator(), s.stringValue().replaceAll(regex.stringValue(), replacement.stringValue()));
END OPERATOR;

ANNOUNCE 'operator REPLACE_FIRST';
OPERATOR REPLACE_FIRST(s CHARACTER, regex CHARACTER, replacement CHARACTER) RETURNS CHARACTER Java FOREIGN
// Replaces the first substring of this string that matches the given regular expression with the given replacement.
return ValueCharacter.select(context.getGenerator(), s.stringValue().replaceFirst(regex.stringValue(), replacement.stringValue()));
END OPERATOR;

ANNOUNCE 'operator STARTS_WITH';
OPERATOR STARTS_WITH(s CHARACTER, prefx CHARACTER) RETURNS BOOLEAN Java FOREIGN
// Tests if this string starts with the specified prefix.
return ValueBoolean.select(context.getGenerator(), s.stringValue().startsWith(prefx.stringValue()));
END OPERATOR;

ANNOUNCE 'operator STARTS_WITH';
OPERATOR STARTS_WITH(s CHARACTER, prefx CHARACTER, toffset INTEGER) RETURNS BOOLEAN Java FOREIGN
// Tests if this string starts with the specified prefix beginning at a specified index.
return ValueBoolean.select(context.getGenerator(), s.stringValue().startsWith(prefx.stringValue(), (int)toffset.longValue()));
END OPERATOR;

ANNOUNCE 'operator TO_LOWER_CASE';
OPERATOR TO_LOWER_CASE(s CHARACTER) RETURNS CHARACTER Java FOREIGN
return ValueCharacter.select(context.getGenerator(), s.stringValue().toLowerCase());
END OPERATOR;

ANNOUNCE 'operator TO_UPPER_CASE';
OPERATOR TO_UPPER_CASE(s CHARACTER) RETURNS CHARACTER Java FOREIGN
// Converts all of the characters in this String to upper case using the rules of the default locale.
return ValueCharacter.select(context.getGenerator(), s.stringValue().toUpperCase());
END OPERATOR;

ANNOUNCE 'operator TRIM';
OPERATOR TRIM(s CHARACTER) RETURNS CHARACTER Java FOREIGN
// Trim leading and trailing blanks.
return ValueCharacter.select(context.getGenerator(), s.stringValue().trim());
END OPERATOR;

ANNOUNCE 'operator E';
OPERATOR E() RETURNS RATIONAL Java FOREIGN
// The RATIONAL value that is closer than any other to e, the base of
// the natural logarithms.
return ValueRational.select(context.getGenerator(), Math.E);
END OPERATOR;

ANNOUNCE 'operator PI';
OPERATOR PI() RETURNS RATIONAL Java FOREIGN
// The RATIONAL value that is closer than any other to pi, the ratio of
// the circumference of a circle to its diameter.
return ValueRational.select(context.getGenerator(), Math.PI);
END OPERATOR;

ANNOUNCE 'operator ABS';
OPERATOR ABS(x RATIONAL) RETURNS RATIONAL Java FOREIGN
// Returns the absolute value of a RATIONAL value.
return ValueRational.select(context.getGenerator(), Math.abs(x.doubleValue()));
END OPERATOR;

ANNOUNCE 'operator ABS';
OPERATOR ABS(x INTEGER) RETURNS INTEGER Java FOREIGN
// Returns the absolute value of a INTEGER value.
return ValueInteger.select(context.getGenerator(), Math.abs(x.longValue()));
END OPERATOR;

ANNOUNCE 'operator ACOS';
OPERATOR ACOS(x RATIONAL) RETURNS RATIONAL Java FOREIGN
// Returns the arc cosine of an angle, in the range of 0.0 through pi.
return ValueRational.select(context.getGenerator(), Math.acos(x.doubleValue()));
END OPERATOR;

ANNOUNCE 'operator ASIN';
OPERATOR ASIN(x RATIONAL) RETURNS RATIONAL Java FOREIGN
// Returns the arc sine of an angle, in the range of -pi/2 through pi/2.
return ValueRational.select(context.getGenerator(), Math.asin(x.doubleValue()));
END OPERATOR;

ANNOUNCE 'operator ATAN';
OPERATOR ATAN(a RATIONAL) RETURNS RATIONAL Java FOREIGN
// Returns the arc tangent of an angle, in the range of -pi/2 through
// pi/2.
return ValueRational.select(context.getGenerator(), Math.atan(a.doubleValue()));
END OPERATOR;

ANNOUNCE 'operator ATAN2';
OPERATOR ATAN2(y RATIONAL, x RATIONAL) RETURNS RATIONAL Java FOREIGN
// Converts rectangular coordinates (x, y) to polar (r, theta).
return ValueRational.select(context.getGenerator(), Math.atan2(y.doubleValue(), x.doubleValue()));
END OPERATOR;

ANNOUNCE 'operator CEIL';
OPERATOR CEIL(a RATIONAL) RETURNS RATIONAL Java FOREIGN
// Returns the smallest (closest to negative infinity) RATIONAL value
// that is not less than the argument and is equal to a mathematical
// integer.
return ValueRational.select(context.getGenerator(), Math.ceil(a.doubleValue()));
END OPERATOR;

ANNOUNCE 'operator COS';
OPERATOR COS(a RATIONAL) RETURNS RATIONAL Java FOREIGN
// Returns the trigonometric cosine of an angle.
return ValueRational.select(context.getGenerator(), Math.cos(a.doubleValue()));
END OPERATOR;

ANNOUNCE 'operator EXP';
OPERATOR EXP(a RATIONAL) RETURNS RATIONAL Java FOREIGN
// Returns Euler's number e raised to the power of a RATIONAL value.
return ValueRational.select(context.getGenerator(), Math.exp(a.doubleValue()));
END OPERATOR;

ANNOUNCE 'operator FLOOR';
OPERATOR FLOOR(a RATIONAL) RETURNS RATIONAL Java FOREIGN
// Returns the largest (closest to positive infinity) RATIONAL value that
// is not greater than the argument and is equal to a mathematical
// integer.
return ValueRational.select(context.getGenerator(), Math.floor(a.doubleValue()));
END OPERATOR;

ANNOUNCE 'operator REMAINDER';
OPERATOR REMAINDER(f1 RATIONAL, f2 RATIONAL) RETURNS RATIONAL Java FOREIGN
// Computes the remainder operation on two arguments as prescribed by the
// IEEE 754 standard.
return ValueRational.select(context.getGenerator(), Math.IEEEremainder(f1.doubleValue(),
f2.doubleValue()));
END OPERATOR;

ANNOUNCE 'operator LOG';
OPERATOR LOG(a RATIONAL) RETURNS RATIONAL Java FOREIGN
// Returns the natural logarithm (base e) of a RATIONAL value.
return ValueRational.select(context.getGenerator(), Math.log(a.doubleValue()));
END OPERATOR;

ANNOUNCE 'operator MAXIMUM';
OPERATOR MAXIMUM(a RATIONAL, b RATIONAL) RETURNS RATIONAL Java FOREIGN
// Returns the greater of two RATIONAL values.
return ValueRational.select(context.getGenerator(), Math.max(a.doubleValue(), b.doubleValue()));
END OPERATOR;

ANNOUNCE 'operator MAXIMUM';
OPERATOR MAXIMUM(a INTEGER, b INTEGER) RETURNS INTEGER Java FOREIGN
// Returns the greater of two INTEGER values.
return ValueInteger.select(context.getGenerator(), Math.max(a.longValue(), b.longValue()));
END OPERATOR;

ANNOUNCE 'operator MINIMUM';
OPERATOR MINIMUM(a RATIONAL, b RATIONAL) RETURNS RATIONAL Java FOREIGN
// Returns the smaller of two RATIONAL values.
return ValueRational.select(context.getGenerator(), Math.min(a.doubleValue(), b.doubleValue()));
END OPERATOR;

ANNOUNCE 'operator MINIMUM';
OPERATOR MINIMUM(a INTEGER, b INTEGER) RETURNS INTEGER Java FOREIGN
// Returns the smaller of two INTEGER values.
return ValueInteger.select(context.getGenerator(), Math.min(a.longValue(), b.longValue()));
END OPERATOR;

ANNOUNCE 'operator POW';
OPERATOR POW(a RATIONAL, b RATIONAL) RETURNS RATIONAL Java FOREIGN
// Returns the value of the first argument raised to the power of the
// second argument.
return ValueRational.select(context.getGenerator(), Math.pow(a.doubleValue(), b.doubleValue()));
END OPERATOR;

ANNOUNCE 'operator RANDOM';
OPERATOR RANDOM() RETURNS RATIONAL Java FOREIGN
// Returns a RATIONAL value with a positive sign, greater than or equal
// to 0.0 and less than 1.0.
return ValueRational.select(context.getGenerator(), Math.random());
END OPERATOR;

ANNOUNCE 'operator RINT';
OPERATOR RINT(a RATIONAL) RETURNS RATIONAL Java FOREIGN
// Returns the RATIONAL value that is closest in value to the argument
// and is equal to a mathematical integer.
return ValueRational.select(context.getGenerator(), Math.rint(a.doubleValue()));
END OPERATOR;

ANNOUNCE 'operator ROUND';
OPERATOR ROUND(a RATIONAL) RETURNS INTEGER Java FOREIGN
// Returns the closest INTEGER to the argument.
return ValueInteger.select(context.getGenerator(), Math.round(a.doubleValue()));
END OPERATOR;

ANNOUNCE 'operator SIN';
OPERATOR SIN(a RATIONAL) RETURNS RATIONAL Java FOREIGN
// Returns the trigonometric sine of an angle.
return ValueRational.select(context.getGenerator(), Math.sin(a.doubleValue()));
END OPERATOR;

ANNOUNCE 'operator SQRT';
OPERATOR SQRT(a RATIONAL) RETURNS RATIONAL Java FOREIGN
// Returns the correctly rounded positive square root of a RATIONAL
// value.
return ValueRational.select(context.getGenerator(), Math.sqrt(a.doubleValue()));
END OPERATOR;

ANNOUNCE 'operator TAN';
OPERATOR TAN(a RATIONAL) RETURNS RATIONAL Java FOREIGN
// Returns the trigonometric tangent of an angle.
return ValueRational.select(context.getGenerator(), Math.tan(a.doubleValue()));
END OPERATOR;

ANNOUNCE 'operator TO_DEGREES';
OPERATOR TO_DEGREES(angrad RATIONAL) RETURNS RATIONAL Java FOREIGN
// Converts an angle measured in radians to an approximately equivalent
// angle measured in degrees.
return ValueRational.select(context.getGenerator(), Math.toDegrees(angrad.doubleValue()));
END OPERATOR;

ANNOUNCE 'operator TO_RADIANS';
OPERATOR TO_RADIANS(angdeg RATIONAL) RETURNS RATIONAL Java FOREIGN
// Converts an angle measured in degrees to an approximately equivalent
// angle measured in radians.
return ValueRational.select(context.getGenerator(), Math.toRadians(angdeg.doubleValue()));
END OPERATOR;

ANNOUNCE 'type STAFFNO';
TYPE STAFFNO possrep { C CHAR constraint LENGTH ( C ) = 4 AND SUBSTRING ( C , 0 , 1 ) = 'S' AND IS_DIGITS ( SUBSTRING ( C , 1 ) ) };

ANNOUNCE 'type COMPID';
TYPE COMPID possrep { C CHAR constraint LENGTH ( C ) = 5 AND SUBSTRING ( C , 0 , 2 ) = 'PC' AND IS_DIGITS ( SUBSTRING ( C , 2 ) ) };

ANNOUNCE 'type SESSION#';
TYPE SESSION# IS { INTEGER CONSTRAINT INTEGER > 0 };

ANNOUNCE 'type AMPM';
TYPE AMPM possrep { C CHAR constraint C = 'AM' OR C = 'PM' };

ANNOUNCE 'type AorT';
TYPE AorT possrep { C CHAR constraint C = 'A' OR C = 'T' };

ANNOUNCE 'type COURSEID';
TYPE COURSEID possrep { C CHAR constraint LENGTH ( C ) = 4 AND SUBSTRING ( C , 0 , 1 ) = 'C' AND IS_DIGITS ( SUBSTRING ( C , 1 ) ) };

ANNOUNCE 'var Types';
VAR Types VIRTUAL ( sys.Types where Owner = 'User' ) { Name , Definition };

ANNOUNCE 'var teacher';
VAR teacher VIRTUAL staff WHERE THE_C ( Stype ) = 'T';

ANNOUNCE 'type DAY';
TYPE DAY possrep { C CHAR constraint C = 'Mon' OR C = 'Tue' OR C = 'Wed' OR C = 'Thu' OR C = 'Fri' };

ANNOUNCE 'var session';
VAR session VIRTUAL lecture union practical;

ANNOUNCE 'var canteach';
VAR canteach REAL RELATION {StaffNo STAFFNO, Subject CHARACTER} KEY {StaffNo, Subject};
canteach := RELATION {
TUPLE {StaffNo STAFFNO("S009"), Subject "Database Administration"},
TUPLE {StaffNo STAFFNO("S009"), Subject "Tutorial D"},
TUPLE {StaffNo STAFFNO("S042"), Subject "Data Mining"},
TUPLE {StaffNo STAFFNO("S042"), Subject "Database Systems"},
TUPLE {StaffNo STAFFNO("S042"), Subject "SQL"},
TUPLE {StaffNo STAFFNO("S055"), Subject "Data Warehouses"},
TUPLE {StaffNo STAFFNO("S055"), Subject "Multimedia Databases"},
TUPLE {StaffNo STAFFNO("S055"), Subject "Object-Relational Databases"},
TUPLE {StaffNo STAFFNO("S057"), Subject "Database Systems"},
TUPLE {StaffNo STAFFNO("S057"), Subject "Object-Oriented Databases"},
TUPLE {StaffNo STAFFNO("S093"), Subject "Database Systems"},
TUPLE {StaffNo STAFFNO("S093"), Subject "Relational Theory"},
TUPLE {StaffNo STAFFNO("S101"), Subject "Database Systems"},
TUPLE {StaffNo STAFFNO("S101"), Subject "Tutorial D"},
TUPLE {StaffNo STAFFNO("S110"), Subject "Networks"},
TUPLE {StaffNo STAFFNO("S110"), Subject "SQL"},
TUPLE {StaffNo STAFFNO("S123"), Subject "Data Warehouses"},
TUPLE {StaffNo STAFFNO("S123"), Subject "Database Systems"},
TUPLE {StaffNo STAFFNO("S123"), Subject "Distributed Data Management"}
}
;

ANNOUNCE 'var staff';
VAR staff REAL RELATION {StaffNo STAFFNO, Name CHARACTER, Stype AorT} KEY {StaffNo};
staff := RELATION {
TUPLE {StaffNo STAFFNO("S003"), Name "Selena Gaunt", Stype AorT("A")},
TUPLE {StaffNo STAFFNO("S005"), Name "Christie Malakite", Stype AorT("A")},
TUPLE {StaffNo STAFFNO("S009"), Name "Olwen Smith", Stype AorT("T")},
TUPLE {StaffNo STAFFNO("S017"), Name "Anne Solent", Stype AorT("A")},
TUPLE {StaffNo STAFFNO("S042"), Name "James Redfern", Stype AorT("T")},
TUPLE {StaffNo STAFFNO("S055"), Name "Robert Weevil", Stype AorT("T")},
TUPLE {StaffNo STAFFNO("S057"), Name "Roger Monk", Stype AorT("T")},
TUPLE {StaffNo STAFFNO("S093"), Name "Darnley Otter", Stype AorT("T")},
TUPLE {StaffNo STAFFNO("S101"), Name "Dimity Stone", Stype AorT("T")},
TUPLE {StaffNo STAFFNO("S110"), Name "Gerda Torp", Stype AorT("T")},
TUPLE {StaffNo STAFFNO("S123"), Name "John Urquhart", Stype AorT("T")},
TUPLE {StaffNo STAFFNO("S142"), Name "Edwin Stallbridge", Stype AorT("A")}
}
;

ANNOUNCE 'var computer';
VAR computer REAL RELATION {CompId COMPID, Make CHARACTER, Speed CHARACTER, RAM CHARACTER, OpSys CHARACTER} KEY {CompId};
computer := RELATION {
TUPLE {CompId COMPID("PC001"), Make "Colossus IV", Speed "2.8GHz", RAM "512MB", OpSys "Windows XP"},
TUPLE {CompId COMPID("PC002"), Make "Colossus IV", Speed "2.8GHz", RAM "1GB", OpSys "Windows Vista"},
TUPLE {CompId COMPID("PC010"), Make "Deep Thought I", Speed "2.8GHz", RAM "2GB", OpSys "Windows Vista"},
TUPLE {CompId COMPID("PC011"), Make "Deep Thought II", Speed "4GHz", RAM "3GB", OpSys "Windows 7"},
TUPLE {CompId COMPID("PC012"), Make "Deep Thought III", Speed "4GHz", RAM "4GB", OpSys "Windows 7"},
TUPLE {CompId COMPID("PC051"), Make "HAL 370", Speed "2.8GHz", RAM "512MB", OpSys "OS/2"},
TUPLE {CompId COMPID("PC052"), Make "HAL 370", Speed "2.8GHz", RAM "1GB", OpSys "OS/2"},
TUPLE {CompId COMPID("PC101"), Make "HAL 390", Speed "4GHz", RAM "2GB", OpSys "OS/3"},
TUPLE {CompId COMPID("PC102"), Make "HAL 390", Speed "4GHz", RAM "2GB", OpSys "OS/3"}
}
;

ANNOUNCE 'var Dir';
VAR Dir VIRTUAL ( sys.Catalog WHERE Owner <> "Rel" ) { Name };

ANNOUNCE 'var sysDir';
VAR sysDir VIRTUAL ( sys.Catalog WHERE Owner = "Rel" ) { Name };

ANNOUNCE 'var Ops';
VAR Ops VIRTUAL sys.Operators { Name };

ANNOUNCE 'var Dependencies';
VAR Dependencies VIRTUAL UNION { EXTEND sys.DependenciesTypeType ADD ( "Type on Type" as Dependency ) , EXTEND sys.DependenciesRelvarType ADD ( "Relvar on Type" as Dependency ) , EXTEND sys.DependenciesOperatorType ADD ( "Operator on Type" as Dependency ) , EXTEND sys.DependenciesRelvarRelvar ADD ( "Relvar on Relvar" as Dependency ) , EXTEND sys.DependenciesTypeOperator ADD ( "Type on Operator" as Dependency ) , EXTEND sys.DependenciesOperatorRelvar ADD ( "Operator on Relvar" as Dependency ) , EXTEND sys.DependenciesRelvarOperator ADD ( "Relvar on Operator" as Dependency ) , EXTEND sys.DependenciesConstraintRelvar ADD ( "Constraint on Relvar" as Dependency ) , EXTEND sys.DependenciesOperatorOperator ADD ( "Operator on Operator" as Dependency ) , EXTEND sys.DependenciesConstraintOperator ADD ( "Constraint on Operator" as Dependency ) , EXTEND sys.DependenciesTypeRelvar ADD ( "Type on Relvar" as Dependency ) , EXTEND sys.DependenciesConstraintType ADD ( "Constraint on Type" as Dependency ) };

ANNOUNCE 'var sessionneeds';
VAR sessionneeds REAL RELATION {CourseId COURSEID, Session# SESSION#, CompId COMPID} KEY {CourseId, Session#, CompId};
sessionneeds := RELATION {
TUPLE {CourseId COURSEID("C876"), Session# SESSION#(3), CompId COMPID("PC001")},
TUPLE {CourseId COURSEID("C876"), Session# SESSION#(3), CompId COMPID("PC002")},
TUPLE {CourseId COURSEID("C876"), Session# SESSION#(4), CompId COMPID("PC001")},
TUPLE {CourseId COURSEID("C876"), Session# SESSION#(4), CompId COMPID("PC002")},
TUPLE {CourseId COURSEID("C876"), Session# SESSION#(5), CompId COMPID("PC010")},
TUPLE {CourseId COURSEID("C876"), Session# SESSION#(5), CompId COMPID("PC011")},
TUPLE {CourseId COURSEID("C876"), Session# SESSION#(5), CompId COMPID("PC012")},
TUPLE {CourseId COURSEID("C877"), Session# SESSION#(2), CompId COMPID("PC051")},
TUPLE {CourseId COURSEID("C877"), Session# SESSION#(2), CompId COMPID("PC052")},
TUPLE {CourseId COURSEID("C877"), Session# SESSION#(5), CompId COMPID("PC051")},
TUPLE {CourseId COURSEID("C877"), Session# SESSION#(5), CompId COMPID("PC052")},
TUPLE {CourseId COURSEID("C877"), Session# SESSION#(8), CompId COMPID("PC101")},
TUPLE {CourseId COURSEID("C877"), Session# SESSION#(8), CompId COMPID("PC102")},
TUPLE {CourseId COURSEID("C877"), Session# SESSION#(10), CompId COMPID("PC101")},
TUPLE {CourseId COURSEID("C877"), Session# SESSION#(10), CompId COMPID("PC102")}
}
;

ANNOUNCE 'var practical';
VAR practical REAL RELATION {CourseId COURSEID, Session# SESSION#, Day DAY, Time AMPM, Subject CHARACTER} KEY {CourseId, Session#} KEY {CourseId, Day, Time};
practical := RELATION {
TUPLE {CourseId COURSEID("C876"), Session# SESSION#(3), Day DAY("Thu"), Time AMPM("AM"), Subject "Tutorial D"},
TUPLE {CourseId COURSEID("C876"), Session# SESSION#(4), Day DAY("Thu"), Time AMPM("PM"), Subject "Tutorial D"},
TUPLE {CourseId COURSEID("C876"), Session# SESSION#(5), Day DAY("Fri"), Time AMPM("AM"), Subject "SQL"},
TUPLE {CourseId COURSEID("C877"), Session# SESSION#(2), Day DAY("Mon"), Time AMPM("PM"), Subject "Distributed Data Management"},
TUPLE {CourseId COURSEID("C877"), Session# SESSION#(5), Day DAY("Wed"), Time AMPM("AM"), Subject "Object-Relational Databases"},
TUPLE {CourseId COURSEID("C877"), Session# SESSION#(8), Day DAY("Thu"), Time AMPM("PM"), Subject "Data Warehouses"},
TUPLE {CourseId COURSEID("C877"), Session# SESSION#(10), Day DAY("Fri"), Time AMPM("PM"), Subject "Data Mining"}
}
;

ANNOUNCE 'var lecture';
VAR lecture REAL RELATION {CourseId COURSEID, Session# SESSION#, Day DAY, Time AMPM, Subject CHARACTER} KEY {CourseId, Session#} KEY {CourseId, Day, Time};
lecture := RELATION {
TUPLE {CourseId COURSEID("C876"), Session# SESSION#(1), Day DAY("Wed"), Time AMPM("AM"), Subject "Database Systems"},
TUPLE {CourseId COURSEID("C876"), Session# SESSION#(2), Day DAY("Wed"), Time AMPM("PM"), Subject "Relational Theory"},
TUPLE {CourseId COURSEID("C876"), Session# SESSION#(6), Day DAY("Fri"), Time AMPM("PM"), Subject "Database Administration"},
TUPLE {CourseId COURSEID("C877"), Session# SESSION#(1), Day DAY("Mon"), Time AMPM("AM"), Subject "Distributed Data Management"},
TUPLE {CourseId COURSEID("C877"), Session# SESSION#(3), Day DAY("Tue"), Time AMPM("AM"), Subject "Object-Oriented Databases"},
TUPLE {CourseId COURSEID("C877"), Session# SESSION#(4), Day DAY("Tue"), Time AMPM("PM"), Subject "Object-Relational Databases"},
TUPLE {CourseId COURSEID("C877"), Session# SESSION#(6), Day DAY("Wed"), Time AMPM("PM"), Subject "Multimedia Databases"},
TUPLE {CourseId COURSEID("C877"), Session# SESSION#(7), Day DAY("Thu"), Time AMPM("AM"), Subject "Data Warehouses"},
TUPLE {CourseId COURSEID("C877"), Session# SESSION#(9), Day DAY("Fri"), Time AMPM("AM"), Subject "Data Mining"}
}
;

ANNOUNCE 'var course';
VAR course REAL RELATION {CourseId COURSEID, Title CHARACTER, Duration INTEGER} KEY {CourseId};
course := RELATION {
TUPLE {CourseId COURSEID("C876"), Title "Relational Database Systems", Duration SESSION#(3)},
TUPLE {CourseId COURSEID("C877"), Title "Advanced Database Technology", Duration SESSION#(5)}
}
;

ANNOUNCE 'var teaches';
VAR teaches REAL RELATION {StaffNo STAFFNO, CourseId COURSEID} KEY {StaffNo, CourseId};
teaches := RELATION {
TUPLE {StaffNo STAFFNO("S009"), CourseId COURSEID("C876")},
TUPLE {StaffNo STAFFNO("S042"), CourseId COURSEID("C876")},
TUPLE {StaffNo STAFFNO("S042"), CourseId COURSEID("C877")},
TUPLE {StaffNo STAFFNO("S055"), CourseId COURSEID("C877")},
TUPLE {StaffNo STAFFNO("S057"), CourseId COURSEID("C877")},
TUPLE {StaffNo STAFFNO("S093"), CourseId COURSEID("C876")},
TUPLE {StaffNo STAFFNO("S123"), CourseId COURSEID("C877")}
}
;

ANNOUNCE 'var administrator';
VAR administrator VIRTUAL staff WHERE THE_C ( Stype ) = 'A';

ANNOUNCE 'var courseadmin';
VAR courseadmin REAL RELATION {CourseId COURSEID, StaffNo STAFFNO} KEY {CourseId} KEY {StaffNo};
courseadmin := RELATION {
TUPLE {CourseId COURSEID("C876"), StaffNo STAFFNO("S005")},
TUPLE {CourseId COURSEID("C877"), StaffNo STAFFNO("S017")}
}
;

ANNOUNCE 'constraint AdminRunsCourse';
CONSTRAINT AdminRunsCourse IS_EMPTY ( courseadmin NOT MATCHING course );

ANNOUNCE 'constraint CourseExistsForSession';
CONSTRAINT CourseExistsForSession IS_EMPTY ( session NOT MATCHING course );

ANNOUNCE 'constraint LecturesPracticalsDisjoint';
CONSTRAINT LecturesPracticalsDisjoint IS_EMPTY ( lecture { CourseId , Session# } MATCHING practical );

ANNOUNCE 'constraint LecturesPracticalsDisjoint2';
CONSTRAINT LecturesPracticalsDisjoint2 IS_EMPTY ( lecture { CourseId , Day , Time } MATCHING practical );

ANNOUNCE 'constraint NoCompsInLectures';
CONSTRAINT NoCompsInLectures IS_EMPTY ( sessionneeds MATCHING lecture );

ANNOUNCE 'constraint CompsInPracticals';
CONSTRAINT CompsInPracticals IS_EMPTY ( practical NOT MATCHING sessionneeds );

ANNOUNCE 'constraint PracticalUsingCompExists';
CONSTRAINT PracticalUsingCompExists IS_EMPTY ( sessionneeds NOT MATCHING practical );

ANNOUNCE 'constraint UsedCompExists';
CONSTRAINT UsedCompExists IS_EMPTY ( sessionneeds NOT MATCHING computer );

ANNOUNCE 'constraint TeacherCanTeach';
CONSTRAINT TeacherCanTeach IS_EMPTY ( teacher NOT MATCHING canteach );

ANNOUNCE 'constraint CanTeachFK';
CONSTRAINT CanTeachFK IS_EMPTY ( canteach NOT MATCHING teacher );

ANNOUNCE 'constraint TeachesFK1';
CONSTRAINT TeachesFK1 IS_EMPTY ( teaches NOT MATCHING teacher );

ANNOUNCE 'constraint TeachesFK2';
CONSTRAINT TeachesFK2 IS_EMPTY ( teaches NOT MATCHING course );

ANNOUNCE 'constraint coursenonempty';
CONSTRAINT coursenonempty IS_EMPTY ( course NOT MATCHING ( practical union lecture ) );

ANNOUNCE 'constraint teacheravailable';
CONSTRAINT teacheravailable IS_EMPTY ( session not matching ( canteach join teaches ) );

ANNOUNCE 'constraint CourseRunByAdmin';
CONSTRAINT CourseRunByAdmin IS_EMPTY ( courseadmin not matching administrator );

COMMIT;

/*** End of Rel Database Backup ***/
ANNOUNCE 'End of Script.';
Dave
Site Admin
Posts: 368
Joined: Sun Nov 27, 2005 7:19 pm

Re: Backup defines virtual relvar in advance of dependent re

Post by Dave »

Strange... I've been unable to duplicate the problem. After editing the backup script to put the definition of both teacher and session after staff, the backup can be loaded. Then I can successfully back it up and restore it.

I noticed that type SESSION# is inherited from INTEGER. Since the creation order of all definitions in the catalog is also an INTEGER, I suspect there may be a bug related to creating subtypes of INTEGER, but at this point I'm afraid I don't know what it might be.
Post Reply