From: Marc A. <mar...@fr...> - 2004-03-24 15:23:18
|
Hello, Richard Tango-Lowy asked me to send this also to the AXMLS mailing list. I am using adodb-xmlschema to describe my database, but I wanted to use two features from the adodb-datadict that I was unable to use with the current version of axmls : the DEFTIMESTAMP and CONSTRAINT field options. I propose a simplified database schema to illustrate my patch, sample.xml : <?xml version="1.0"?> <schema version="0.2"> <table name="cart"> <descr> A simplified shopping cart. </descr> <field name="cart_id" type="I"> <KEY/> <AUTOINCREMENT/> </field> <field name="created" type="T"> <NOTNULL/> </field> </table> <table name="item"> <field name="item_id" type="I"> <KEY/> <AUTOINCREMENT/> </field> <field name="name" type="C" size="50"/> <field name="cart_id" type="I"> <NOTNULL/> </field> </table> </schema> I wanted to declare DEFTIMESTAMP for the created field in the cart table and add a constraint on the cart_id field in the item table. The code parses an opts attribute in the field, but I think there is a bug in the code near line 382. Is this attribute described in the dtd ? The dtd shows a constraint element for the field, but I think the code doesn't parse it. My patch implements the parsing of a constraint element in a field. The following schema can be parsed with my pactched code (sample1.xml, changes in bold) : <?xml version="1.0"?> <schema version="0.2"> <table name="cart"> <descr> A simplified shopping cart. </descr> <field name="cart_id" type="I"> <KEY/> <AUTOINCREMENT/> </field> <field name="created" type="T" opts="DEFTIMESTAMP"> <NOTNULL/> </field> </table> <table name="item"> <field name="item_id" type="I"> <KEY/> <AUTOINCREMENT/> </field> <field name="name" type="C" size="50"/> <field name="cart_id" type="I"> <constraint> REFERENCES cart (cart_id) </constraint> <NOTNULL/> </field> </table> </schema> The patch inline : diff -Naur adodb-xmlschema-1.0.1-cvs200403241400/adodb-xmlschema.inc.php adodb-xmlschema-1.0.1-cvs200403241400-mod/adodb-xmlschema.inc.php --- adodb-xmlschema-1.0.1-cvs200403241400/adodb-xmlschema.inc.php 2004-03-23 18:59:38.000000000 +0100 +++ adodb-xmlschema-1.0.1-cvs200403241400-mod/adodb-xmlschema.inc.php 2004-03-24 14:56:33.000000000 +0100 @@ -293,6 +293,14 @@ switch( $this->currentElement ) { // Table constraint case 'CONSTRAINT': + if( isset( $this->current_field ) ) { + $this->addFieldOpt( $this->current_field + , 'CONSTRAINT' + , $cdata ); + } else { + $this->addTableOpt( $cdata ); + } + break; // Table option case 'OPT': $this->addTableOpt( $cdata ); @@ -316,6 +324,10 @@ xml_set_object( $parser, $this->parent ); $this->destroy(); break; + case 'FIELD': + unset($this->current_field); + break; + } } @@ -379,7 +391,7 @@ // Set the field options if( isset( $opts ) ) { - $this->fields[$field_id]['OPTS'] = $opts; + $this->fields[$field_id]['OPTS'][] = $opts; } } @@ -486,7 +498,7 @@ if( is_array( $opt ) ) { $key = key( $opt ); $value = $opt[key( $opt )]; - $fldarray[$field_id][$key] = $value; + $fldarray[$field_id][$key] .= $value; // Option doesn't have arguments } else { $fldarray[$field_id][$opt] = $opt; @@ -1961,4 +1973,4 @@ echo '</pre>'; } } -?> \ Pas de fin de ligne à la fin du fichier. +?> Best regards, Marc ALBER |