Topics related to the database API implemented by Drupal.

learn more… | top users | synonyms

0
votes
0answers
22 views

db-update is not working

Node status does not change. If I set status = 1 it works fine. function yt_common_changes_mark_spam($args) { $num_updated = db_update('node') // Table name no longer needs {} ...
0
votes
2answers
36 views

How to convert a complex select query to Drupal dynamic query?

I read online that db_query is faster than db_select for complex queries. I wanted to check this for one of the queries I have written. Following is the code with db_query: $query = "SELECT ...
1
vote
1answer
13 views

How to do multiple conditions for db_update by using OR condition?

I would like to convert the following UpdateQuery statement to work with multiple conditions by using OR instead of the default AND condition: db_update('system') ->fields(array('status' ...
4
votes
3answers
136 views

Whats faster db_query, db_select, or EntityFieldQuery

So I'm trying to find out what is faster db_query, db_select, or EntityFieldQuery. Currently I'm using EntityFieldQuery. I'm grabbing about 1600 node entries. I realize this can be taxing on the ...
2
votes
1answer
45 views

MySQL date format functions in Drupal

How can I do a MySQL date function in Drupal? I have this now: $select = db_select('someTable', 'st'); $select->addExpression('DATE_FORMAT(FROM_UNIXTIME(created), "%Y-%m")', 'createdMonth'); ...
0
votes
2answers
48 views

Select users with only one role

How can i select all users wich have only 1 role. For example i got 4 users: User 1: Role 1, Role 2 User 2: Role 1 User 3: Role 1, Role 2 User 4: Role 1 How can i retrieve a list of users ...
0
votes
2answers
26 views

How add/update a record conditionally based on existence of primary key?

I have a table with structure: Table ( record_1 int, record_2 int, PRIMARY KEY (record_1) ); I want to write/update a record based on its existence. I was told to use drupal_write_record(), but for ...
0
votes
1answer
25 views

How to translate a database query with a subquery to a db_select statement?

Assume any variable that doesn't have a definition in the sample code is defined elsewhere. I need to get the results of the following query: select type, eid, vid, language, keyword, custom_value ...
0
votes
2answers
42 views

Complex condition drupal query

I'm trying to add following mysql condition: WHERE DAYOFYEAR(curdate()) <= DAYOFYEAR(DATE_ADD(FROM_UNIXTIME(field_birthday_value, '%y-%m-%d'), INTERVAL (YEAR(NOW()) - ...
0
votes
1answer
56 views

How can I make Drupal/MySql accept special characters in ANSI (without changing the file's encoding)?

I'm developing a custom module where a user (actually an admin of sorts) can upload a CSV file. Based on the contents of this file, certain rows are inserted into a table. I'm now having problems ...
2
votes
1answer
39 views

Is a DB transaction executed when it is committed?

cache_get() is not working as expected when called in a request initiated by drupal_http_request() on the same server. Is it true that the cache_set() immediately before drupal_http_request() doesn't ...
2
votes
3answers
562 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
4answers
105 views

drupal as mobile app backend

Im currently using drupal 7 + commerce for online sales and I have a phonegap app that creates orders. I want to use drupal 7 via a the services module to sync the app sales data with the online ...
0
votes
2answers
38 views

Show table records in view via hook_form

I managed to get things looking a bit better, However I dont know why the checkbox below is showing like the picture. I want to select the checkbox and make it do something with the corresponding ...
0
votes
1answer
28 views

uid is not taking

I'm getting uid by $account->uid on rules when I wrote a query by using this id it returns 0 rows. Below is the code that i'm writing on rules $uid=$account->uid; $sql="select * from profile where ...
0
votes
1answer
96 views

LEFT JOIN with db_select()

I'm trying to do a left join but it isn't working. I have 2 tables: TABLE profile - uid - pid TABLE field_data_field_naam - entity_id - field_naam_value I want to select the field_naam_value ...
0
votes
1answer
14 views

Facets blocks populated with incorrect field data and strange behavior

I'm building a product catalog with faceted search. I'm using Search API, Search API Database Search, and Display Suite. I've created a search server as well as an index which indexes four fields ...
0
votes
1answer
65 views

Correct way for a db_query for nodes between two timestamps

I have a very simple db_query. I want to look for any node created between two timestamps. This query works fine in MySQL shell SELECT nid as id,created as start,title FROM node WHERE created ...
1
vote
1answer
67 views

EntityFieldQuery with “NOT IN” FieldCondition and “=” FieldCondition on the same multi-value field is only processing one FieldCondition

The EFQ is: $query->entityCondition('entity_type', 'node') ->fieldCondition('field_terms_wb_access', 'tid', array_keys($children), 'NOT IN') ->fieldCondition('field_terms_wb_access', ...
0
votes
0answers
25 views

Creating custom content types with a custom module

As a newbie to the Drupal developer community, I'm struggling to understand whether or not a specific approach follows best practices. Regarding persisting data in a custom module, the Database API ...
0
votes
2answers
130 views

Dependent Dropdown based on Database Queries

I've been working through the Drupal 7 AJAX form examples in the Examples module, and am trying to set up a dependent dropdown form element with 2 select lists populated from the database. Basically, ...
2
votes
1answer
29 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 ...
0
votes
1answer
33 views

db_query and db_select not returning anything

I'm trying to use either db_select or db_query with a join in Drupal 7, but not having luck. The query I'm trying to run is: SELECT floormap_counter_expected.counter_name, ...
1
vote
0answers
15 views

I'm getting an error saying I'm inserting a duplicate entry when there isn't one

I have a form for users to update labels for cameras that my Drupal 7 module is displaying. When the user submits the form, first I check to see if the submitted value already exists int he DB: ...
1
vote
0answers
31 views

db_query select nodes created this month [duplicate]

I need to query the database directly using php. I am getting my head around this an how to do this using the Drupal database abstraction layer (using db_select and db_query). I need to limit my query ...
0
votes
1answer
65 views

db_add_field not working

I want to add a new field to node table using db_add_field when intalling a new module, but it seems there is something wrong or missing: here is the code used: /** * Implements hook_schema_alter() ...
1
vote
1answer
101 views

How can I prevent placeholders to wrap the value with single quotes in db_query?

I want to run a select query using db_query. Here is the code: $nid_array = array(24,34,56,7,8); $list_of_nids = implode(',',$nid_array); $query = " SELECT * FROM {table_name} as t ...
0
votes
1answer
34 views

One time db scrub with .install file

I need to scrub a production db to replace paths in the body field. Being a production database, it needs to happen in a time-sensitive, well-documented way with the solution frozen in code. I'd ...
0
votes
0answers
50 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
1answer
36 views

What is “alias” in db_select() function?

Beginner Drupal Developer. The drupal API didn't provide info for what purpose the $alias must be used in db_select? And what is that anyway?
0
votes
0answers
9 views

How to convert certain db_query to db_select using WHERE, OR and AND conditions [duplicate]

I have this db_query: $transactions = db_query("SELECT * FROM {funds_transactions} WHERE uid='$user->uid' OR type='Transfer' AND reference=$user->uid"); And I need to convert it to db_select. ...
0
votes
0answers
75 views

Drupal db_select Query to over ride empty array inside NOT IN ()

I had a query (part of a big query): $query->add_where(1, '10', db_select('users_roles', 'r') ->fields('r', array('rid')) ->where('r.uid = users_node__users_roles.uid'), 'NOT ...
2
votes
0answers
50 views

DB API: How to implement an enumerated field using hook_schema?

I need to have a field in my database that is shall hold a limited set of enumerated values. The MySQL ENUM type is not one of the predefined Drupal data types. So how do one implement a field to ...
0
votes
0answers
62 views

db_select pager query orderBy signed int

I have an INT 'weight' field for some nodes that runs -20 through to +20 and want to order the nodes so that -20 is at the top, but, as far as I can tell I'm getting them in string order. I've tried ...
0
votes
3answers
52 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 ...
0
votes
1answer
65 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 ...
6
votes
1answer
407 views

Preventing SQL injection

In Drupal 6, queries are issued with db_query(). Using %-modifiers, query arguments are substituted into the query after being filtered. Strings %s (and only strings) are ultimately run through ...
1
vote
1answer
858 views

db_update add value to field [duplicate]

I want use db_update to update a field,instead of update a field with new value (replace) , I want add a value to last value, I know I can do it with mysql command UPDATE ...
0
votes
1answer
75 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
270 views

How to query for null in nested db_or conditional

I am trying to perform a query as listed below (notice the check for NULL) $query = db_select('node', 'n'); /* add fields and joins... */ $query->condition(db_or() ->condition(db_and() ...
0
votes
2answers
58 views

Accessing field inside a block

I have created a block to display flash content. All it needs a a variable to be assigned dynamically from the content to flashVar. I created a field called myfile path in the custom content type. ...
3
votes
2answers
72 views

Should I use content-types or database abstraction layer?

I am building an admin site for my brother's property management company. The design seems pretty straight forward. I need a database with tables to store: Estates. Each estate has a number or ...
0
votes
2answers
128 views

How to order unions separately in db_select?

I have a UNION query, where the second part of the UNION should be ordered separately, not the complete UNION. The resulting query should look like this: ( SELECT id, fname FROM tab1 WHERE fname = ...
0
votes
1answer
29 views

Setting up Multiple Databases on a current site

I'm having issues with my current shared hosting provider due to my core database exploding upwards of 1GB due to cache_form. I've been looking at trying to offload the cache and revisions databases ...
0
votes
0answers
60 views

Drupal 7 with standalone PHP service

I'm trying to create a stand alone PHP page that going to be service. I know about Services module, but I need the stand alone page. This page is localed under my Drupal root directory in _services ...
0
votes
1answer
90 views

The most efficient way to query the user table and custom profile info based on UID

I am trying to grab a specific users profile info + custom profile fields WHERE uid = X, I have used the views module currently and copied that sql however that creates a massive query. I was ...
1
vote
2answers
436 views

Using db_select with subqueries

Here's an example raw query of what I am trying to achieve with database API: SELECT * FROM ( SELECT n.nid AS entity_id, n.uid, n.title, node_body.body_value, ...
1
vote
2answers
122 views

How to create db table while installing a module?

I want to create a table in Drupal while installing a module (custom module which is crated by me). I tried in the below way, but I could not able to create a table in Drupal db. what am I missing, ...
2
votes
2answers
509 views

Drupal 7 db_error() equivalent?

I'm trying to figure out how to get the last database error after a query fails, and I'm having trouble finding the appropriate function. It seems up until Drupal 7 there was a db_error() function ...
0
votes
0answers
21 views

Query treating large number as a string

I am trying to run a select statement on a table for a column. The column is decimal(20,0) unsigned. A majority of the entries can be found using the select statement: db_query('SELECT * FROM ...