j4mie / paris

A lightweight Active Record implementation for PHP5, built on top of Idiorm.
http://j4mie.github.com/idiormandparis/
996 stars 131 forks source link

INSERT IGNORE / ON DUPLICATE KEY #26

Closed brdrck closed 11 years ago

brdrck commented 12 years ago

Not sure the best way to do:

http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html

tag commented 11 years ago

The trouble is, implementing this requires different SQL-style language depending on the database back end, as this effect is typically managed with custom extensions to the SQL standard by db engines. MySQL is different from sqLite, which are both different from [insert db provider here]. See, e.g., this Stack Overflow question, which mentions a solution to a similar issue (see also, here, which suggests the REPLACE INTO syntax which works with MySQL and sqLite, but not necessarily other db engines; also useful is the Wikipedia explanation of MERGE syntax).

My initial suggestion would be to leave that sort of complex behavior to Idiorm's raw queries, in keeping with the 80%/20% philosophy of the original design of Paris/Idiorm.

However, if this is to be implemented in Paris/Idiorm, the documentation should be changed to reflect specific support for only certain providers, and the test suite would need to be expanded to account for differences in db engines.

treffynnon commented 11 years ago

In the upcoming release of Idiorm an ORM::raw_execute() method has been added. It is my suggestion that queries like these are treated as complex queries and make use of this method instead of having special handling per DB vendor.