After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 589102 - GdaServerProvider requires quoted table names and field names.
GdaServerProvider requires quoted table names and field names.
Status: RESOLVED FIXED
Product: libgda
Classification: Other
Component: PostgreSQL provider
4.1.x
Other Linux
: Normal normal
: ---
Assigned To: malerba
gnome-db Maintainers
: 589103 (view as bug list)
Depends on: 589607 589822
Blocks: 587051
 
 
Reported: 2009-07-20 09:01 UTC by Murray Cumming
Modified: 2009-08-26 14:51 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gda-capitals-add-column.c (2.78 KB, patch)
2009-07-20 09:07 UTC, Murray Cumming
none Details | Review
Slightly modified version where gda_sql_identifier_quote() is used. (2.90 KB, text/x-csrc)
2009-07-20 11:34 UTC, malerba
  Details

Description Murray Cumming 2009-07-20 09:01:09 UTC
This test case shows that using GDA_SERVER_OPERATION_CREATE_TABLE and GDA_SERVER_OPERATION_ADD_COLUMN currently requires mixed-case SQL identifiers to be quoted. If not, lowercase table names or field names are created, as can be seen in PgAdmin3, for instance.

This is not a problem with the SQLite provider, as you can see by commenting out the alternative connection line.

Vivien mentioned on the mailing list that quoting should not be necessary with this API.
Comment 1 Murray Cumming 2009-07-20 09:06:01 UTC
*** Bug 589103 has been marked as a duplicate of this bug. ***
Comment 2 Murray Cumming 2009-07-20 09:07:17 UTC
Created attachment 138785 [details] [review]
gda-capitals-add-column.c
Comment 3 Murray Cumming 2009-07-20 09:09:31 UTC
Note that I left the working code in, and commenting out the code that shows the problem. Sorry:

  const char* table_name = "\"CapitalTest8\"";
  /* This creates a "capitaltest8" table instead of a "CapitalTest8" table: 
  const char* table_name = "CapitalTest8";
  */
Comment 4 malerba 2009-07-20 11:34:28 UTC
Created attachment 138807 [details]
Slightly modified version where gda_sql_identifier_quote() is used.

Using the GdaServerOperation object does not _require_ you to call gda_sql_identifier_quote() like you have to do with gda_connection_update_meta_store(), where you _have to_ or otherwise you may  not get the expected result.

This means that the SQL identifier string you passed using gda_server_operation_set_value_at() is used as-is, unchanged, in the resulting SQL actually being used.

So the example works as expected, the SQL being "CREATE TABLE CapitalTest8 ...", for which postgres creates a capitaltest8 named table. It does work with SQLite because SQLite implements a different set of rules.

Libgda can't assume someone using CapitalTest8 as a table name really means to keep the case sensitivity because this depends on the application's policy and is a matter of user/programmer choice (imagine if psql did this...)

Now if within Glom you you want to make sure CapitalTest8 creates a table where the case is kept, you need to call gda_sql_identifier_quote (..., TRUE) and pass that string to gda_server_operation_set_value_at(), as illustrated in the slightly modified version of your example.
Comment 5 Murray Cumming 2009-07-20 11:50:08 UTC
OK, please update the documentation to mention that you need to use  gda_sql_identifier_quote() there if you want it to create what you said you want to create.

> Libgda can't assume someone using CapitalTest8 as a table name really means to
> keep the case sensitivity because this depends on the application's policy and
> is a matter of user/programmer choice (imagine if psql did this...)

As I've said repeatedly (sorry for that, but I find this so awful), Why can't libgda just do what I say?
1. If the application or programmer wants to lowercase everything then they can. 
2. libgda should hide backend-specific quirks.

