Topics related to the database API implemented by Drupal.

learn more… | top users | synonyms (3)

0
votes
1answer
11 views

How do I break my query result into smaller chunks

Background I have a query that returns 140000+ results and I need to perform more calculations on the result before displaying them to the user. This has caused a huge wait time (left it to run for ...
0
votes
4answers
39 views

Why is my Query not returning a result

Background I have a large table with lots of values and want to check if any of the names are repeating and only display those results. I have built a view and cannot get the SQL query to return the ...
1
vote
1answer
15 views

insert json into db

I'm trying to store some JSON data as string into database, but db_query change my JSON {} to table prefix. So I have wrong JSON in DB as result. How can I prevent such behavior?
3
votes
1answer
44 views

How to check in a rules condition if an image field has value?

Is there any way to check if a field has no value (image field) after saving the content in Rules? I tried Data Value is Empty, but it doesn't work! Output of the rules: { ...
3
votes
1answer
28 views

Using NOT LIKE in db condition?

I don't see an example when looking at the api. I'm setting up a query and would like to use NOT LIKE as opposed to STARTS since START does not seem to be supported. Is this possible?
0
votes
1answer
23 views

How to add Replace (mysql) function in view query condition field

I am using EntityReference Autocomplete with filter by entity reference view. And I want to ignore space in search filed. For example, column username in DB has value first name it should popup when ...
0
votes
1answer
23 views

Add tag to db_insert?

I want to do some debugging with a db_insert query. I tried to use the addTag() method, but I got an error: $query = db_insert('nodes') ->addTag('my query'); PHP Fatal error: Call to undefined ...
0
votes
0answers
45 views

Advanced conditions for db_select or db_query [on hold]

I am trying to replicate a set of conditions from a normal MySQL query. The original query is as follows: NOTICE This is an old table which contains a terribly named date column called "date"! ...
0
votes
1answer
16 views

Drilling down into an Entity Reference Field in Rules Actions

I have the following setup where I have 2 content types called BRIEFS and IDEAS. On BRIEFS, I have a list of users selected in a field called brief_recipients which is a user reference field. IDEAS ...
0
votes
1answer
15 views

How to set an alias to a fields on a db_select?

Like it said on the title, as we use alias to fields with a static query, i want to do same thing with a dynamic query example : with static select : $sql = db_query ("SELECT my_super_long_field as ...
0
votes
1answer
35 views

Drupal insert query with uploaded CSV file

array 0 => array 'id' => float 1110 'description' => string 'Culture de céréales (à l'exception du riz), de légumineuses et de graines oléagineuses' (length=86) ...
-1
votes
0answers
24 views

How to order MySQL result based on field values in db_select?

How to get result's order based on field values in db_select, Suppose I have to get all users but I want a result in this way that all top result of the user belongs to the specific role. Note: I ...
1
vote
1answer
31 views

db_select query advice

I have two content types: development and house. A development has many houses. Each house has a house_type field I'm trying to perform a db_select query that allows me to search all developments ...
1
vote
1answer
18 views

How to put multiple fields in an index operation on a GET HTTP request with services?

I'm working with the module "services" everything's ok with a get request, note that i've create my own custom resource with CRUD operations, the "retrieve","update" are ok but the problem is with the ...
0
votes
1answer
22 views

How to store additional_settings value when adding a node?

Since storing node type additional_settings is done without the need for calling any other hooks, I quite have a problem to store a simple string from additional_settings on node add form. After the ...
0
votes
1answer
13 views

Pager extention not working in dynamic database query

I am trying to create a page which shows all the nodes created by the currently logged in user. To do this I am using a dynamic query to fetch the relevant nodes. However, for some reason the pager ...
3
votes
4answers
262 views

Get a message if insert into table works

My db_insert (and another db_merge) work great, I can populate my table well (also using a post http) now i want to get a message : success => when insert is ok fail => if not (if duplicated ...
0
votes
1answer
15 views

How do I set a stored procedure?

How can I process following query structure in drupal 7. set @num := 0, @termid := 0; SELECT * FROM (SELECT tid,nid,created, @num:=IF(@termid = tid, @num + 1, 1) AS row_number, ...
0
votes
1answer
29 views

Using SQL to output link to a node

Does anyone know - using SQL only - how to output the link to a drupal node? If I was using PHP I think it would be something like this: print l($node->title, 'node/' . $node->nid); But I'm ...
0
votes
0answers
33 views

How to use fields in node's comment in a node's Computed field?

I'm new in php and I'm stuck with this. First problem, In a computed field of a node, I would like to use fields that are in the comments of this node. I don't know how to get access to comment's ...
0
votes
1answer
12 views

How to get each db result value count

How to get values count in db_select My query is: $last_item = '2015-07-19'; $query = db_select('field_data_appointment_date','ap'); $query->join('field_data_appointment_slot','aps','aps.entity_id ...
1
vote
1answer
29 views

How can I combine a product attribute with a subset of another one in Drupal Commerce?

Assume I have 2 product attributes (using the Drupal Commerce module): Background color (white, black, green, blue, yellow). Surface (glossy or matte). And assume that surface "glossy" can be only ...
0
votes
0answers
33 views

D7 db_update — how do I get the unique ID (primary key)

I am working on an edit/update function in my module. I am able to populate the form with the correct data based on the unique ID but am unable to pass this to my submit_handler function. Submit in ...
0
votes
0answers
12 views

What is the first parameter of this db_query call for?

I've inherited some code. It works, but I'm wondering what the "5" does in this db_query statement. $result = db_query(5, "SELECT * FROM {foo} WHERE bar = '%d'", $bar_val);
0
votes
1answer
24 views

Printing fields from View using query

The query below is taken from the related View. How can I get the field value for 'field_data_field_news_link', 'field_data_field_news_source', and field_data_field_news_date' for each row (news ...
1
vote
1answer
25 views

How can I make db_query SELECT LIKE case insensitive?

I'm querying for an email address where I can't force the case of the search term or the data in the table. It's an API thing. How can I convert this query to be case insensitive? $results = ...
0
votes
2answers
65 views

db_query and db_select

I have static query (db_query works great) but for some reason, I have to put a condition to the query result I don't want to re-write the same db_query with "where", I'm looking for a way to write ...
0
votes
1answer
47 views

db_select sub query

I need to use sub query on db_select but, as you can see the sql, I think the first select should be like db_select('tabe1','tab') but this table is a "virtual" table I've to create temporary only for ...
1
vote
1answer
30 views

How do I add a COALESCE to a db_select?

I want to achieve the following query using db_select(): SELECT Column1, Column2, COALESCE(Column1, Column2) AS Column3 FROM TEST_ATTRIBUTES How do I add the coalesced column to the ...
1
vote
2answers
36 views

DB Query exclude duplicates, returning only the newest

I need to alter the query below to only return one row for each unique 'name'. The row returned should be the most recent based on the contents of 'date'. 'date' is an integer. $query = ...
2
votes
1answer
35 views

Error when trying to extend a db_select query

I'm trying to add a field to my query by using addField(). However, whenever I add this to the query I get a whitescreen and an apache error message on the line after. Any help in resolving this would ...
0
votes
1answer
10 views

How do I reset a user's name using Drush in Drupal 7?

To change a password I would use: drush user-password USERNAME --password="SOMEPASSWORD" Is there a similar way to change a user's name using Drush from the command line?
0
votes
1answer
29 views

Get the CCK field value using dbquery

I have a content type called user registration under this one cck field called regid. i would like to fetch the entered values of this particular field through programmatically probably by using ...
1
vote
2answers
31 views

Use Firebird Database to Lookup Data

I have installed my drupal in postgres. I've been using multiple databases in my customized module. Below is my settings.php: $databases = array ( 'default' => array ( ...
0
votes
2answers
32 views

Add a “with +10 minutes” condition using db_select()

I'm trying to add a condition "within 10 minutes" using db_select(). This is my code. $query = db_select('table1', 'c'); $query->innerJoin('table2', 'i', 'i.nid = c.nid'); $query->fields('c', ...
0
votes
1answer
19 views

Dynamic query returns multiple reuslts

I have a quite simple query : (find all nodes, fetch 3 fields from the node table and join the results with some tax.terms) $query = db_select ( 'node', 'n' ); $query->fields ( 'n', array( ...
0
votes
0answers
37 views

How do I limit the number of results from a search query with hook_query_alter?

I've followed the Drupal 7 documentation for hook_query_alter() in order to limit the number of total search results when searching for nodes or users to an arbitrary number. However, with the ...
0
votes
1answer
47 views

Fetch field values in drupal 8

How to query all the values of a particular field. I used Drupal\Core\Database\Connection object to fetch the values as below: $connection = \Drupal::database(); $result = ...
0
votes
1answer
18 views

How to use db_select and apply a condition for another table's data?

I know this is probably the dumbest question ever but I'm just not getting warm with SQL. I am writing this function which loads all users that have a role assigned: function ...
0
votes
1answer
24 views

Is this SQL query even possible in Drupal 7?

I'm trying to find a way to run this query in a custom drush command to dump chunks of data from the DB into CVS files. The query works fine directly in the terminal but I was wondering how would ...
0
votes
1answer
47 views

My first module: db_select question

I'm working on my first module, in this module I want to show a pager to two similar nodes. (Yes I know there are modules for this but it's more complex then the above but I kept it simple to make my ...
0
votes
0answers
30 views

Use OrderBy in Query

I want to retrieve only the latest course of the student which is BSCS in my semstudent table, so I sorted it out by using orderBY sy and sem. Below is my code: $query = db_select('student', ...
0
votes
0answers
32 views

Content loss in Drupal related with field_attach_update

Drupal field_attach_update seems to be the cause of a content loss in my application. This function is used to save a node field instead of the whole node but if it is not used properly it can ...
1
vote
1answer
52 views

How to add a correlated subquery expression in hook_views_query_alter?

In hook_views_query_alter, how to add a condition which is a correlated subquery in which the value of the condition is an expression? Given a view the produces this query: SELECT node.nid, ...
1
vote
2answers
44 views

db_query or db_select for getting content type fields

Originally I was doing something along the lines of $query = "SELECT {}" and then $result = db_query($query). This method works fine for most of my queries until I needed to get the field values and ...
0
votes
1answer
52 views

“the website encountered an unexpected error.Please try again later” after db_update

Drupal responses "the website encountered an unexpected error.Please try again later" after running db_update statement in my custom module. I always do this without any error. Any suggestion pls! ...
0
votes
1answer
43 views

How to select fields from content type

What is the best way to do a db query for fields in a content type? I need to get specific fields from a content type, but only where the 'featured' field value is 1. <?php $query = new ...
0
votes
0answers
28 views

Fetch result of query twice

I faced with problem while fetching query results, my code: $result = $query->execute(); $array1 = $result->fetchAllKeyed(1, 0); $array2 = $result->fetchAllKeyed(2, 0); But the $array2 is ...
0
votes
0answers
40 views

Search on field collection with EntityFieldQuery

I have a node resource with fields name files (field collection) And field collection with fields title path How can I search all node have file title = 'example' How can ...
0
votes
0answers
8 views

domain taxonomy exposed on page load uc_catalog

On my homepage, we have displayed catalog block using uc_catalog module. Also, we have domain_taxonomy module installed in our Drupal 6 setup and it seems to be working fine when we are going to ...