Topics related to the database API implemented by Drupal.
0
votes
0answers
20 views
Multiple condition not working in drupal
I am trying to fetch the record from db using below code
if(($from_date != '') && ($to_date != ''))
{
$all_list = db_select('downloaded_users', 'n')
->fields('n')
...
0
votes
2answers
28 views
limit db_select query by the value of a specific field
I am trying to build a custom drupal module to return the 'staff' that work at a specific charity when you are on the page of the charity. Both the charities and the staff members exist as separate ...
0
votes
1answer
24 views
multi query execution
i want to implement store procedure in drupal 6, i need database(mysql) connection to execute $mysqli->multi_query($query) currently i am creating new connection every time when my function called.
...
1
vote
1answer
25 views
db_insert() returns wrong key
I'm trying to migrate from drupal_write_record() to db_insert() / db_update(),
but db_insert() returns a weird key instead of the last inserted key.
On an empty table, I'm doing an insert, and ...
0
votes
1answer
33 views
Using db_insert with a reserved keyword as the column name
It appears that db_insert() (Drupal 7) fails when I try to specify a column name which is one of the reserved keywords (in this case, insert). I tried finding a way to use the back tick syntax which ...
0
votes
1answer
36 views
Check for field values to be unique when storing into the DB
I have a content type "Research assignment" which has several fields including the field "field_user" and "field_project".
I want to remove any old research assignments having the same user and ...
2
votes
1answer
27 views
How to get constant string array field into db_query?
First post here :)
Here's a valid MySQL query: SELECT "'a','b'" AS FieldStrArray;
(To enter as a string in PHP, remember the backslashes before double quotes.)
At least in Drupal 7's db_query(), ...
2
votes
1answer
37 views
Placeholders and the query builder?
I read on the drupal.org site: "Never put a literal value or variable directly into a query fragment, just as literals and variables should never be placed into a static query directly (they can lead ...
2
votes
1answer
40 views
Can db_select cope with mysql “case when” structures?
I have a complex mysql query with "case when" to combine values across multiple rows in columns. I'm currenty using db_query, but I would like to use the TableSort and Pager extenders. But (correct me ...
3
votes
1answer
39 views
Conflict with db_set_active and variable_get
I am running a drupal multi-site system, with shared code and seperated DB. Each individual multi-site represents one continent and can have different language versions.
What i want:
I am working on ...
0
votes
1answer
74 views
D7 - db_select: order by most recent, commented status
I'm writing my custom module.
I use the modules Statuses and 'fbss_comments' (part of the Statuses module). Comments are used to comment on statuses.
Using the following code I get a list of ...
0
votes
0answers
22 views
How to link to latest taxonomy term page from menu?
Apologies in advance for the newbie question, I'm just starting to work my way around the D7 API.
I'm trying to create a link in my Drupal 7 main menu which will always link to the most recently ...
1
vote
1answer
52 views
Migrating taxonomy terms when source is a separate table?
I'm writing a migrator for a now-unsupported WordPress plugin that used a single "attachments" table to store data ranging from thumbnails to musical genres. It looks like this:
mysql> describe ...
1
vote
1answer
354 views
Automatically fill in “City” field when “Postal code” is entered
I encountered a problem that has been discussed many times but for which no solution has been written down yet. This is about Drupal 7.
On my node add form, I have an "Address" field; a field ...
1
vote
3answers
51 views
How can I get count of deleted rows
How can I get count of deleted rows after db_delete?
db_delete('node')
->condition('uid', 1)
->execute();
something like
$count = db_delete('node')
->condition('uid', 1)
...
0
votes
0answers
21 views
use database function in db_api
Does anybody know hot to overcome the lack of specific database functions support in drupal?
I have a content type field that should get filled with the help of database function and when i use it ...
0
votes
0answers
42 views
Boolean field from custom content type not loading in Node when i use EntityFieldQuery [closed]
I am trying to load a node of custom content type using EntityFieldQuery as explained in the answer given by Clive here. I am able to run a similar query and load the node. I have 3 custom fields, two ...
1
vote
2answers
127 views
how to Insert form data in table
i have an enquiry form and submitting the form using jquery/ajax method.
$.ajax({
url:enquiry.php
I am able to insert records into database table using php mysql_query. When i use ...
7
votes
1answer
229 views
Is EntityFieldQuery really this inefficient?
I am an admitted newbie to the Entity API, but am trying to cure that. I'm working on a site that uses a number of content types with various fields attached to them; nothing fancy. So, when I want ...
0
votes
0answers
18 views
how to get get query string from db_query() [duplicate]
I know there is a drupal function to get the string of the query that is being used using the db api.
I just can't remember how it is called and how it is used.
For example using the following query:
...
2
votes
2answers
38 views
Looking up database schema of custom content type
I am setting up some reports using DB API to query custom content fields, and rendering in tables and charts. I am looking for a way to easily look up the names of tables and fields in the Drupal DB.
...
0
votes
1answer
32 views
Where In or clause for when a variable might not exist
If I were to run a normal mySQL query that selects all nodes I would do this:
set @type='node';
select * from actions where type = @type;
but what if lets say I set type to be something that ...
1
vote
2answers
64 views
WHERE NOT IN using an Array
My issue here is that I would like to execute Query 1, return an array of values from Query 1, and then exclude those values from Query 2. The reason for this is I will be performing an insert ...
0
votes
1answer
43 views
How to orderBy joined table after ordered main in db_select
I have 3 joined tables - The query search some string on main table then join other by entity_id. I want to orderBy records in order first second third tables result, but no success now. At this time ...
1
vote
1answer
26 views
DB API: How to add the result of an embedded query and a retrieved value
More fun with the DB API: I'm tracking the number of views of instances of a particular node type: I have a table that collects entries of the viewed node's nid and the timestamp of the view (which ...
0
votes
1answer
287 views
db_select group by of union
I'm quite new to drupal ad I've some problem with parsing a query throught the API:
SELECT t.pg,p.classe, sum(t.punti) AS punti, sum(t.vinte) AS vinte, sum(t.perse) AS perse, ...
0
votes
1answer
24 views
Getting a subset of items: Is it better to user PagerDefault and limit, or get'em'all and array_splice?
I want to pull some number of nodes out of the database for rendering and display. There are several ways to do this, two of which would be:
do a db_select(...)->extend('PagerDefault'); and add ...
0
votes
1answer
56 views
db_query - Get all nid in more than one nodetype
This is a simple query , but i really dont know why its not working. I think the problem is with single quote used!
$type = array('node_type_1', 'node_type_2', 'node_type_3');
$placeholders = ...
1
vote
3answers
53 views
DB API: How to get a list of nodes ordered by highest comment creation date?
The DB API is once again kicking my tail...
I've got a bunch of nodes of a certain type, each of which can have any number of comments, all in the usual way. I'm trying to do a db_select()-based ...
2
votes
1answer
93 views
how do i use subquery in db_api condition?
I am using drupal 7 and i would like to create subquery in condition clause with db_api. With db_query it goes something like this:
select *
from some_table_1
where some_table_1.something =
(select ...
1
vote
3answers
79 views
how to get nid of a node when user is not on a node page
I had made a custom form and want a field in it that would work as a node reference field. Currently iam not on the node page but i want the nid of nodes of a content type to be the options of the ...
2
votes
1answer
45 views
Problem with db_select not returning records sometimes
Works:
$rows = db_select('notification_queue', 'nq')
fields('nq', array('created_time', 'uid', 'notification_type', 'delivery_method','latest_time', 'earliest_time'))
->groupBy('uid')
...
0
votes
2answers
99 views
How can I write SelectQuery for SELECT LAST_INSERT_ID()?
Is it possible to run the following query with SelectQuery ?
SELECT LAST_INSERT_ID();
I would do this with db_query(), but I'm finding a way to use the query builder.
$last_id = db_query("SELECT ...
0
votes
1answer
34 views
Sub selection in db_select selectQuery [duplicate]
Possible Duplicate:
Is it possible to join dynamic tables (subqueries) using db_select()?
I have this part of a query running in drupal with db_query.
LEFT JOIN (SELECT ogmk.gid, ...
2
votes
2answers
148 views
Querying for user's whose birthday is today plus other OR conditions
We have a date field attached to the user entity. It stores values for year, month and day, in the following format (looking at the field_date_of_birth_value column in the DB): 1987-06-08T00:00:00.
...
1
vote
1answer
113 views
Why can't I have hyphens in my db_query()
I am trying to SELECT all the rows in my MySQL where a field matches a variable using the db_query() function. The variable is not a user input, it is retrieved from another database table based on ...
2
votes
0answers
63 views
Using join query / checking conditions with a table without unique key
User fields are:
field_age (text field)
field_sex (text field)
field_vaccinations_taken (node reference field with multiple values, referenced to vaccination content type)
Vaccination content ...
2
votes
2answers
125 views
How do I add COUNT(foo.bar) to a dynamic query?
I have a query like the following:
SELECT t.tid, t.name, t.description, COUNT(i.nid)
FROM taxonomy_term_data t
LEFT JOIN taxonomy_index AS i ON i.tid = t.tid
GROUP BY i.nid
LIMIT 60
I ...
0
votes
2answers
86 views
Can someone explain how db_query() works? [closed]
Can someone please explain what's going on in here,
db_query("update {my_table} set sugar_values='%s' where drupal_id='%d'", $serialized_data, $user->uid)
I don't quite understand how this works. ...
2
votes
2answers
160 views
How to use NOT EXISTS condition?
I have 2 tables:
|users | |users_roles|
-------- -------------
| uid | |uid| rid |
-------- -------------
| 1 | | 1 | 3 |
| 2 |
For the authenticated ...
1
vote
2answers
104 views
How do I know whether drupal_write_record has done an insert or an update?
I use the function to insert or update records in a table, but sometimes I would like to know whether the function has executed an update or an insert. In my scenario I always provide the primary key:
...
3
votes
2answers
151 views
How to perform join with multiple columns using db_select?
How to perform join with multiple columns using db_select? Any help?
Here below is the sample, which I'm looking for.
SELECT * FROM digitaliq_flds_by_node a
JOIN digitaliq_fld_category b ON
...
2
votes
2answers
81 views
what is the best way to insert arrays of values in drupal 7
i am tring to insert multible values from textarea to the db table called banned_users
foreach ($user_emails as $key => $value) {
$insert_banned_emails = db_insert('banned_users');
...
0
votes
0answers
80 views
“Select” form field depending from another “select” form field receives just a value
I am working with a custom form using two "select" form fields where one depends from the other one. The second "select" form fields receives only one value.
What is wrong with the code I am using?
...
2
votes
1answer
198 views
convert to db_query and addExpression
Is there a way convert this static query in a dynamic query?
$sql = "SELECT n.nid, n.title, n.created, n.type, n.status, IF((SELECT nid FROM `newsletter_lists` WHERE cid=$cid AND nid=n.nid), TRUE, ...
2
votes
1answer
143 views
How can I use the MySQL FIELD() function within a SelectQuery object in Views?
I want to use the MySQL FIELD() function to alter a query so that it orders a particular field on a particular order of keys.
The keys for this 'select' field are: active, under_contract, sold
I ...
3
votes
1answer
106 views
Mapping regular SQL to Drupal's Database API - using 'exists'?
I have the following SQL that I'm trying to translate using Drupal's Database API:
select nid,biblio_type from biblio where not exists
(select * from biblio_types where biblio_type = tid);
What ...
0
votes
1answer
38 views
How to use addField function when the field name is SQL keyword
I have a field with name 'order' in the database. How to select it, using addField?
$query->addField('sco_groups', 'order');
Gives an error.
5
votes
2answers
133 views
Use a database specific function in dbtng (e.g. uuid in db_insert)
I have a table that contains a char(36) field for a uuid. It seems like I can insert data into that field with a mysql query like: INSERT INTO mytable (uid, event_guid) VALUES (1, uuid());. I'd like ...
0
votes
1answer
64 views
How to process the data which type is BLOB?
I get the following data from MySQL by db_query(). The type of the column is BLOB.
a:2:{s:10:"attributes";a:1:{s:5:"title";s:0:"";}s:8:"langcode";s:7:"zh-hans";}
How should I process it?