I see no need to impose SQL's inconsitency and weirdness on to libgda's API.
Comment 6 Murray Cumming 2009-07-20 11:58:47 UTC
(In reply to comment #4)
(imagine if psql did this...)

psql is a place to write SQL, so obviously quotes are part of that system. To prove that this API is a good idea, you'll need to come up with a better real-world example.
Comment 7 malerba 2009-07-20 12:03:33 UTC
Because the default in database applications ecosystem is to consider that the
user does not care about case sensitivity. User A can name a table MyTable and
user B name it mytable cand user C MYTABLE and they usually all speak of the
same object.

As Libgda is a _general purpose_ library (even for writing command line tools), it can't cut itself from that kind of
users/applications.

And even if the majority of users wanted the case sensitivity to be preserved,
the work needed to be done for the other users wo don't care about case
sensitivity would otherwise be enormous to be able to use Libgda.

The current API does on the contrary hide SQL's inconsitency and weirdness: use
gda_sql_identifier_quote() to do it an a database agnostic way. Of course
making this call could be done automatically but deciding to use TRUE or FALSE
as the last argument depend on the programmer.
Comment 8 Murray Cumming 2009-07-20 12:11:23 UTC
(In reply to comment #7)
> Because the default in database applications ecosystem is to consider that the
> user does not care about case sensitivity.

There are very few _users_ in the database application ecosytem. Real (non-techy) users have no idea of this issue.

Database developers are well aware of the problem and use quotes when writing SQL. libgda is not SQL so they'd expect it to be better behaved.

Maybe you could consider fixing this for a future parallel-installable libgda.
Comment 9 malerba 2009-07-20 12:15:23 UTC
Ok, here is what I propose: add a new GDA_CONNECTION_OPTIONS_KEEP_IDENTIFIERS_CASE option to gda_connection_open*() which a programmer can use to specify that all the SQL identifiers will have to be kept case sensitive whenever Libgda really manipulates them. This way it can be in 4.1.

What do you think?
Comment 10 Murray Cumming 2009-07-20 12:20:53 UTC
That would be a vast improvement that would greatly improve my mood and would make me very thankful.

"case" might not be the best name, because this is also an issue of spaces, etc.
Comment 11 malerba 2009-07-20 12:24:55 UTC
Ok, what about GDA_CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE (a bit long but who cares)?

Along with this I can add:
gda_meta_store_quote(const char*, GdaConnection *cnc)
and
gda_server_provider_quote (GdaServerProvider *provider, const char*), or
gda_connection_sql_identifier_quote(GdaConnection *cnc, const char*) or both.
Comment 12 Murray Cumming 2009-07-20 12:36:21 UTC
(In reply to comment #11)
> Ok, what about GDA_CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE (a bit
> long but who cares)?

That still mentions only case. Either is fine, I guess as long as what it actually means is documented. I can't think of a better name than SQL_IDENTIFIERS_AS_SPECIFIED, but that's silly.
 
> Along with this I can add:
> gda_meta_store_quote(const char*, GdaConnection *cnc)
> and
> gda_server_provider_quote (GdaServerProvider *provider, const char*), or
> g_connection_sql_identifier_quote(GdaConnection *cnc, const char*) or both.

gda_connection_quote(GdaConection* cnc, const char*) would be more consistent for that last one.

But I wonder when the GdaServerProvider is relevant? Isn't the GdaConnection enough to know what to do?
Comment 13 malerba 2009-07-20 12:42:28 UTC
> gda_connection_quote(GdaConection* cnc, const char*) would be more consistent
> for that last one.

Ok.

> But I wonder when the GdaServerProvider is relevant? Isn't the GdaConnection
> enough to know what to do?

Usually yes, but sometimes (for example for testing but not only) only a provider pointer is available, but I guess it's a corner case and there is no need for a specific API for this.

Also, if you need it for Glom, I think I can backport the work in LIBGDA_4.0 as well, so tell me.
Comment 14 Murray Cumming 2009-07-20 13:28:06 UTC
On second thoughts, a gda_server_provider_quote() would make sense _if_ it would be more efficient if I already have a GdaServerProvider. I have no objection to convenience API.

Yes, this would be welcome in libgda-4.0. You really should have an Amazon wish-list or suchlike.
Comment 15 malerba 2009-07-23 19:42:10 UTC
I've just pushed the changes implementing all this, both in master and LIBGDA_4.0 branches. Can ou check it?
Comment 16 Murray Cumming 2009-07-23 22:06:06 UTC
Thanks. It seems to work very well and already makes Glom better.

We seem to now have a problem discovering new fields that we added to tables such as "CapitalTest" but I will investigate tomorrow to see if it's a libgda or Glom problem.
Comment 17 Murray Cumming 2009-07-24 13:40:39 UTC
Getting the fields does not seem to work yet: Bug #589607
Comment 18 Murray Cumming 2009-08-19 20:44:46 UTC
There's still an issue with updating metadat after adding a field: Bug 589822