Questions related to SQL queries, used in a module to retrieve information in a database table.
16
votes
4answers
5k views
Custom query in Views?
At some point I found the need to modify an SQL query generated by Views, in the end I overrode views_pre_execute and changed the query for that specific view.
This feels like an ugly hack to me and ...
11
votes
3answers
6k views
How do you make sortable tables with a pager with data from a custom table?
For Drupal 6 you could do something like this:
$header = array(
array('data' => t('Order id'), 'field' => 'order_id'),
...
array('data' => t('Transaction time'), 'field' => ...
9
votes
2answers
250 views
What is the most sustainable way to obtain aggregate information on fields?
EntityFieldQuery is not intended to be used to run aggregate functions (SUM, AVG, etc.) on field data because it is SQL-agnostic. That said, such operations legitimately need to be run from time to ...
8
votes
4answers
7k views
“OR” condition in db_select
I am studying the new database layer, and I am glad it is changed to an OOP layer. I need to implement a query with db_select(). I found I can add a WHERE statement with $query->condition(), but by ...
7
votes
3answers
3k views
What does vid mean
I have designed a view and I see this query in the preview section:
SELECT node.nid AS nid,
node_data_field_crm_history_brokerid.field_crm_history_brokerid_value AS ...
7
votes
3answers
560 views
Drupal as (powerful) relational database
I’d like to make a Drupalsite, providing a platform for people around the world who are working on the same research topic to collaborate and communicate. (I’m sure Drupal is therefore an excellent ...
7
votes
2answers
1k views
Views3 and subqueries?
I've got a view which generates a query that does multiple joins. This produces a cartesian join, and I need to "convert" the joins to subqueries.
I've looked through documentation, Google search ...
6
votes
2answers
4k views
Print the query which is built using db_select()
I want to print the query which is built using db_select() in a programmatical way. Is there any API function provided by Drupal Abstraction Layer?
It is similar to query output in Views, but I want ...
6
votes
5answers
3k views
Using OR with EntityFieldQuery
I have never had the need to do this before today, but it doesn't seem like you can make OR queries with EntityFieldQuery, since db_or is used for select queries.
An example would get to all entities ...
6
votes
1answer
4k views
Trying to get COUNT(*) from custom content type with EntityFieldQuery
How can I retrieve the 'count(*)' from a query in drupal 7? The query needs to include a custom content type and a custom field.
Notes
Custom Content Type: employees
Custom Field Name: ...
6
votes
1answer
794 views
Debugging custom database queries
Is there a convenient way to ask a particular database object to print its query?
Every now and then, I write a DBTNG db_op() in a module, and far to often, I don't quite get the queries right.
I ...
6
votes
1answer
1k views
Difference between field_data and field_revision tables?
I have a lot of custom functions; I just want to make sure I'm doing this right.
If I want the most recent version—the live version—of a node, I go to the field_data_field_xyz table, right?
My ...
5
votes
6answers
2k views
Excluding empty(Null) fields when using EntityFieldQuery query condition
Is it possible to select all of the entities who's xyz field is empty?
I tried soemthing like this:
->fieldCondition('field_name', 'value', NULL, 'IS NOT NULL');
However, this doesn't seem to ...
5
votes
1answer
389 views
How to set new AUTO_INCREMENT value in D7
I have the following statement in my module code:
db_query("ALTER TABLE {tripletex_invoice} AUTO_INCREMENT = :number", array(':number' => $start_value));
During Simpletes (D7) i get the ...
5
votes
3answers
3k views
How to define and use an external database connection in a custom module
I'm developing a module that will rely heavily on external database queries. Is there a best practice for defining and using an external database connection throughout a module?
This page tells me ...