I was using drupal 7.12 installation and using webform module to get meeting request from user for other users. Now I need a webform submission listing page for viewing the meeting request for the loggined user from other users. I took these data from database using normal db_query() method. The query I used for this is given below.

"SELECT nid, sid, uid, submitted FROM webform_submissions WHERE sid IN ( SELECT sid FROM webform_submitted_data WHERE cid = '1' AND nid = (SELECT nid FROM node WHERE title = 'Book Meeting') AND data = '".$user->uid."' )"

After that when tried the same using db_select() function I was getting some fatal errors.

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 261900 bytes) in /home/rajeesh.r/project/dvs_test/includes/database/query.inc on line 1073

Please check the code I used for this.

$query = db_select('webform_submissions', 'ws')
  					->fields('ws', array('nid','sid','uid'));
						$subquery = db_select('webform_submitted_data', 'wsd')
  							->fields('wsd', array('sid'));
 							 	$subquery = db_select('node', 'n')
 							 					->fields('n', array('nid'))
 							 					->condition('n.title','Book Meeting');		
 							 $subquery ->condition('wsd.nid',$subquery);
 							 $subquery ->condition('wsd.cid',1);
 							 $subquery ->condition('wsd.data',$user->uid);
			$query->condition('ws.sid', $subquery, 'IN');
		
		$result = $query->execute();

I can't understand why it was happening and I followed writing subquery in db_select() method from this article. http://drupal.stackexchange.com/questions/8548/where-not-in-select-with-...
I think it's may be because in my query I was having two inner subqueries. Help from anybody will be appreciated.
Thanks.
(Sorry for my bad english).

Comments

robertdbailey’s picture

Perhaps a little late on a response to your question, but it appears you are reassigning the first $subquery before using it. If you are really using both subqueries, then you should have two lines like this:

$query->condition('ws.sid', $subquery, 'IN');

For debugging your query, you can use the following method on the query object to view the query as it will be submitted:

print_r($query->__toString());

See https://drupal.org/node/310075 for more info on writing dynamic queries.

Version: 7.12 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.