Needs work
Project:
Examples for Developers
Version:
4.0.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
18 Feb 2010 at 20:40 UTC
Updated:
2 Oct 2025 at 09:40 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
rfayIt should also have:
A transaction
A delete with more than one condition
An update with more than one condition
A condition based on subquery (from @tanoshimi)
A join
A static query
range(): successor of db_query_range()
ordering
random ordering
grouping
Comment #2
tanoshimi commentedA condition based on a subquery
Comment #3
gregglesA start ;)
I probably won't do many more but needed to learn to do this and found it missing in example.module
Comment #4
rfayA good start :-)
Comment #5
rfayCommitted #3, thanks.
Comment #6
rfayComment #7
rfayWhat I'd like to see in that module is a whole "recipe" section with "all" the things that are missing. Lots of practical things people need.
It wouldn't bother me if there were no UI at all, but if we can get a testable, full-quality set of recipes in here I'd be really happy.
Good comments
Real running queries
Explanations of what the related SQL would be
Tests for each
Comment #8
tr commentedSetting version.
Comment #9
mile23I'd actually love to see simpler examples to copy and paste. :-)
Comment #10
rfayOK, so it just needs lots more examples :-)
Comment #11
mile23Mentioning this one #1028168: Create a page to show results from database including a pager. in case someone gets excited. :-)
Comment #12
mile23Comment #13
minakshiPh commentedI have patched filter form for the listing page; a new easy to learn stuff in this module.
Kindly review.
Thanks!
Comment #14
minakshiPh commentedAlso review the new patch containing "Ordered List" example.
Thanks!
Comment #16
aburrows commentedRemove this linebreak
Doxygen should be /**
Comment #17
legolasboThis is not an ordered list, but a table.
Comment #18
minakshiPh commentedThis query will create an ordered list.
Comment #19
minakshiPh commentedcorrected the patch as mentioned in #16 and attached the same.
Kindly review.
Thanks!
Comment #20
minakshiPh commentedComment #21
legolasboI think the example would be better if it is called "Ordering results" or something similar as that is what the example is about.
Extraneous whitespace after
database..It seems to me that this string should be on one line in one t() call.
I know the internet is littered with examples using TRUE as an access callback. Using TRUE as an access callback is however dangerous in production code and has been known to cause security issues. It should therefore be prevented in any code you write to ensure you never accidentally leave access to menu items unchecked. Try to always use a genuine access callback (even if it's just checking if a user has access to the admin pages or permission to view content for example).
This comment exceeds 80 characters.
This comment exceeds 80 characters.
This should be declared closer to where it is used. Besides that, this menu callback should actually return a render array instead of a string.
If you extract this section into it's own method named something like dbtng_example_execute_ordered_select_query, then the dev reading the example would immediately know where to look for the actual Database API example.
I'm not sure about the schema of the dbtng_example table, but it seems to me like you are selecting all fields in the table.
If that is the intention, you can just do the following:
Or even better
That way you can direct the reader's focus on the
$select->orderBy('ex.name', 'ASC')call.This comment exceeds 80 characters.
You could also extract this into a function dbtng_example_render_resultset_as_table to make sure that the reader does not have to filter out information that is not relevant to the database API.
Comment #22
minakshiPh commented@legolasbo: The mentioned modifications have been made in the new patch and also attached the interdiff.
Kindly review.
Thanks!
Comment #23
minakshiPh commentedComment #24
legolasbo'Ordering' should be 'ordering'
This is too specific. 'access content' or 'access administration pages' will do.
This can be removed if you use one of the permissions mentioned above
/s/retrives/retrieves
/s/in an ascending/in ascending
Maybe explain that the code below will result in the following query
Excess blank comment line
I think you misunderstood me here. I meant something as follows:
The foreach should actually be inside of the dbtng_example_render_resultset_as_table() function
Comment #25
minakshiPh commented@legolasbo: Modified the code as mentioned and also attached the interdiff.
Kindly review.
Thanks!
Comment #26
legolasboReview of the interdiff:
Checking wether or not there is something to render should be the task of dbtng_example_render_resultset_as_table. The entire method could be as simple as:
Pretty self-descriptive no? You could even change the function's docblock to "Menu callback."
This comment is redundant.
return $dbtng_example_result;almost literally states 'return the result'Review of the entire patch (without previous comments from the interdiff)
If you render the to html here, the output can't be changed anymore. If you however return a render array it can still be altered by the theme layer if required.
i.e.:
The method can then be renamed to something like 'dbtng_example_convert_resultset_to_table_render_array()' which would make it self-describing.
Comment #27
minakshiPh commentedCorrections are made in the updated patch with interdiff.
Kindly review.
Thanks!
Comment #28
legolasbo"Generate a list of database records ordered by the 'name' column in ascending order." reads better I think.
Menu callback demonstrating how to retrieve ordered results from the database.
This should live in a method called
dbtng_example_convert_resultset_to_table_rows()and be called fromdbtng_example_convert_resultset_to_table_render_array()Comment #29
legolasboThis is also missing tests that prove that everything works as expected.
Comment #30
minakshiPh commentedCorrections are made as mentioned in #28
Kindly review.
Thanks!
Comment #31
legolasboThis docblock is missing an @return annotation.
this docblock is missing a @return annotation.
Maybe you should add a comment explaining the 'ex'. Or even better replace all 'ex' with $tableAlias.
Maybe this comment should also explain what 'ex' and 'name' are exactly.
I'm not sure what you mean this comment.
An empty line above the return statement more clearly separates the 2 logical steps querying and returning data.
This function does not render anything, it just converts the resultset into table rows.
'dbtng_example_convert_resultset_into_table_rows'
Besides that, the docblock is missing @param and @return annotations.
Doesn't this result in a pass by reference warning?
You can inline this variable.
Comment #32
minakshiPh commentedAdded annotations as mentioned in #31
Kindly review.
Thanks!
Comment #33
legolasbothis doesn't improve the example. Something like the pseudocode below explains what is going on without the need for comments.
/s/converts/convert
This comment is incorrect. the function converts a resultset into a render array.
Comment #34
minakshiPh commentedcorrections are made as mentioned in #33.
Kindly review.
Thanks!
Comment #39
manojbisht_drupal commentedHi,
Attached is the patch for delete based on multiple condition.
Comment #42
manojbisht_drupal commentedComment #44
rfay@manojbisht_drupal - Your patch is not in proper git format, so doesn't apply. Full instructions are at https://www.drupal.org/node/707484
Comment #46
manojbisht_drupal commentedHi rFay,
Please find the revised patch attached with the instructions on the link.
Thanks,
Manoj Bisht
Comment #47
mile23Rescoping.
This is all good stuff. Moving to 8.x-1.x because that's current.
File an issue per item, and when it's in, we can backport to 7.x-1.x as needed in those child issues.
Comment #48
mile23Comment #49
mile23Comment #50
mile23Comment #51
valthebaldMoving to new examples meta
Comment #52
jungleLet's move this to 4.0.x, which is for ^9.4 || ^10
Comment #53
avpaderno