Closed (fixed)
Project:
Weight
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
29 May 2013 at 00:36 UTC
Updated:
23 Jun 2013 at 03:40 UTC
Jump to comment: Most recent file
That could be a bit cleaner.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | weight-weight_get_settings-2006540-3.patch | 1.65 KB | jweowu |
| #2 | weight-weight_get_settings-2006540-2.patch | 1.63 KB | jweowu |
| #1 | weight-weight_get_settings-2006540-1.patch | 1.6 KB | jweowu |
Comments
Comment #1
jweowu commentedThe patch removes the repetition, and moves the name changes into the query so that we can use a simple
fetchAllAssoc('type').(That does also add 'type' into the settings when it wasn't there before, but that didn't look to be an issue.)
The leading comma formatting in the static query is just my preferred convention for multi-line selects (it means you can comment out lines without worrying about whether the final line has a trailing comma or not), but go ahead and change it to whatever you prefer.
Or you could use a dynamic query. I didn't do that because static queries are slightly faster, and field aliases become a bit more cumbersome (because you need
addField()), but in practice the difference is most likely negligible:Comment #2
jweowu commentedBug fix to handle an unknown $type argument.
Comment #3
jweowu commented...and it would help if I actually returned arrays (
PDO::FETCH_ASSOC) instead of objects :)Comment #4
davisbenI had to add backticks to the column aliases since range and default are reserved words, but everything else looks good. Committed to dev.
Comment #5
jweowu commentedAh, sorry about that. Perhaps this is why it was done the more long-winded way to begin with. In any case I'm afraid back-ticks are a MySQL-only convention, so we mustn't ever use them with Drupal. It might be sensible to switch to the db_select() approach, and let it take care of the quoting.
Comment #6
davisbenI reverted this back to it's previous version.
Comment #7
jweowu commentedFair enough.