Topics related to the database API implemented by Drupal.

learn more… | top users | synonyms (1)

0
votes
2answers
19 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
15 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
25 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
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
4answers
49 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
29 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
25 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
29 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
9 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
24 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
16 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
21 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
58 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
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 ...
0
votes
1answer
22 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
12 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
28 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
33 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
75 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
29 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
41 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
29 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
64 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
37 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
47 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
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 ...
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 ...
6
votes
1answer
260 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 ...
0
votes
1answer
410 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
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
131 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
48 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
69 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
86 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
28 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
56 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
75 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
292 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
109 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
353 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 ...
1
vote
1answer
984 views

db_select condition with subquery causes PDOexception

I want to build a relative simple select query with a subquery in its condition. What I want to achieve is to get the list of users updated after a given timestamp. The working SQL-Query which I ...
1
vote
1answer
80 views

How to implement ORDER BY SUBSTRING in db_query

I am migrating comments from a Drupal 6 site into Drupal 7 - but I am importing into the Reply module https://drupal.org/project/reply because the comments were on a Profile node in Drupal 6 but now ...
2
votes
1answer
326 views

SQL left join query using Drupal DB Layer

The following (my)?sql query performs a left joins of node table with url_alias table by matching a node with its url alias, and returns rows with the node's title, date created, type, and url-alias: ...
2
votes
1answer
39 views

How to make weights continous with db_update?

With pure MySQL, I can do something like: SET @weight:=0; UPDATE mymodule_table SET mymodule_weight=@weight:=@weight+1 ORDER BY mymodule_weight, mymodule_id; Is there a Drupal way to achieve ...
0
votes
1answer
454 views

Can't change quantity of line item with rules

I created a rule that checks for the quantity of a product while adding to cart and while proceeding to the second step of checking out. The action sends a warning message to the site that says you ...
0
votes
3answers
446 views

How can I run a sql query from a file in Drupal?

I have a module that will be used as a location finder, and it needs to create a table on install that will hold zip codes and their location. That's easy to do. However, I also need to populate that ...
0
votes
2answers
584 views

Get a taxonomy id(tid) from a node id (nid)

if($node->type=='student') { $nid = $node->nid; print_r("The node id is: ".$nid.'<br/>'); $tid =db_query('SELECT tid FROM {taxonomy_index} WHERE nid = :nid', ...
0
votes
1answer
32 views

Get the highest Matched output in result

I have a table like this Now my requirement is like below:- I have to fetch all Content ID related to User Id-31. Here the matching content id are 225,178. I am able to retrieve this. Now I want ...