Permalink
Browse files

error reporting for xmldb (credit: Nigel McNie <nigel@catalyst.net.nz>)

  • Loading branch information...
1 parent d9bd994 commit 722c3bfeded346b20af59ee4878922f1822a45de mjollnir_ committed Oct 19, 2006
View
@@ -1155,4 +1155,8 @@ function change_db_encoding() {
}
}
+function xmldb_dbg($message) {
+ error_log($message);
+}
+
?>
@@ -252,6 +252,7 @@ function arr2XMLDBField($xmlarr) {
$this->name = trim($xmlarr['@']['NAME']);
} else {
$this->errormsg = 'Missing NAME attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
@@ -262,10 +263,12 @@ function arr2XMLDBField($xmlarr) {
$this->type = $type;
} else {
$this->errormsg = 'Invalid TYPE attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
} else {
$this->errormsg = 'Missing TYPE attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
@@ -277,9 +280,11 @@ function arr2XMLDBField($xmlarr) {
$this->type == XMLDB_TYPE_CHAR) {
if (!(is_numeric($length)&&(intval($length)==floatval($length)))) {
$this->errormsg = 'Incorrect LENGTH attribute for int, number or char fields';
+ xmldb_dbg($this->errormsg);
$result = false;
} else if (!$length) {
$this->errormsg = 'Zero LENGTH attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
}
@@ -293,6 +298,7 @@ function arr2XMLDBField($xmlarr) {
$length != 'medium' &&
$length != 'small') {
$this->errormsg = 'Incorrect LENGTH attribute for text and binary fields (only big, medium and small allowed)';
+ xmldb_dbg($this->errormsg);
$result = false;
}
}
@@ -308,6 +314,7 @@ function arr2XMLDBField($xmlarr) {
$this->unsigned = false;
} else {
$this->errormsg = 'Incorrect UNSIGNED attribute (true/false allowed)';
+ xmldb_dbg($this->errormsg);
$result = false;
}
}
@@ -320,6 +327,7 @@ function arr2XMLDBField($xmlarr) {
$this->notnull = false;
} else {
$this->errormsg = 'Incorrect NOTNULL attribute (true/false allowed)';
+ xmldb_dbg($this->errormsg);
$result = false;
}
}
@@ -332,6 +340,7 @@ function arr2XMLDBField($xmlarr) {
$this->sequence = false;
} else {
$this->errormsg = 'Incorrect SEQUENCE attribute (true/false allowed)';
+ xmldb_dbg($this->errormsg);
$result = false;
}
}
@@ -348,6 +357,7 @@ function arr2XMLDBField($xmlarr) {
$this->enum = false;
} else {
$this->errormsg = 'Incorrect ENUM attribute (true/false allowed)';
+ xmldb_dbg($this->errormsg);
$result = false;
}
}
@@ -356,6 +366,7 @@ function arr2XMLDBField($xmlarr) {
$enumvalues = strtolower(trim($xmlarr['@']['ENUMVALUES']));
if (!$this->enum) {
$this->errormsg = 'Wrong ENUMVALUES attribute (not ENUM)';
+ xmldb_dbg($this->errormsg);
$result = false;
$this->enumvalues = $enumvalues;
} else {
@@ -374,16 +385,19 @@ function arr2XMLDBField($xmlarr) {
if (substr($enumelement, 0, 1) != "'" ||
substr($enumelement, -1, 1) != "'") {
$this->errormsg = 'Incorrect ENUMVALUES attribute (some value is not properly quoted)';
+ xmldb_dbg($this->errormsg);
$result = false;
}
}
} else {
$this->errormsg = 'Incorrect ENUMVALUES attribute (comma separated of quoted values)';
+ xmldb_dbg($this->errormsg);
$result = false;
}
}
} else if ($this->enum) {
$this->errormsg = 'Incorrect ENUMVALUES attribute (field is not declared as ENUM)';
+ xmldb_dbg($this->errormsg);
$result = false;
}
/// Finally, set the value
@@ -399,13 +413,16 @@ function arr2XMLDBField($xmlarr) {
$this->type == XMLDB_TYPE_FLOAT) {
if (!(is_numeric($decimals)&&(intval($decimals)==floatval($decimals)))) {
$this->errormsg = 'Incorrect DECIMALS attribute for number field';
+ xmldb_dbg($this->errormsg);
$result = false;
} else if ($this->length <= $decimals){
$this->errormsg = 'Incorrect DECIMALS attribute (bigget than length)';
+ xmldb_dbg($this->errormsg);
$result = false;
}
} else {
$this->errormsg = 'Incorrect DECIMALS attribute for non-number field';
+ xmldb_dbg($this->errormsg);
$result = false;
}
} else {
@@ -96,6 +96,7 @@ function arr2XMLDBIndex($xmlarr) {
$this->name = trim($xmlarr['@']['NAME']);
} else {
$this->errormsg = 'Missing NAME attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
@@ -107,10 +108,12 @@ function arr2XMLDBIndex($xmlarr) {
$this->unique = false;
} else {
$this->errormsg = 'Incorrect UNIQUE attribute (true/false allowed)';
+ xmldb_dbg($this->errormsg);
$result = false;
}
} else {
$this->errormsg = 'Undefined UNIQUE attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
@@ -124,14 +127,17 @@ function arr2XMLDBIndex($xmlarr) {
}
} else {
$this->errormsg = 'Incorrect FIELDS attribute (comma separated of fields)';
+ xmldb_dbg($this->errormsg);
$result = false;
}
} else {
$this->errormsg = 'Empty FIELDS attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
} else {
$this->errormsg = 'Missing FIELDS attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
/// Finally, set the array of fields
@@ -133,6 +133,7 @@ function arr2XMLDBKey($xmlarr) {
$this->name = trim($xmlarr['@']['NAME']);
} else {
$this->errormsg = 'Missing NAME attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
@@ -143,10 +144,12 @@ function arr2XMLDBKey($xmlarr) {
$this->type = $type;
} else {
$this->errormsg = 'Invalid TYPE attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
} else {
$this->errormsg = 'Missing TYPE attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
@@ -160,14 +163,17 @@ function arr2XMLDBKey($xmlarr) {
}
} else {
$this->errormsg = 'Incorrect FIELDS attribute (comma separated of fields)';
+ xmldb_dbg($this->errormsg);
$result = false;
}
} else {
$this->errormsg = 'Empty FIELDS attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
} else {
$this->errormsg = 'Missing FIELDS attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
/// Finally, set the array of fields
@@ -180,15 +186,18 @@ function arr2XMLDBKey($xmlarr) {
$reftable = strtolower(trim($xmlarr['@']['REFTABLE']));
if (!$reftable) {
$this->errormsg = 'Empty REFTABLE attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
} else {
$this->errormsg = 'Wrong REFTABLE attribute (only FK can have it)';
+ xmldb_dbg($this->errormsg);
$result = false;
}
} else if ($this->type == XMLDB_KEY_FOREIGN ||
$this->type == XMLDB_KEY_FOREIGN_UNIQUE) {
$this->errormsg = 'Missing REFTABLE attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
/// Finally, set the reftable
@@ -210,19 +219,23 @@ function arr2XMLDBKey($xmlarr) {
}
} else {
$this->errormsg = 'Incorrect REFFIELDS attribute (comma separated of fields)';
+ xmldb_dbg($this->errormsg);
$result = false;
}
} else {
$this->errormsg = 'Empty REFFIELDS attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
} else {
$this->errormsg = 'Wrong REFFIELDS attribute (only FK can have it)';
+ xmldb_dbg($this->errormsg);
$result = false;
}
} else if ($this->type == XMLDB_KEY_FOREIGN ||
$this->type == XMLDB_KEY_FOREIGN_UNIQUE) {
$this->errormsg = 'Missing REFFIELDS attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
/// Finally, set the array of reffields
@@ -103,6 +103,7 @@ function arr2XMLDBStatement($xmlarr) {
$this->table = strtolower(trim($xmlarr['@']['TABLE']));
} else {
$this->errormsg = 'Missing TABLE attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
@@ -113,10 +114,12 @@ function arr2XMLDBStatement($xmlarr) {
$this->type = $type;
} else {
$this->errormsg = 'Invalid TYPE attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
} else {
$this->errormsg = 'Missing TYPE attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
@@ -131,6 +134,7 @@ function arr2XMLDBStatement($xmlarr) {
$sentencesarr[] = trim($sentence['@']['TEXT']);
} else {
$this->errormsg = 'Missing TEXT attribute in sentence';
+ xmldb_dbg($this->errormsg);
$result = false;
}
}
@@ -151,25 +155,30 @@ function arr2XMLDBStatement($xmlarr) {
/// Check that we aren't inserting the id field
if (in_array('id', $fields)) {
$this->errormsg = 'Cannot insert the "id" field. It is an autonumeric column';
+ xmldb_dbg($this->errormsg);
$result = false;
}
if ($result && count($fields) == 0) {
$this->errormsg = 'Missing fields in sentence "' . $sentence . '"';
+ xmldb_dbg($this->errormsg);
$result = false;
}
if ($result && count($values) == 0) {
$this->errormsg = 'Missing values in sentence "' . $sentence . '"';
+ xmldb_dbg($this->errormsg);
$result = false;
}
if ($result && count($fields) != count($values)) {
$this->errormsg = 'Incorrect number of fields (' .implode(', ', $fields) . ') or values (' . implode(', ', $values) . ')';
+ xmldb_dbg($this->errormsg);
$result = false;
}
}
}
} else {
/// Sentences different from INSERT are not valid for now
$this->errormsg = 'Only INSERT statements are supported';
+ xmldb_dbg($this->errormsg);
$result = false;
}
@@ -342,18 +342,21 @@ function arr2XMLDBStructure($xmlarr) {
$this->path = trim($xmlarr['XMLDB']['@']['PATH']);
} else {
$this->errormsg = 'Missing PATH attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
if (isset($xmlarr['XMLDB']['@']['VERSION'])) {
$this->version = trim($xmlarr['XMLDB']['@']['VERSION']);
} else {
$this->errormsg = 'Missing VERSION attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
if (isset($xmlarr['XMLDB']['@']['COMMENT'])) {
$this->comment = trim($xmlarr['XMLDB']['@']['COMMENT']);
} else {
$this->errormsg = 'Missing COMMENT attribute';
+ xmldb_dbg($this->errormsg);
$result = false;
}
@@ -369,11 +372,13 @@ function arr2XMLDBStructure($xmlarr) {
$this->tables[] = $table;
if (!$table->isLoaded()) {
$this->errormsg = 'Problem loading table ' . $name;
+ xmldb_dbg($this->errormsg);
$result = false;
}
}
} else {
$this->errormsg = 'Missing TABLES section';
+ xmldb_dbg($this->errormsg);
$result = false;
}
@@ -382,16 +387,19 @@ function arr2XMLDBStructure($xmlarr) {
/// Check tables names are ok (lowercase, a-z _-)
if (!$this->checkNameValues($this->tables)) {
$this->errormsg = 'Some TABLES name values are incorrect';
+ xmldb_dbg($this->errormsg);
$result = false;
}
/// Check previous & next are ok (duplicates and existing tables)
if ($result && !$this->checkPreviousNextValues($this->tables)) {
$this->errormsg = 'Some TABLES previous/next values are incorrect';
+ xmldb_dbg($this->errormsg);
$result = false;
}
/// Order tables
if ($result && !$this->orderTables($this->tables)) {
$this->errormsg = 'Error ordering the tables';
+ xmldb_dbg($this->errormsg);
$result = false;
}
}
@@ -408,6 +416,7 @@ function arr2XMLDBStructure($xmlarr) {
$this->statements[] = $statement;
if (!$statement->isLoaded()) {
$this->errormsg = 'Problem loading statement ' . $name;
+ xmldb_dbg($this->errormsg);
$result = false;
}
}
@@ -418,16 +427,19 @@ function arr2XMLDBStructure($xmlarr) {
/// Check statements names are ok (lowercase, a-z _-)
if (!$this->checkNameValues($this->statements)) {
$this->errormsg = 'Some STATEMENTS name values are incorrect';
+ xmldb_dbg($this->errormsg);
$result = false;
}
/// Check previous & next are ok (duplicates and existing statements)
if ($result && !$this->checkPreviousNextValues($this->statements)) {
$this->errormsg = 'Some STATEMENTS previous/next values are incorrect';
+ xmldb_dbg($this->errormsg);
$result = false;
}
/// Order statements
if ($result && !$this->orderStatements($this->statements)) {
$this->errormsg = 'Error ordering the statements';
+ xmldb_dbg($this->errormsg);
$result = false;
}
}
Oops, something went wrong.

0 comments on commit 722c3bf

Please sign in to comment.