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

learn more… | top users | synonyms (1)

0
votes
0answers
2 views

select nodes whose created date in hours is equal or larger than 48 hours

I make a PHP routine in which all node is selected and check created date and delete those nodes which is created in last 48 hours or greater. $result = db_query('SELECT n.nid, n.title, ...
0
votes
0answers
6 views

views_query_alter change to operator OR for contextual filters and normal filters

My question is rather simple and I have searched quite a bit for the answer with no result. My view produces below SQL (simplified): SELECT stuff FROM tableA LEFT JOIN tableB LEFT JOIN tableC ON ...
-2
votes
0answers
13 views

OG Module trying to call db_condition_placeholder in intergare value in DB [on hold]

I've been working with a drupal website, nothing been changed or updated and overnight got the error below. I've not got a great knowledge of drupal and unsure why this error appear and can't find ...
1
vote
1answer
22 views

Possible to use PDO inside a custom module in Drupal 6?

I'm about to build some new functionality on an old Drupal 6 site which will be upgraded to D7 or D8 within a year or so. This new module is heavy on the SQL and I'm building many complex SQL queries. ...
0
votes
1answer
25 views

how to get the response in JSON format?

I am using Drupal 7 Services to expose an API, The following is the code I am using to get some of the datails and It is giving the response interms of Arrays, But I don't want the response to be in ...
0
votes
0answers
17 views

Slow SQL query in Views relationship from Content Profile module

I have a slow SQL query in a view using a relationship from the Content Profile module (D6). My problem is more on the SQL side. Once I have the proper query I should be able to change it. The query ...
0
votes
2answers
22 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
21 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
26 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
130 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
119 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
19 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
26 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
50 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
52 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
65 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
24 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
63 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
20 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
24 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
95 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
73 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
46 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
29 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
50 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
207 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
123 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
40 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
53 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
57 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
56 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
45 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
47 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
184 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
64 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
52 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
217 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
20 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
213 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
321 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
132 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
93 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
78 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 ...