Questions related to SQL queries, used in a module to retrieve information in a database table.

learn more… | top users | synonyms (1)

0
votes
2answers
13 views

querying content type via drupal database API

Using Drupal 7 I have created a content type called 'fauna'. I simply want to filter by an attribute (eg: 'area') using Drupal database API. As far as I have seen around, most of people follow ...
0
votes
0answers
19 views

Get a node and fields with SQL?

Is there any way in Drupal 7 to load a node and its fields without the Entity Query API? I need to get a field value based on another field in an external script, and don't want to bootstrap Drupal.
0
votes
0answers
16 views

Using addExpression and GROUP_CONCAT gives null result

This has been bothering me for a few days now. Using Migrate module, I am using a GROUP_CONCAT in an expression and the prepareRow always has a null value for the expression. For example, heres how ...
2
votes
3answers
100 views

How to db_select DISTINCT on a particular field in Drupal 7?

I understand that you can specify ->distinct() on the db_select statement so that it only returns distinct values when looking at ALL fields. But what I want is to return distinct values by only ...
1
vote
3answers
101 views

Migrate: What's the difference between prepare() and prepareRow()?

Using the Migrate module: I understand that prepareRow() runs a filter on the row and should return TRUE or FALSE based on some conditions, which allows a row to be migrated or not, but could someone ...
0
votes
0answers
14 views

Migrate using MigrateSourceSQL and MigrateDestinationTable returns incorrect rows

I'm using MigrateSourceSQL source and MigrateDestinationTable for the destination . In the migrate UI where you have the Query ; this query returns the correct amount of rows I wish. Also in the ...
0
votes
1answer
25 views

Help me with my page, when open this page shows me this:

