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

learn more… | top users | synonyms (1)

2
votes
4answers
33 views

Accessing content type data using mysql

I'm trying to use data captured within my drupal database to drive some analytics in another tool. I am trying to develop a view which gets the field data for a content type i've created. The db model ...
3
votes
4answers
177 views

Will the PHP filter prevent SQL injection attacks?

I had trouble getting the form API to work though I am considering re doing all my forms with it. I have some custom html/php forms however I directly insert into the DB using pg_query. I am looking ...
1
vote
1answer
49 views

db_insert in Drupal 7 without field names

I have the following INSERT in a db_query, but feel like I should convert it to a db_insert, but can't figure out the syntax: INSERT INTO {mytable} VALUES (23, 'foo', 'bar', 42) This example is ...
1
vote
1answer
29 views

Hiding error messages: sql query

I have a site running on Drupal. There is a production site, publicly seen online and a development version on a private machine. When migrating from a devel to a production server I'd like to ...
0
votes
0answers
26 views

SQL Statement - multiple inner joins

Drupal 7 / Views 3 I have a view where I'm trying to use filter grouping: See http://www.micnap.com/images/filter-groups.png for a screenshot of the filters. If I set field_emp_county to 56, I get ...
-1
votes
0answers
42 views

I get an AJAX error during image upload in Drupal 7 [closed]

Eine AJAX-Anfrage ist abnormal beendet worden. Im Folgenden finden Sie Debugging-Informationen. Pfad: /de/file/ajax/field_iuk_bild/und/form-pYUt5fpI-crX-MEVpWUj4JNykQI2s1icTwbz2qEOngA Statustext: ...
0
votes
3answers
61 views

Can I rewrite a view's query SQL directly?

Can I modify the SQL generated by the Views Query Builder? Views doesn't support subquery out of the box, so I'm just wondering if I can add the final line to my query manually? Background info: The ...
0
votes
1answer
18 views

Custom DatabaseConnection driver does not get found by drupal!

I need to customize a method on the DatabaseConnection_sqlsrv (MSSQL) driver, so i created a new driver class called DatabaseConnection_sqlsrvseed and extended all depended classes from the *_sqlsrv ...
1
vote
1answer
32 views

Best way to make an EntityFieldQuery query be case sensitive?

The case-sensitivity of queries created using EntityFieldQuery rely on the underlying database's collation [*]. So if the collation for a particular field is 'utf8_general_ci', then all the queries ...
0
votes
2answers
24 views

How to create complex conditional clauses / queries?

I've been reading the documentatoin on conditional clauses and also studied the api description for db_and() and db_or() but I fail to create a $query with 3 ->conditions: select all between 0 ...
2
votes
1answer
33 views

How to skip first row in a dynamic query?

I've not yet found the right way to use ->range($offset,$limit) in a dynamic query to skip first result, but without limiting the resultset (LIMIT clause). The only workaround I've found is to use an ...
0
votes
1answer
20 views

Left Join query causing 'Column not found' error

In Drupal (v7.22) I'm trying to modify a query in a module so that it checks the value of an additional field from another table while looking for a result. I've been going through the documentation ...
0
votes
1answer
25 views

Rewrite SQL on a specific content type node on Drupal 7

I'm trying to rewrite SQL on a specific node type on Drupal 7. I found this, But it only works on Drupal 6-. What's about Drupal 7? Thank you. ...
1
vote
1answer
23 views

How do I mark a database query with a tag?

How do I mark a database query with a tag so that I may alter it via hook_query_alter? I get the concept, but does anyone know what the syntax is? A working example would be helpful. Thanks.
-1
votes
1answer
53 views

When creating new view: “Base table or view not found” problem [closed]

When creating a new view and then trying to save it, I get this error: PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'drupal.views_display' doesn't exist: INSERT INTO ...
0
votes
1answer
19 views

How to order a database query

In Drupal v7.22 I'm trying to order the query below for a custom module but I cannot seem to find documentation that fits this query. $sql = "SELECT field1, field2 FROM {tablename} WHERE field3 = ...
1
vote
1answer
42 views

The 'Drupal' way to query the database

I'm using the method below to query the database within a custom module but it doesn't seem to be the 'Drupal' way of doing things. Is there a better way? $sql = "SELECT field1, field2 FROM ...
2
votes
1answer
28 views

Count Unique Visits to the Drupal Site

Is there any way I can count unique visits to my Drupal Site. I have a customized reporting module for the Drupal within which I want to put the unique visits to the site based on date. I am using ...
1
vote
1answer
50 views

What is a one line mysql query that can update all body fields of matched nodes?

I am trying to do a bulk node update that affects 100+ nodes. I want to set each of these node's body field to a specific string. Say I want to affect all content types: "basic page". Since my sql ...
0
votes
0answers
30 views

How to convert Drupal Field Collection to Node?

I am using Drupal 7 and have a Field Collection that I would like to convert to a custom content type (Node) with the exact same fields. What is the best way to do this? The field collection has the ...
2
votes
1answer
76 views

Passing Timestamp in the SQL Query to filter results

