⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Problem with Temporary Table



Dogtooth

Dogtooth
  • profile picture
  • Member

Posted 25 November 2014 - 18:12 PM

Hello everyone,

 

I need to be able to run queries across several tables. After some research I thought the most comfortable way would be to use temporary tables.

 

But something goes wrong and I'm starting to think it's a bug, because I found an ugly workaround. Or I'm totally wrong, because I'm a beginner and missing some essential rule.

 

 

This controller won't work:

public function my_query()
	{
	$crud = new grocery_CRUD();
	
	$this->db->query('DROP TABLE IF EXISTS temp');
	$this->db->query('CREATE TEMPORARY TABLE temp AS 
					   (SELECT a.foo, b.goo, c.hoo 
					        FROM XYZ a, XYZ b, XYZ c
						WHERE a.id = b.a_id 
						AND b.id = c.b_id)');
	
	$crud->set_table('temp');
	$crud->set_primary_key('hoo');
	
	$output = $crud->render();
	$this->default_output($output);
	}

Fatal error: Uncaught exception 'Exception' with message 'The table name does not exist. Please check you database and try again.'

 

 

But it IS working since I created the table "temp" as normal table with just a placeholder column. So: Is this a bug or a feature?

 

 

Cheers

 

 

P.S.

If someone reads this and has a better idea to query multiple tables, I'm all ears! :)

 


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 26 November 2014 - 04:24 AM

Well the library cannot be moulded to check if such table exists or not. Grocery crud uses show tables command from mysql to determine the existance of the table. Show tables unfortunately dose not show up the temporary tables in the list. Hence there aint any way currently exists which allows to determine if temporary table exists or not. Hence when Oracle will incorporate the mechanism to determine the availibility of temporary tables.. then can the library be modified to work on the same.