
brion at wikimedia
May 12, 2008, 9:33 AM
Post #1 of 4
(154 views)
Permalink
|
|
Re: [MediaWiki-CVS] SVN: [34608] trunk/phase3/maintenance/mssql/README
|
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Simetrical wrote: > On Sat, May 10, 2008 at 10:20 PM, <nad[at]svn.wikimedia.org> wrote: >> In MySQL the standard way of inserting data into rows exhibiting AUTOINCREMENT columns is simply to use a ''NULL'' value which will be ignored. In MSSQL however assigning a ''NULL'' to an ''IDENTITY'' column is not allowed, instead the best way is not to include those items in the list of columns to be updated at all. >> >> To get round this in the MediaWiki MSSQL layer, I've modified the insert wrapper in the ''DatabaseMssql'' class to check if the primary key is used in the insert and remove it if so. It checks this by assuming that the primary key will be of the same name as the table but with ''_id'' on the end, and that it will the first item in the list of columns to update. > > It would be best to raise some kind of warning when this condition > occurs, preferably in the MySQL code path too, so that developers > using MySQL with notices enabled can notice and fix it. Just not > specifying the column to begin with works fine with MySQL too, so it > should be used if it's more compatible. The complication here is that for PostgreSQL, we *must* insert a value, since it doesn't have autoincrement columns. This is why we jump through hoops to use $dbw->nextSequenceValue() stuff... Rather than making assumptions about field names (which sounds like baaaad mojo that can break in many exciting ways), it may be more reliable to use a special value here. Using a type-safe value (say, returning an object of a particular class from nextSequenceValue()) could allow the database class to drop the column from the query in a safe way. >> MySQL implicitly casts NULL assignments to NOT NULL columns to an empty string or zero value accordingly, but MSSQL raises an error instead. This is a big problem within the MediaWiki environment because the code relies heavily on this implicit NULL casting. I've tried to get round the problem by replacing NULL's with empty strings from update and insert queries, and MSSQL is happy to cast the empty string to a numeric zero if necessary. > > How does PostgreSQL handle this? If you know what type the column is, > you can cast it in the application logic. Again, it would seem better > to implement this checking in the cross-database code and raise > warnings if it comes up so it can be fixed on a case-by-case basis. > This doesn't work with MySQL strict mode either, which is the default > under some circumstances last I heard. This is simply a case where if it's going on, it's a bug in the code. Don't "work around" it in the database class, just fix it! :) - -- brion -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkgocWEACgkQwRnhpk1wk45LOQCg3BK1m6DamiZHFQq9CsXOklIS CYsAniSbC90ZEyxb7uAlt8yI0xc/eNVd =y0ND -----END PGP SIGNATURE----- _______________________________________________ Wikitech-l mailing list Wikitech-l[at]lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
|