MySQL, for one, allows creation of fields and tables with names containing spaces, matching reserved words, etc. To use them in queries, they need to be quoted (with backticks for MySQL, double-quotes for Postgres). Right now, Views doesn't do the quoting, so such fields and tables cannot be exposed to Views. The attached patch is a start towards supporting this (I expect there are more areas that will need to be changed to support this).

CommentFileSizeAuthor
views-quotes.patch3.62 KBmikeryan
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikeryan’s picture

For context, this arose from Table Wizard bug #408094: Handle column names with spaces.

merlinofchaos’s picture

I'm leery of even looking at this because the Drupal coding standard requires that you avoid reserved words for your tables.

mikeryan’s picture

The purpose of the Table Wizard module is to expose non-Drupal tables (such as exports from another CMS, or spreadsheet data) to Views. We can't count on the rest of the world using Drupal coding standards...

Thanks.

esmerel’s picture

Status: Needs work » Closed (won't fix)

No work done on this in more than a year.

scotwith1t’s picture

Project: Views (for Drupal 7) » Table Wizard
Version: 6.x-2.3 » 6.x-1.3
Category: bug » feature
Status: Closed (won't fix) » Active

I'm reactivating this in hopes that someone will be saved the trouble of finding out the data they imported to MYSQL, which accepts spaces in the column names without problem, then went and pulled up in TW with no issues, went to analyzing the data and going to pull up the view and alas, nothing is there...what was more confusing to me was the fact that the pager rendered just fine with the empty text just above it. I agree with Earl though that this should be headed off by TW before it even gets to that point. When you analyze the table with TW, couldn't it simply check for unacceptable characters (like spaces in my case)? I understand the issue now and can completely avoid in the future by naming my data columns correctly, but thought maybe it was worth a shot to reassign, recategorize as a feature request and see what happens. I don't think patching views is the answer though.

x-lette’s picture

Instead of patching views, tw and whatelse, you could just create a VIEW (within mysql/postgresql/...) with a similar name, selecting all columns and translating bad column names to good ones (SELECT `bad name` AS good_name ...). Given your base table doesn't change it's structure (which in fact would make re-analyzing the table in tw essential) you could handle your table as usual and access it with tw/views nevertheless.
VIEWs are great! :)

13rac1’s picture

Note: There is a Drupal 8.x feature request for backticks: #1426084: Provide backtick escaping for MySQL in DB abstraction layer.

Does it make this request a dupe?