Re: extending the mdb schema format
| From: | Sérgio Carvalho | Date: | Tue, 14 Jun 2005 16:07:14 +0000 |
| Subject: | Re: extending the mdb schema format | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-38116@lists.php.net to get a copy of this message | ||
Lukas Smith wrote:
> 1) auto increment
>
> Currently you can only define sequences as follows:
>
> <sequence>
> <name>foo</name>
> <start>23</start>
> <on>
> <table>foo</table>
> <field>bar</field>
> </on>
> </sequence>
>
> The <start> and <on> tags are optional. The <on> tag basically lets you
> sync the sequence against a certain field in a table. Now I was
> pondering extending the <on> tag to also allow for an optional
> "<autoincrement>1</autoincrement>". This format is in the sprit of the
> rest of the tags in that it doesnt use atributes.
>
> Now the problem is that we may need a separate syntax for "I only want
> autoincrement!" and "Use autoincrement if available." as MDB2 supports a
> nice mode where either auto increment or sequences are used. I dont
> really like something like "<autoincrement>force</autoincrement>" for
> this case.
>
> I could also add something like this
>
> <autoincrement>
> <table>foo</table>
> <field>bar</field>
> <start>23</start>
> <force>1</force>
> </autoincrement>
>
> This is also not very nice and seriously screws with how the current
> code works and the current DTD is structured.
Why not go with the dual approach? An autoincrement is not an entity in
the RDBMS, like sequences are. It is a behaviour of a field, so define
it in the field:
<table>
<name>foo</name>
<declaration>
<field>
<name>bar</name>
<type>integer</type>
<default>
<autoincrement>
<start>1</start>
<increment>1</increment>
</autoincrement>
</default>
</field>
</declaration>
</table>
This way, if a RDBMS does not have autoincrement fields, it may behave
like Postgresql: create a sequence behind the scenes, and assign
sequence::next_val to the field's default value.