[wp-trac] [WordPress Trac] #22196: add $wpdb->upsert function
WordPress Trac
noreply at wordpress.org
Mon Jul 24 00:20:06 UTC 2017
#22196: add $wpdb->upsert function
-------------------------------------------------+-------------------------
Reporter: thomask | Owner:
Type: enhancement | Status: closed
Priority: normal | Milestone: Future
Component: Database | Release
Severity: normal | Version: 3.4.2
Keywords: has-patch needs-testing needs- | Resolution: maybelater
refresh needs-unit-tests | Focuses:
-------------------------------------------------+-------------------------
Comment (by pento):
I think we're stuck between a rock and a hard place, here.
On the one hand, MySQL's upsert behaviour is unpredictable under some
circumstances, so making it easier to use seems unwise.
On the other hand, having WPDB's upsert behave differently to MySQL seems
like a recipe for people running into edge cases that they didn't expect.
There'd also need to be a tradeoff between doing a complete set of pre-
flight checks on upsert queries (for example, running a SELECT query
first, based on any columns being updated that are part of unique keys)
while also maintaining compatibility with non-transactional DB engines,
like MyISAM.
I don't really have a good answer here, unfortunately. I think the best
method for now is to require upsert queries to be written manually -
people who are aware of the query can use it, but we're not encouraging
wider use of something that is often not entirely understood.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/22196#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list