Go to file
Dries Buytaert 29337ad8bb - Patch #13581 by Steven: Db_query() allows a variable amount of parameters so you can pass the query arguments in. There is however an alternative syntax: instead of passing the query arguments as function arguments, you can also pass a single array with the query arguments in it. For example the following two statements are equivalent:
db_query($query, $a, $b, $c);
db_query($query, array($a, $b, $c));

This usage is particularly interesting when the query is constructed dynamically, and the amount of arguments to pass varies. In that case we use the second method to avoid using call_user_func_array(). This behaviour is not documented explicitly, but it is used in several places.

However, db_query_range() and pager_query() do not support this syntax properly, which means there are several pieces of code which still revert to the ugly call_user_func_array() call.

This patch updates db_query_range() and pager_query() so they support the array-passing method. I also added documentation about this method to each of the db functions.

I also cleaned up the code for db_query (it was weird and hard to understand) and moved db_query() and db_queryd() from database.xxxxx.inc to database.inc: it was the same between both mysql and pgsql, as it doesn't do anything database specific. It just prefixes the tables and inserts the arguments. The actual db query is performed in _db_query(), which is still in database.xxxxx.inc.

Finally, I updated several places with the new syntax, and the code is a lot cleaner. For example:
- array_unshift($params, "SELECT u.* FROM {users} u WHERE $query u.status < 3");
- $params[] = 0;
- $params[] = 1;
- $result = call_user_func_array('db_query_range', $params);
+ $result = db_query_range("SELECT u.* FROM {users} u WHERE $query u.status < 3", $params, 0, 1);

and

- return call_user_func_array('db_query_range', array_merge(array($query), $args, array((int)$pager_from_array[$element], (int)$limit)));
+ return db_query_range($query, $args, (int)$pager_from_array[$element], (int)$limit);

I've tested it on mysql. I didn't alter the actual db behaviour, so pgsql should be okay too.

This patch is important because many people avoid the call_user_func_array() method and put data directly into the db query.  This is very, very bad because the database prefix will be applied to it, and strip out braces. It's also generally bad form as you have to call check_query() yourself.  With the new, documented syntax, there is no more excuse to put data directly in the query.
2004-11-29 13:13:29 +00:00
database - Changed aid from tinyint to int. 2004-11-28 13:35:11 +00:00
includes - Patch #13581 by Steven: Db_query() allows a variable amount of parameters so you can pass the query arguments in. There is however an alternative syntax: instead of passing the query arguments as function arguments, you can also pass a single array with the query arguments in it. For example the following two statements are equivalent: 2004-11-29 13:13:29 +00:00
misc - Removed hardcode font size from drupal.css as per #13095. 2004-11-21 08:34:57 +00:00
modules - Patch #13581 by Steven: Db_query() allows a variable amount of parameters so you can pass the query arguments in. There is however an alternative syntax: instead of passing the query arguments as function arguments, you can also pass a single array with the query arguments in it. For example the following two statements are equivalent: 2004-11-29 13:13:29 +00:00
scripts - Patch #6166 by Moshe: node preview should not display links. Push the links to the theme instead of the theme having to pull them in using node_link(). 2004-11-23 23:11:59 +00:00
sites/default - Patch #5942 by jhriggs and Adrian: 2004-11-24 22:44:01 +00:00
themes - Patch #13030 by killes: fixed invalid CSS code in bluemarine's stylesheet. 2004-11-27 11:23:42 +00:00
.htaccess - Changed FollowSymLinks to +FollowSymLinks. 2004-10-09 20:41:49 +00:00
CHANGELOG.txt - Refactored the statistics and watchdog module (views). The most important 2004-11-28 12:28:35 +00:00
INSTALL.txt - Patch #12606 by Gerhard: corrected the pattern of the download link in the installation instructions. 2004-11-27 11:28:55 +00:00
LICENSE.txt - Patch #9224 by JonBob: updated to latest version with new address and such. 2004-09-15 20:48:18 +00:00
MAINTAINERS.txt Adding myself as maintainer for the filter system. 2004-09-15 20:53:27 +00:00
cron.php - Refactored the statistics and watchdog module (views). The most important 2004-11-28 12:28:35 +00:00
favicon.ico (grmbl, figures stupid MS icon editing thingy would mess up the colors... fixed now) 2003-06-11 20:50:05 +00:00
index.php - Patch by JonBob: for consistency and readability, add brief descriptions of each source file inside the @file comment block at the head of the file. This helps with Doxygen indexing, and also allows neophytes to see what a file does immediately on opening the source, regardless of the organization of the hooks. 2004-08-21 06:42:38 +00:00
update.php - Fixed a warning. 2004-09-08 18:53:57 +00:00
xmlrpc.php - Patch by JonBob: for consistency and readability, add brief descriptions of each source file inside the @file comment block at the head of the file. This helps with Doxygen indexing, and also allows neophytes to see what a file does immediately on opening the source, regardless of the organization of the hooks. 2004-08-21 06:42:38 +00:00