⚠ 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 specific table name - bug with fix



slav123

slav123
  • profile picture
  • Member

Posted 13 May 2012 - 23:13 PM

I have table called 'unlock' which is specific function name in MySQL. When I try to fetch data from it I'm getting this error.

SHOW COLUMNS FROM unlock
Filename: /Applications/MAMP/htdocs/cba_centenarysocial_z624/models/grocery_crud_model.php
Line Number: 353


quick fix is just to modify sources (grocery_crud_model - Line Number: 353):

from:

foreach($this->db->query("SHOW COLUMNS FROM {$this->table_name}`")->result() as $db_field_type)


to:
foreach($this->db->query("SHOW COLUMNS FROM `{$this->table_name}``")->result() as $db_field_type)



but in general i think better way is just use
$this->db->list_fields

slav123

slav123
  • profile picture
  • Member

Posted 13 May 2012 - 23:24 PM

and another small change required:

$select = "`{$this->table_name}`.*";


in line 52 [color=#000000][size=2]grocery_crud_model[/size][/color][color=#666600][size=2].[/size][/color][color=#000000][size=2]php[/size][/color]

in general this changes should be included in source code to avoid this kind of problems with table names...

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 14 May 2012 - 00:01 AM

Thank you for that, just fixed it https://github.com/scoumbourdis/grocery-crud/commit/77cb4a2c61579bf8b2c251c57264eace9958c186

The SHOW COLUMNS is used because it gives me more information about the database than $this->db->list_fields.

Thanks to mention it and thanks for the fix.

johnvanham

johnvanham
  • profile picture
  • Member

Posted 15 May 2012 - 17:32 PM

[quote name='slav123' timestamp='1336951445' post='1730']
and another small change required:

$select = "`{$this->table_name}`.*";


in line 52 [color=#000000][size=2]grocery_crud_model[/size][/color][color=#666600][size=2].[/size][/color][color=#000000][size=2]php[/size][/color]

in general this changes should be included in source code to avoid this kind of problems with table names...
[/quote]

I'm using a table prefix of 'sdb_' configured in codeignitor's configuration and this has been working fine until I tried the latest snapshot on github - this update breaks the SQL query and I get a SQL syntax error:

[i]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.*, (SELECT GROUP_CONCAT(DISTINCT sdb_boroughs.name) FROM sdb_boroughs LEFT JOIN' at line 1[/i]

[i]SELECT sdb_`sdb_records`.*, (SELECT GROUP_CONCAT(DISTINCT sdb_boroughs.name) FROM sdb_boroughs LEFT JOIN sdb_link_record_borough ON sdb_link_record_borough.borough_id = sdb_boroughs.id WHERE sdb_link_record_borough.record_id = `sdb_records`.id GROUP BY sdb_link_record_borough.record_id) AS borough, (SELECT GROUP_CONCAT(DISTINCT sdb_service_categories.name) FROM sdb_service_categories LEFT JOIN sdb_link_record_service_category ON sdb_link_record_service_category.category_id = sdb_service_categories.id WHERE sdb_link_record_service_category.record_id = `sdb_records`.id GROUP BY sdb_link_record_service_category.record_id) AS service_category FROM (`sdb_records`) LIMIT 25[/i]

Reverting line 52 back to;

$select = "{$this->table_name}.*";


..fixes this error. I'm not sure why but it seems to be adding the prefix on twice. But it wasn't before using ` quotes.

I'm defining my tables like this:

$this->crud->set_table($this->db->dbprefix('records'));


Just thought I should let you know!

Cheers.

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 15 May 2012 - 21:45 PM

Hello johnvanham and thanks to mention that.

Actually the db_prefix is a known issue of grocery CRUD ( http://www.grocerycrud.com/documentation/known-issues ) , and I am glad that till now you have figure out a way to use it. However the:


$select = "`{$this->table_name}`.*";


is a right thing to do so I will probably (not promising) try to have a normal fix so grocery CRUD will support the db_prefix with the normal way. It was in the plan to get rid of all the known issues of grocery CRUD as for the next two releases, so your post will also help me to solve similar problems.

Thanks

miamarti

miamarti
  • profile picture
  • Member

Posted 13 August 2012 - 12:32 PM

Hello friends,
My grocerycrud already with the corrections as the repository, however the problem still remains:
https://github.com/s...264eace9958c186

Please help me

>>>>>>>>>>>>>>>>>>>>>>>>


[b] A Database Error Occurred[/b]

Error Number: 1146
Table 'serv.usur' doesn't exist
SHOW COLUMNS FROM `usur`
Filename: C:\Eclipse_Arq_Fal\xamp\htdocs\emb\system\database\DB_driver.php
Line Number: 330