Re: extending the mdb schema format
| From: | Lukas Smith | Date: | Tue, 14 Jun 2005 09:48:45 +0000 |
| Subject: | Re: extending the mdb schema format | ||
| References: | 1 2 3 4 5 6 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-38102@lists.php.net to get a copy of this message | ||
Hi,
Helgi was kind enough to get the ball rolling and added autoincrement and primary key support to MDB2 CVS. I am not quite happy with the result API-wise and right now only mysql is supported but it gives us something more concret to ponder on.
Anyways in this first step the path was taken to add the autoincrement tag inside the sequence tag and the logic inside the createSequence() method. What he also did was add the autoincrement handling inside the getIntegerDeclaration() method. So actually the createSequence() method would then defer to the alterTable() method. Thinking about it I think its probably better to go with supporting it inside createTable()/alterTable() directly. I will investigate the syntax a bit more, however here are some findings:
- mysql, sqlite, fbsql and mssql all support autoincrement on integer fields only
- mysql, sqlite and fbsql expect a single column primary key on the column
- fbsql automatically adds autoincrement to any integer single column primary key field
- only mssql allows multiple "autoincrement" columns per table
- mysql, sqlite and mssql expect the definition of the autoincrement to be made within the column definition (and not at the end of the table definition)
- only sqlite doesnt seem to support explicity setting of starting values, however none of them support a starting value inside a create table statement
To conclude:
I think your original suggestion of placing the autoincrement tag inside the table definition makes the most sense. I am not sure if it makes sense to even stick it inside the primary key definition, since appearently all but mssql require a primary key on the field anyways. The tricky bit in generally is that you really need to do the autoincrement definition inside the column declaration, yet you are likely to also need a primary key, so there is the danger of defining a primary key twice. Beyond that I would say the possible values for the autoincrement tag would be a boolean or a string.
True meaning: add autoincrement only if supported (and maybe give a warning when not).
False meaning: dont autoincrement
String: create autoincrement (or sequence if autoincrement is not supported) - this also means that if the autoincrement was successfully set, the sequence would be skipped
Optionally I could also see allowing an integer value to specify a starting value. 0 would still be false and 1 would equate to true (and the default starting value is 1 anyways) and any integer higher than 1 would be the wanted starting value.
regards,
Lukas