PDOException: SQLSTATE[HY000]: General error: 145 Table './mapibrasil/watchdog' is marked as crashed and should be repaired: INSERT INTO {watchdog} (uid, type, message, variables, severity, link, ...
0
votes
1answer
42 views

How to deal with duplicate table name with db_select left join

Basically I have a db_select that has two left joins. And will be calling up two table fields with the same name. The fields have different data though, so I need to be able to have access to both ...
0
votes
0answers
29 views

Intermittent slow Views query

The Drupal 7 site we've produced is intermittently experiencing slowdown on page load. Using Devel I've pinpointed the slow down to queries generated by two similar Views and the SQL generated. The ...
0
votes
2answers
47 views

What is the proper way to drop database references for an uninstalled drupal module?

I've uninstalled the Commerce Coupon 7.x-2.0-beta3 through the admin ui and removed the corresponding folder from the sites/all/modules directory. Now when I install the previous version of Commerce ...
0
votes
3answers
52 views

Customizing recent blog posts block

I'm including the recent blog posts block in the sidebar of my Drupal site which pulls out the 10 most recent posts in a list with the title of the post linking to the post itself. I'd like to pull ...
0
votes
0answers
47 views

What am I doing wrong? Trying to join two fields from two tables, Drupal 7

Based on this tutorial I created a module to be able to find first name or lastname from user fields. Everything is working fine, but I notice that the search only looks either for name and last name ...
0
votes
0answers
15 views

Drupal Product Display List view- selecting image from variation with lowest delta

I am currently trying to set up a catalog listing for commerce product display nodes. Each display has several selectable product variations referenced. Using a T-Shirt example, think all shirts ...
1
vote
1answer
49 views

Find users who have not uploaded certain contents in last 30 days [closed]

I need to find users who have not uploaded certain contents in last 30 days. I have tried this query it is not working. Can anyone help me? select uid, max(created) as max_created from node where ...
1
vote
2answers
49 views

How to add UNION with pagination in drupal 7 query?

My query is like : $query_club = db_select('club_members','cm'); $query_club->fields('cm',array('first_name','last_name')); $query_club->group_by('cm.uid'); $query_network = ...
0
votes
1answer
18 views

How to add multiple havingCondition with OR operator?

I want to add havingCondition with OR operator In normal sql query my having conditions are like: group by n.nid having comment_count!=0 OR viewed_count!=0 OR likes_count!=0; With adding multiple ...
0
votes
1answer
9 views

How to get the values ​​of an array in the options list (hook_rules_condition_info ()) instead of array index?

'example_condition_user' => array( 'label' => t('User Condition'), 'arguments' => array( ), 'parameter' => array( 'username' => array( 'type' => 'text', ...
0
votes
0answers
20 views

node_save throwing PDOException: “Duplicate entry '' for key 'uri'”

I'm working on a script to update some content (no file management) - but when I call node_save($node), it throws this error: [errorInfo] => Array ( [0] => 23000 [1] => ...
2
votes
1answer
28 views

How to do a db api join on “has no value”?

I've got two tables, Foo and Bar. Foo and Bar can be joined by matching Foo's "nid" column to Bar's "col" column. In use, some rows in Foo will have a corresponding entry in Bar, but some won't. I ...
1
vote
1answer
46 views

How to use LIKE condition in db_select() query?

How do you build up a LIKE condition in a db_select() query? I know how to do this with a db_query() API call, but is there a special syntax / method for doing this with db_select()?
0
votes
1answer
16 views

What is the SQL query to filter og Admin Accounts?

I currently have the following SQL statement that gives me a list of all of my og nodes and their associated owner. I am having trouble nesting my JOIN statements to add the name of the owner from the ...
0
votes
1answer
66 views

get all nodes created in a specific month

I have a custom search form that I posts a year + month, such as 2014-04 I would like to get all nodes created that month, when I create the timestmap I use: "SELECT ....... AND changed >= ...
0
votes
0answers
42 views

db_query complete Content Type with all fields automatically

Can I do this automatically in my module without hard coding the list of content type fields: $query = db_select('node', 'n'); $query->join(ALL FIELDS OF THIS CONTENT TYPE, FIELD ALIASES, ONs); ...
0
votes
0answers
27 views

Query to Database

I want make a query for get some products related with the identified user. The type contain has a taxonomy field called 'operating system' and the main profile has also it. For example: If a user has ...
2
votes
0answers
47 views

Extend db query in CKEditor Link User module

The CKEditor Link User module has essentially the functionality I need, but it requires editors to know users by their 'name' field in the users table. I wanted to extend the query to join with the ...
0
votes
0answers
182 views

unknown column base.enabled in 'field list' commerce kickstart entity module?

After moving some modules into my sites/all/modules directory I suddenly get the following error: PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'base.enabled' in 'field ...
1
vote
1answer
102 views

How to Display Unique Values from database using db_select in Drupal

i tried with following code but i cant get the attached output $query = db_select('webform_submitted_data', 'u'); $query->fields('u', array('sid','nid','data')); ...
0
votes
1answer
37 views

drupal 7, db_select(), strange behavior : malformed query

I have a table: mantenimiento_extras. I want a query like this: select * from mantenimiento_extras where id in (7, 9). (this case assumes passing array(7, 9), but it could be variable, even ...
1
vote
0answers
51 views

Why does views add the sort field as a SELECT expression?

The Context I have a content type with a Date field on it, field_dates. The field is configured to have a single value, allow end dates, and also allow recurrences. For those who don't know how ...
0
votes
1answer
52 views

SQL queries in theme functions - is it a bad practise? [closed]

I know, that calling SQL queries in template files is bad practise. But is it bad practise also for theme functions? For example when my form is rendering with my custom theme function: <?php ...
0
votes
3answers
48 views

Limit the results returned by 'published'

I am new to the Database API and SQL queries in general. I needed to create a custom module that could be given a list of fields and would output the average value of each of these fields. I am ...
1
vote
1answer
53 views

PDOException error - Google AdWords Conversion module

My Drupal site is having a serious issue. Whenever I try to add content, such as a Basic Page, I receive this error: PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column ...
0
votes
1answer
39 views

Displaying and selecting data from a database in a module

I have a database table (gpx_api) with the following fields: runID userID score distance pace speed gpx_path missionID startTime duration I want to display all of these fields ...
0
votes
2answers
43 views

Lots of generated queries

I enabled devel to Display query log UPDATE: this problem only happens for logged users I found that the Frontpage generate 900 queries. **67** of them generated by the **Locale** module and ...
0
votes
1answer
166 views

hook_views_query_alter all condition

I have an exposed filter that shows products which have multiple entity references. The user should be able to pick some number of entities and the view should show entities containing all those ...
0
votes
1answer
60 views

Help with a db_select() not returning results when it *should*

I'm having trouble figuring out why the db_select() is not returning any results. Long story short, if I pass the results of $results->execute() through a foreach ($results as $result), I don't ...
1
vote
1answer
49 views

What is the difference between havingCondition and having?

Drupal dynamic queries have 2 conditional clauses called having and havingCondition. The documentation states "The Having clause behaves identically to the WHERE clause, except that it uses methods ...
1
vote
1answer
197 views

drupal dynamic query for Inner join on same table

I want a dynamic query to do inner join on same table. My query is "select t1.table1 from table1 t1 inner join table2 t2 on t1.id = t2.id and t1.name = t2.name" I want to join table1 and table2 ...
0
votes
0answers
19 views

set_query_operator not having any effect on my WHERE clause construction

I'm doing a hook_views_query_alter and trying to add a simple OR condition to the end of the existing WHERE clause. I'm using set_group_operator('OR') but when I examine the actual query in the MySQL ...
0
votes
3answers
188 views

programmatically getting custom node belonging to a term

have searched google but cannot find anything specific . Intention is to get all Custom Node types that have been assigned a specific term of vocabulary . for example the follwoing is a db query to ...
3
votes
2answers
284 views

updating field value of a content type with query

I have a problem, may you guys can help me :) I have content type called book, and it has field called stock. Instead of using node_save() I want to update value of book stock using manual query. I ...
0
votes
1answer
121 views

views : display user list with number of comments and forum posts

I want to create blocks to display a list of all users with their number of comments and number of post on forum. In SQL, something like that : SELECT u.name as user, COUNT( n1.nid ) as 'number of ...
1
vote
1answer
86 views

Unable to add WHERE conditions as OR to query object

I'm attempting to override the query method for a node migration in the migrate_d2d module by adding two where conditions with "OR", and the first one is being added as AND instead of OR for some ...
0
votes
1answer
76 views

Manually populating fields using SQL queries

I have created a new field on an existing content type. The field is called "Global News." It's a checkbox and I need it to be checked for all existing nodes. I ran a SQL query to gather all nodes of ...
3
votes
1answer
104 views

How would I use DATEDIFF(), NOW(), and BETWEEN in a db_delete() query?

Is the something like the following possible? db_delete('note_dates') ->condition("DATEDIFF('start', NOW()) BETWEEN 0 AND 30") ->execute();
-1
votes
1answer
41 views

Problem with storing database queries values in array

I have a simple table with four field email,title,url & status status can be '0' or '1' There can be multiple values with status '1'. I want to store the all datas from the table with status ...
2
votes
1answer
58 views

D7 is slow when i visit admin pages

I turned on Devel query log and at the bottom of my pages it shows the log with the number of executed queries and ms. When i visit any admin page for example /admin/appearance i have following ...
3
votes
1answer
72 views

Query between 2 tables

I want the date for the last login for a defined role, but I have a problem with my query with drupal 7. I have the good answer in phpmyadmin with this query : SELECT login FROM `users` AS u, ...
0
votes
1answer
23 views

Error which i am incountering

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'dropjob.semaphore' doesn't exist: SELECT expire, value FROM {semaphore} WHERE name = :name; Array ( [:name] => variable_init ) ...
0
votes
1answer
35 views

How can I run a query in the views in the context of the user access?

How can I run a query in the views in the context of the user? E.g. using EntityFieldQuery I can run $query->addMetaData('account', user_load(1)); is there any equivalent for $view->query?