Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
database system
Priority:
Minor
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
19 Feb 2010 at 16:19 UTC
Updated:
17 Mar 2010 at 20:00 UTC
Jump to comment: Most recent file
Comments
Comment #1
Crell commentedSubscribe. I don't know what this code is doing either, but it doesn't look good. (But then, I've always hated drupal_write_record(), especially now that we have DBTNG.)
Comment #2
mcarbone commentedI think this is just a case of poor variable naming and/or a confusing control structure. Below the bit you quote above, there seems to be awareness that that variable is over-loaded with the result of a possible db_insert or db_update:
So I don't think this is a bug, but it's definitely worth fixing. Since drupal_write_record is called 26 times at the moment, I'd be suprised if something was actually broken and not being found in other tests.
I wonder, however: should this function be rewritten to use db_merge?
Comment #3
mcarbone commentedJust found the thread where this bit of code was added, and it also happens to show that moshe deliberately decided not to use db_merge for this, though not with any explanation: #299088: [DBTNG]: simplify drupal_write_record() with db_insert() and db_update()
Comment #4
Crell commentedCould it perhaps be related to #715108: Make Merge queries more consistent and robust?
Comment #5
carlos8f commentedYeah, I think drupal_write_record() was sloppily ported to DBTNG, and that caused #626790: drupal_write_record returns FALSE for valid update queries due to the return value confusion. The code currently works, but could be cleaned up a bit. Namely, don't call the variable "last insert id" if it's an update :)
Comment #6
Crell commentedWe should go a step farther and just remove that abomination of a function in Drupal 8. :-) For now, though, cleaning it up to at least read clearer and be better documented internally would be good.
Comment #7
jhodgdonComment #8
jhodgdonHere's a patch. I couldn't resist clarifying the function header doc a bit too.
Comment #9
Crell commentedLooks good to me. Really it's just a doc change, even though one of those docs is a variable name. :-)
Comment #10
dries commented#8: 719468.patch queued for re-testing.
Comment #11
dries commentedAsked for a re-test because of another change that was committed to drupal_write_record() in #353918: drupal_write_record writes empty string instead of empty serialized array. Haven't reviewed this patch yet.
Comment #12
Crell commentedLooks like it's still passing.
Comment #13
dries commentedGreat. Committed to CVS HEAD.