I've a query where I want to filter query results based on today, yesterday and week. I've written queries within Drupal 7 and it is as follows:- $result = db_query(" SELECT n.title, n.nid, ...
0
votes
0answers
45 views

Seemingly random error when writing to /tmp

Lately I've been getting numerous errors of this type: PDOException: SQLSTATE[HY000]: General error: 1 Can't create/write to file '/tmp/# Yet the /tmp directory is set to 777. Oddly enough: If I ...
0
votes
1answer
23 views

What is the reason to define indexes in hook_schema?

How do I choose what fields to index and which ones not to? Is the index useful for when I set a condition in the database query for a quick look up of the rows? I guess this is an SQL question but I ...
2
votes
1answer
44 views

What module will show me all sql queries being run on the loaded page?

My site is running slow and I suspect its a module, but not sure which one. Is there a module that can display all the sql queries being run on a loaded page? If there isn't maybe there is a command ...
0
votes
1answer
78 views

How to get values of delta field from “block” table in drupal 7 from the database for the activated theme in a custom module?

Can I get all the values of delta field from "block" table from the database in my custom module I have tried with this code as clive has explained it here but it shows me an error: $query = ...
0
votes
2answers
62 views

Sql-sync prefixed multi-site installations within the same database with Drush?

I am running several Drupal 7 multi-sites that share same code base as well as the same database with prefixed tables per multi-site (some tables are shared too). I chose this setup, because i need ...
1
vote
0answers
22 views

How to write a nested join in Drupal 7?

I know how to write a join in Drupal 7, using leftJoin(), join() etc. These basically take a table name and a condition, which in SQL maps to something very much along the lines of: LEFT OUTER JOIN ...
4
votes
2answers
97 views

SQL query the Drupal way, complex SELECT, conditional aggregate

I'm starting to invest time in learning custom Drupal entities like the ones explained here and I want to make sure that I am going to be able to do something in the future. I am working with Drupal ...
0
votes
1answer
17 views

How to print all the elements of a specific column from a table from database in custom module?

I have a custom module. I would like to see all the blocks in it . For that i have written a query in my costom.module file . But it will show me the following error. Query:- $result = ...
0
votes
2answers
26 views

How to make a single query with multiple records

How do I make this as a single query? $result = db_query("SELECT replace(source, 'node/', '') as source FROM {url_alias} where source like 'node/%' limit 11"); foreach ($result as $record) { ...
0
votes
1answer
74 views

GROUP BY in hook_views_query_alter() doesn't work

I'm using Views 7.x-3.6 and I tried altering the GROUP BY clause with hook_views_query_alter() function mymodule_views_query_alter(&$view, &$query) { if ($view->name == "view_name"){ ...
0
votes
1answer
168 views

Add a JOIN with a subquery into a views query

Here's my SQL, which I am trying to include in hook_views_query_alter() to modify the uc_catalog view (from Ubercart 3): JOIN ( SELECT uc_products.nid, MIN(uc_products.sell_price) AS min_price ...
0
votes
0answers
26 views

Ubercart adjustments query hangs up

Recently found a bug in my system which uses ubercart, such that whenever I click on adjustments tab of specific product edit page, the cpu utilization for mysql shoots up to 100% for some reason. I ...
2
votes
1answer
44 views

Is it possible to divide two columns using the the query builder?

Is it possible to divide two columns using the the query builder? Like: $query -> fields('A', array('valsA') / 'B', array('valsB'));
2
votes
2answers
454 views

General error: 2006 MySQL server has gone away

This is the error I am suddenly getting. Additional uncaught exception thrown while handling exception. Original PDOException: SQLSTATE[70100]: Unknown error: 1317 Query execution was ...
0
votes
3answers
54 views

Pulling data into a content type

I'm hoping to get some opinions on the best way to proceed. We are migrating our website from a Microsoft Environment to Drupal 7 and I appear to be having trouble wrapping my head around how to do a ...
0
votes
1answer
34 views

View/query to show latest node related to each term in a taxonomy vocabulary

I have a node type (stories) which is related to a taxonomy vocabulary (countries). Each story is related to one country only. I want to create a view of the latest story from each country, ordered ...
0
votes
1answer
41 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
69 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
46 views

Database Query to test new users

In my Drupal 7 site, I inserted values into the 'surname' and 'date of birth' fields of my database tables. I want to prevent new users whose username and date of birth do not match those on my ...
0
votes
1answer
650 views

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'fmotors_fms.block_node_type' doesn't exist:

This was working fine last night but when i login to my computer again I got this error now. What is this table {block_node_type} I cant find it in the database but it is in the drupal code in ...
2
votes
1answer
40 views

how to groupby with rollup in drupal 7

how to get booking records from booking table .how to get group by function with ROLLUP SELECT * FROM booking GROUP BY startBooking WITH ROLLUP; how to convert above query in drupal 7? ...
1
vote
1answer
22 views

EntityFieldQuery for getting the count of a user blog

EntityFieldQuery for getting the count of a user blog. Blog is a content type.
1
vote
0answers
53 views

Performance Implications when Views JOIN added twice?

I have a view with a flag (relationship, only show flagged nodes). I have modified it a few times and now I see in the query output that views has the join added twice: INNER JOIN {flag_content} ...
0
votes
1answer
101 views

Join multiple tables in D7 Views

I'm trying to create a View Block to display related information on a node. I'm creating an image gallery where each image node is tagged with one/more taxonomy terms, and a block on each of those ...
1
vote
3answers
63 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
1answer
73 views

How to remove and add joins to a view?

Because of some buggy handlers I need to write a hook that will: Get location_instance table's alias from the original query Remove location_instance table join Remove that alias join Remove a ...
0
votes
0answers
297 views

Drupal 7, How to get Taxonomy Parents and Children in View

My Taxonomy Hierarchy: -Council Minutes -Reports to Council -Auditor -Treasurer -Tax Commissioner -Proposed Ordinances -First Readings -Second Readings -Third Readings I attached files ...
1
vote
1answer
85 views

building a query with the database api and groupby multiple fields in drupal 7

first of all I simplified my query so it might be more useable to other users on this site. I'm looking for a solution to use group by on multiple fields. This query selects the values of the ...
0
votes
1answer
115 views

Making fields, condition and join dynamic in db_select query

What is the Drupal way of creating queries which are dynamic in nature ? What I mean is for example- In my module I am asking the user to select some content types and the fields associated with each ...

1 2 3 4 5