Topics related to the database API implemented by Drupal.

learn more… | top users | synonyms

0
votes
0answers
5 views

addExpression() and FROM_UNIXTIME format [duplicate]

Having some trouble figuring this out, all of the examples I have looked at make it appear that what I have done is correct. Here is my query: $query = db_select('webform_submissions', 'w'); ...
1
vote
4answers
86 views

Does node_delete() function deletes the attached media files as well?

I'm deleting my 'articles' created before Sat Nov 1 00:00:00 2014 GMT from Drupal 7.34 site, but I'm not sure whether the node_delete() delete the media files as well? Below is my processing code: ...
0
votes
1answer
6 views

How to drop tables shown as Missing in Schema Report

During development/testing after using Backup and Migrate Restore in conjuction with Schema, Schema will show Extra tables no longer referenced in the database, used by modulesetc, and no longer ...
0
votes
1answer
16 views

Does Drupal cache db_query results for multiple users?

I am running into something strange and perhaps someone here can help me. I am trying to prevent two things from happening at once because the second attempt might be influenced by the first attempt. ...
0
votes
0answers
9 views

Add product using Drupal 7 / Ubercart 3 Api

I'm writting my stupid import module and need to programaticaly add products to db. I need to add title, price and link product to existing group; I'v made some research of ubercart api and found ...
0
votes
0answers
11 views

DUAL table query

How do I construct the following query with DB API (so it's database engine independent): SELECT 1 FROM DUAL This example is for MySQL. I believe the Postgres version is SELECT 1
0
votes
1answer
18 views

SQL replace() function in PDO

I'd like to convert the instructions from this answer into a general script that can be reused across projects. I'm wondering how these commands can be written in Drupal 7 PDO format: UPDATE ...
0
votes
2answers
24 views

Select data from database when submitting a form

I'm trying to learn how to make select queries with Drupal, so I made a form, and when I submit the form I try to query the database and get some results, but instead I'm redirected to an error page, ...
0
votes
1answer
30 views

How do I write this PHP query the Drupal way (database abstraction)?

I am using the code below to evaluate if a panel pane should display. I've read the docs on database abstraction, but I just don't really understand how to apply it. Of course, the dpm values are for ...
0
votes
1answer
30 views

Obtain an image url

I've a module that in the .install creates a table. In that table I have to save the information of one image, that's imagen_leyenda. I obtain that image from a form, that I have created in my ...
0
votes
1answer
45 views

List nodes of children using taxonomy_select_nodes

I want to list nodes from children terms using or editing taxonomy_select_nodes function. Actually I added these few lines but I get an infinite loop or slow response: function ...
0
votes
2answers
28 views

Database object syntax for where conditions giving error

I am trying to convert the following SQL query in calls to the database API. SELECT p.id, p.message,t.posted, p.posted AS reply_date,p.poster_id,t.id,t.subject, t.forum_id FROM punbb.punbb_posts AS p ...
1
vote
1answer
51 views

How to backport db_merge() to drupal 6?

I am converting a module from drupal 7 to drupal 6. I have a query in drupal 7. The query contains function db_merge() db_merge('facebook_rules_user_tokens') ->key(array('uid' => ...
0
votes
0answers
49 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
1answer
68 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
150 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' ...
5
votes
3answers
351 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
211 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
90 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
41 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
39 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
73 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
156 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
52 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
3k 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
246 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
61 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
1k 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
21 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
167 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
222 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
33 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
270 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
30 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
65 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
19 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
33 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
114 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
122 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
39 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
74 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
49 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
10 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
93 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
68 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
94 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
63 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
99 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
528 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 ...