Script created by Backup gives run-time error

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

Script created by Backup gives run-time error

Post by HughDarwen »

The script below was generated by pressing DBrowser's Backup button, using Version 3.18. This script represents Chris Date's supplier-and-parts database, taking advantage of Rel's UDT support for the types SNO, PNO, JNO, NAME, COLOUR, and WEIGHT. If you scroll to the end of the script you will see the error message that resulted from running the script against a brand new database (i.e., an empty folder in Windows Vista). I get the same error message if I use Version 3.17 instead. I cannot relate the given line number, 161, to the script.

Btw, the error does not arise if I execute the various commands one by one in the sequence shown.

Hugh Darwen

/*** Rel Database Backup ***/

// Created in Rel Version 0.3.18 Alpha
// 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.getFalse();
return ValueBoolean.getTrue();
END OPERATOR;

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

ANNOUNCE 'operator SUBSTRING';
OPERATOR SUBSTRING(s CHARACTER, index INTEGER) RETURNS CHARACTER Java FOREIGN
// Substring, 0 based
return new ValueCharacter(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 new ValueCharacter(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 new ValueInteger(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 new ValueInteger(s.stringValue().compareToIgnoreCase(str.stringValue()));
END OPERATOR;

ANNOUNCE 'operator ENDS_WITH';
OPERATOR ENDS_WITH(s CHARACTER, suffx CHARACTER) RETURNS BOOLEAN Java FOREIGN
return ValueBoolean.getBoolean(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.getBoolean(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 new ValueInteger(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 new ValueInteger(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 new ValueInteger(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 new ValueInteger(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.getBoolean(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.getBoolean(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 new ValueCharacter(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 new ValueCharacter(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.getBoolean(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.getBoolean(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 new ValueCharacter(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 new ValueCharacter(s.stringValue().toUpperCase());
END OPERATOR;

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

ANNOUNCE 'type SNO';
TYPE SNO POSSREP { c CHAR CONSTRAINT SUBSTRING ( c , 0 , 1 ) = 'S' AND IS_DIGITS ( SUBSTRING ( c , 1 ) ) };

ANNOUNCE 'type PNO';
TYPE PNO POSSREP { c CHAR CONSTRAINT SUBSTRING ( c , 0 , 1 ) = 'P' AND IS_DIGITS ( SUBSTRING ( c , 1 ) ) };

ANNOUNCE 'type JNO';
TYPE JNO POSSREP { c CHAR CONSTRAINT SUBSTRING ( c , 0 , 1 ) = 'J' AND IS_DIGITS ( SUBSTRING ( c , 1 ) ) };

ANNOUNCE 'type NAME';
TYPE NAME POSSREP { c CHAR CONSTRAINT LENGTH ( c ) > 0 AND LENGTH ( c ) <= 30 };

ANNOUNCE 'type COLOUR';
TYPE COLOUR POSSREP { c CHAR CONSTRAINT c = 'Red' or c = 'Orange' or c = 'Yellow' or c = 'Green' or c = 'Blue' or c = 'Indigo' or c = 'Violet' or c = 'Black' or c = 'White' or c = 'Brown' or c = 'Puce' or c = 'Pink' or c = 'Purple' or c = 'Mauve' or c = 'Turquoise' or c = 'Scarlet' or c = 'Crimson' };

ANNOUNCE 'type WEIGHT';
TYPE WEIGHT POSSREP { r RATIONAL CONSTRAINT r > 0.0 };

ANNOUNCE 'var SP';
VAR SP REAL RELATION {S# SNO, P# PNO, Qty INTEGER} KEY {S#, P#};
SP := RELATION {
TUPLE {S# SNO("S1"), P# PNO("P1"), Qty 300},
TUPLE {S# SNO("S1"), P# PNO("P2"), Qty 200},
TUPLE {S# SNO("S1"), P# PNO("P3"), Qty 400},
TUPLE {S# SNO("S1"), P# PNO("P4"), Qty 200},
TUPLE {S# SNO("S1"), P# PNO("P5"), Qty 100},
TUPLE {S# SNO("S1"), P# PNO("P6"), Qty 100},
TUPLE {S# SNO("S2"), P# PNO("P1"), Qty 300},
TUPLE {S# SNO("S2"), P# PNO("P2"), Qty 400},
TUPLE {S# SNO("S3"), P# PNO("P2"), Qty 200},
TUPLE {S# SNO("S4"), P# PNO("P2"), Qty 200},
TUPLE {S# SNO("S4"), P# PNO("P4"), Qty 300},
TUPLE {S# SNO("S4"), P# PNO("P5"), Qty 400}
}
;

ANNOUNCE 'var S';
VAR S REAL RELATION {Status INTEGER, City CHARACTER, S# SNO, Sname NAME} KEY {S#};
S := RELATION {
TUPLE {Status 20, City "London", S# SNO("S1"), Sname NAME("Smith")},
TUPLE {Status 10, City "Paris", S# SNO("S2"), Sname NAME("Jones")},
TUPLE {Status 30, City "Paris", S# SNO("S3"), Sname NAME("Blake")},
TUPLE {Status 20, City "London", S# SNO("S4"), Sname NAME("Clark")},
TUPLE {Status 30, City "Athens", S# SNO("S5"), Sname NAME("Adams")}
}
;

ANNOUNCE 'var P';
VAR P REAL RELATION {City CHARACTER, P# PNO, Pname NAME, Weight WEIGHT, Colour COLOUR} KEY {P#};
P := RELATION {
TUPLE {City "London", P# PNO("P1"), Pname NAME("Nut"), Weight WEIGHT(12.0), Colour COLOUR("Red")},
TUPLE {City "Paris", P# PNO("P2"), Pname NAME("Bolt"), Weight WEIGHT(17.0), Colour COLOUR("Green")},
TUPLE {City "Oslo", P# PNO("P3"), Pname NAME("Screw"), Weight WEIGHT(17.0), Colour COLOUR("Blue")},
TUPLE {City "London", P# PNO("P4"), Pname NAME("Screw"), Weight WEIGHT(14.0), Colour COLOUR("Red")},
TUPLE {City "Paris", P# PNO("P5"), Pname NAME("Cam"), Weight WEIGHT(12.0), Colour COLOUR("Blue")},
TUPLE {City "London", P# PNO("P6"), Pname NAME("Cog"), Weight WEIGHT(19.0), Colour COLOUR("Red")}
}
;

ANNOUNCE 'var J';
VAR J REAL RELATION {J# JNO, Jname NAME, City CHARACTER} KEY {J#};
J := RELATION {
TUPLE {J# JNO("J1"), Jname NAME("Sorter"), City "Paris"},
TUPLE {J# JNO("J2"), Jname NAME("Display"), City "Rome"},
TUPLE {J# JNO("J3"), Jname NAME("OCR"), City "Athens"},
TUPLE {J# JNO("J4"), Jname NAME("Console"), City "Athens"},
TUPLE {J# JNO("J5"), Jname NAME("RAID"), City "London"},
TUPLE {J# JNO("J6"), Jname NAME("EDS"), City "Oslo"},
TUPLE {J# JNO("J7"), Jname NAME("Tape"), City "London"}
}
;

ANNOUNCE 'var OwnBaseRelvars';
VAR OwnBaseRelvars VIRTUAL ( sys.Catalog where Owner = 'User' and NOT ( isVirtual ) ) { Name , Definition };

ANNOUNCE 'var SPJ';
VAR SPJ REAL RELATION {S# SNO, P# PNO, J# JNO, Qty INTEGER} KEY {S#, P#, J#};
SPJ := RELATION {
TUPLE {S# SNO("S1"), P# PNO("P1"), J# JNO("J1"), Qty 200},
TUPLE {S# SNO("S1"), P# PNO("P1"), J# JNO("J4"), Qty 700},
TUPLE {S# SNO("S2"), P# PNO("P3"), J# JNO("J1"), Qty 400},
TUPLE {S# SNO("S2"), P# PNO("P3"), J# JNO("J2"), Qty 200},
TUPLE {S# SNO("S2"), P# PNO("P3"), J# JNO("J3"), Qty 200},
TUPLE {S# SNO("S2"), P# PNO("P3"), J# JNO("J4"), Qty 500},
TUPLE {S# SNO("S2"), P# PNO("P3"), J# JNO("J5"), Qty 600},
TUPLE {S# SNO("S2"), P# PNO("P3"), J# JNO("J6"), Qty 400},
TUPLE {S# SNO("S2"), P# PNO("P3"), J# JNO("J7"), Qty 800},
TUPLE {S# SNO("S2"), P# PNO("P5"), J# JNO("J2"), Qty 100},
TUPLE {S# SNO("S3"), P# PNO("P3"), J# JNO("J1"), Qty 200},
TUPLE {S# SNO("S3"), P# PNO("P4"), J# JNO("J2"), Qty 500},
TUPLE {S# SNO("S4"), P# PNO("P6"), J# JNO("J3"), Qty 300},
TUPLE {S# SNO("S4"), P# PNO("P6"), J# JNO("J7"), Qty 300},
TUPLE {S# SNO("S5"), P# PNO("P1"), J# JNO("J4"), Qty 100},
TUPLE {S# SNO("S5"), P# PNO("P2"), J# JNO("J2"), Qty 200},
TUPLE {S# SNO("S5"), P# PNO("P2"), J# JNO("J4"), Qty 100},
TUPLE {S# SNO("S5"), P# PNO("P3"), J# JNO("J4"), Qty 200},
TUPLE {S# SNO("S5"), P# PNO("P4"), J# JNO("J4"), Qty 800},
TUPLE {S# SNO("S5"), P# PNO("P5"), J# JNO("J4"), Qty 400},
TUPLE {S# SNO("S5"), P# PNO("P5"), J# JNO("J5"), Qty 500},
TUPLE {S# SNO("S5"), P# PNO("P5"), J# JNO("J7"), Qty 100},
TUPLE {S# SNO("S5"), P# PNO("P6"), J# JNO("J2"), Qty 200},
TUPLE {S# SNO("S5"), P# PNO("P6"), J# JNO("J4"), Qty 500}
}
;

COMMIT;

/*** End of Rel Database Backup ***/
ANNOUNCE 'End of Script.';


operator IS_DIGITS
operator LENGTH
operator SUBSTRING
operator SUBSTRING
operator COMPARE_TO
operator COMPARE_TO_IGNORE_CASE
operator ENDS_WITH
operator EQUALS_IGNORE_CASE
operator INDEX_OF
operator INDEX_OF
operator LAST_INDEX_OF
operator LAST_INDEX_OF
operator MATCHES
operator REGION_MATCHES
operator REPLACE_ALL
operator REPLACE_FIRST
operator STARTS_WITH
operator STARTS_WITH
operator TO_LOWER_CASE
operator TO_UPPER_CASE
operator TRIM
type SNO
type PNO
type JNO
type NAME
type COLOUR
type WEIGHT
var SP
var S
var P
var J
var OwnBaseRelvars
var SPJ
End of Script.



ERROR: Selector SNO(CHARACTER) violates POSSREP constraint in type 'SNO'.


Line 161, column 23 near '"S1"'



Saved D:\AllDocs\All Rel Databases\Test\Results\Spurious-type-constraint-violation.txt
Dave
Site Admin
Posts: 368
Joined: Sun Nov 27, 2005 7:19 pm

Re: Script created by Backup gives run-time error

Post by Dave »

Sorry for my slow (you posted on Tuesday and today is Thursday - I generally try to give same-day service! :)) response!

Coincidentally, I've just been testing backup/restore and have run across a bug in which INTEGER and RATIONAL values larger than a certain number of characters cause an exception when restored. I've fixed this for the next update. The bug you've found, however, seems unrelated. I'll do some testing and post again when I have an explanation.
Dave
Site Admin
Posts: 368
Joined: Sun Nov 27, 2005 7:19 pm

Re: Script created by Backup gives run-time error

Post by Dave »

I've fixed this bug.

It turned out to require the right circumstances: A user-defined type with a constraint that employs a user-defined Java-based operator, and the operator & type are defined along with an attempt to select a value of that type all in the same transaction.

An update with this fix will be available in a day or two.
Post Reply