Hello,
I'm coding my first module using the "Drupal 7 Module Development" for instruction (mimicking the authors' "Artwork" module example). My new module works fine except that after installation, all SQL queries toss a syntax error/exception because the actual SQL statement has the table name wrapped in curly braces. I'm implementing the hook_entity_info() API to establish my table_name.
For example: SELECT ..... FROM {table_name} base .....
I've drilled down several layers through the Dupal code base but after a few hours cannot locate the offending place where these curly braces are added. Also, the module installs fine and creates the intended tables in the database as expected (so it at least gets that SQL statement correct).
I'm hoping someone has a quick suggestion/solution or a place in which to drop in debug statements?
thanks!
JP
Comments
What does your code look
What does your code look like?
There are too many lines to
There are too many lines to reasonably post it and expect someone to read it all (controller, hooks, etc.).. I was just looking for some general hints about why Drupal would output a table name wrapped in curly braces and perhaps where to look or insert debug statements in the code.
I suspect that I should focus on my DrupalDefaultEntityController class extension and/or the hook_entity_info() implementation.
thanks,
What about the code that is
What about the code that is generating the query?
In all honesty, it sounds
In all honesty, it sounds like you are trying to alter core to get around a problem that's probably a result of doing some coding in a non-Drupaly way. You would be better off figuring out where your original problem lies, and fix that. Curly braces are necessary with the Drupal database API, as it allows for table prefixing, which in turn allows sharing between tables and whatnot. But it sounds like they went a little crazy through some code you've entered.
Contact me to contract me for D7 -> D10/11 migrations.
Thanks for the replies. I
Thanks for the replies. I don't intend to modify the core code, but rather trace in to the core code to find out where it decides to add (or leave) curly braces around the table name in the sql statements. I'll be sure to post the ultimate cause when I discover it so as to warn other programmers.
thanks,
If you are using the database
If you are using the database API correctly, the curly braces should not be an issue, hence the question your code.
OK, it seems like it was a
OK, it seems like it was a red herring: My actual problem was that I named one of my columns "desc" (for description) -- obviously it's a reserved SQL word.
I spent time chasing the curly braces issue because when Drupal threw the error, it contained the SQL statement before it went through the prefixTables() which included the curly braces. When I looked at other SQL statements (Devel module dump), they didn't include the curly braces.
I suppose the moral of my time-suck is not to get fixated on one cause early in the debugging process, and to double/triple check the premise especially if it's taking a significant amount of time.
Thanks for everyone's attention.
This helped me!
It wasn't a red herring for me; it was a valuable reference, thanks.
I took a Drupal dump of an entire SQL database and was trying to replicate the structure (just for examination) on a separate database. Drupal dumped all the tablenames with {curly braces} round them, and the other SQL engine wouldn't accept them, and I didn't know what they were for.
The comments on this page convinced me that it was a Drupal internal flexibility thing, and that I could just replace them with `backquotes` and it would work. And it did.
So thank you!