Skip Menu |

This queue is for tickets about the SQL-Statement CPAN distribution.

Report information
The Basics
Id: 34121
Status: resolved
Priority: 0/
Queue: SQL-Statement

People
Owner: REHSACK [...] cpan.org
Requestors: IKEGAMI [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.15
Fixed in: (no value)



Subject: Confuses literals with identifiers
SQL::Statement successfully parses quoted SQL identifiers (e.g. 'SELECT "my_field" FROM "MyTable"'), but fails to handle them properly. It considers the entire literal, quotes included, to be the identifier. As a result, table '"MyTable"' is considered different from table 'MyTable', and field '"my_field"' is considered from field 'my_field'. This bug makes it impossible to use quoted identifiers and to work with tables and fields whose names are reserved words. The problem exists in 1.15 and has probably been present since quoted identifiers were introduced. e.g. The following statement fails since it can't find the field '"set"' when the field 'set' exists: SELECT id, gid, card, "set", illus, num FROM Print e.g. Given my $dbh = DBI->connect('dbi:CSV:'); $dbh->{csv_tables}{Order}{file} = 'Order.csv'; the following creates the wrong file since SQL::Statement reports the table name is '"Order"': CREATE TABLE "Order" ( ... ) And the list goes on and on. The issue was originally brought up on PerlMonks. The following node contains code that produce an error as a result of this bug: http://www.perlmonks.org/?node_id=673399 No patch provided since the fix isn't trivial and could very well break backwards compatibility. See http://www.perlmonks.org/?node_id=673590
Could you please try if 1.16_02 fixes your problems? The patches from RT 15688 (https://rt.cpan.org/Ticket/Display.html?id=15688): »Columns aliased with double quotes are a fatal error« has been applied and the description was similar.
Subject: Re: [rt.cpan.org #34121] Confuses literals with identifiers
Date: Thu, 1 Jan 2009 23:52:58 -0500
To: bug-SQL-Statement [...] rt.cpan.org
From: "Eric Brine" <ikegami [...] adaelis.com>

Message body is not shown because sender requested not to inline it.

Message body is not shown because sender requested not to inline it.

On Thu, Jan 1, 2009 at 6:51 PM, Jens Rehsack via RT < bug-SQL-Statement@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=34121 > > > Could you please try if 1.16_02 fixes your problems? > The patches from RT 15688 > (https://rt.cpan.org/Ticket/Display.html?id=15688): »Columns aliased > with double quotes are a fatal error« has been applied and the > description was similar. >
I'm getting a 404 trying to download 1.16_02 (and 1.16_03). I've attached the test that I would have run. With 1.15, the output is: Show quoted text
>perl test.pl
SQL::Statement v1.15 DBD::CSV::st execute failed: Execution ERROR: No such column 'TEST."text"'. [for Statement " SELECT "text" FROM test "] at test.pl line 47. The desired output is foo bar baz Test passed.
CC: undisclosed-recipients:;, ikegami [...] adaelis.com
Subject: Re: [rt.cpan.org #34121] Confuses literals with identifiers
Date: Thu, 01 Jan 2009 21:46:56 -0800
To: bug-SQL-Statement [...] rt.cpan.org
From: dubzed <dubzed [...] gmail.com>
Hi Ikegami, jZed, here. Unless I'm mistaken you are running afowl of this line in SQL::Statement::Syntax "A delimited identifier is *never* equal to a regular identifer (so "foo" and foo are two different columns). But don't do that :-)." Delimited column names are expected to have quotes around them in the .csv file and the same name without quotes around them is not treated as a delimited identifier (if it didn't save the quotes around it, how would it know was delimited the next time)? If all you want is to be able to name a column with a SQL keyword, try "DROP KEYWORD text" and you can use that as a column name. -- Jeff ikegami@adaelis.com via RT wrote: Show quoted text
> Queue: SQL-Statement > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=34121 > > > On Thu, Jan 1, 2009 at 6:51 PM, Jens Rehsack via RT < > bug-SQL-Statement@rt.cpan.org> wrote: > >
>> <URL: https://rt.cpan.org/Ticket/Display.html?id=34121 > >> >> Could you please try if 1.16_02 fixes your problems? >> The patches from RT 15688 >> (https://rt.cpan.org/Ticket/Display.html?id=15688): »Columns aliased >> with double quotes are a fatal error« has been applied and the >> description was similar. >> >>
> > I'm getting a 404 trying to download 1.16_02 (and 1.16_03). I've attached > the test that I would have run. > > With 1.15, the output is: >
> >perl test.pl
> SQL::Statement v1.15 > > DBD::CSV::st execute failed: > Execution ERROR: No such column 'TEST."text"'. > > [for Statement " > SELECT "text" > FROM test > "] at test.pl line 47. > > The desired output is > > foo > bar > baz > Test passed. > > > > ------------------------------------------------------------------------ > > On Thu, Jan 1, 2009 at 6:51 PM, Jens Rehsack via RT > <bug-SQL-Statement@rt.cpan.org <mailto:bug-SQL-Statement@rt.cpan.org>> > wrote: > > <URL: https://rt.cpan.org/Ticket/Display.html?id=34121 > > > Could you please try if 1.16_02 fixes your problems? > The patches from RT 15688 > (https://rt.cpan.org/Ticket/Display.html?id=15688): »Columns aliased > with double quotes are a fatal error« has been applied and the > description was similar. > > > I'm getting a 404 trying to download 1.16_02 (and 1.16_03). I've > attached the test that I would have run. > > With 1.15, the output is: >
> >perl test.pl
> SQL::Statement v1.15 > > DBD::CSV::st execute failed: > Execution ERROR: No such column 'TEST."text"'. > > [for Statement " > SELECT "text" > FROM test > "] at test.pl line 47. > > The desired output is > > foo > bar > baz > Test passed. >
CC: bug-SQL-Statement [...] rt.cpan.org
Subject: Re: [rt.cpan.org #34121] Confuses literals with identifiers
Date: Fri, 2 Jan 2009 02:14:35 -0500
To: dubzed <dubzed [...] gmail.com>
From: "Eric Brine" <ikegami [...] adaelis.com>
On Fri, Jan 2, 2009 at 12:46 AM, dubzed <dubzed@gmail.com> wrote: Show quoted text
> jZed, here. Unless I'm mistaken you are running afowl of this line in > SQL::Statement::Syntax > "A delimited identifier is *never* equal to a regular identifer (so "foo" > and foo are two different columns). But don't do that :-)." >
Yes I am. I didn't realize the behaviour for which I filed a bug report was documented. (if it didn't save the quotes around it, how would it know was delimited the Show quoted text
> next time)? >
I don't understand what you are saying. What needs to know how the table or field name was encoded, and why does it need to know? Even if I buy into the premise that there is a need to know how the table or field name was encoded, that's doesn't prevent two equivalent encodings of the same name from being treated as the same name. - Eric "ikegami" Brine
Subject: Re: [rt.cpan.org #34121] Confuses literals with identifiers
Date: Fri, 2 Jan 2009 02:58:51 -0500
To: bug-SQL-Statement [...] rt.cpan.org
From: "Eric Brine" <ikegami [...] adaelis.com>

Message body is not shown because sender requested not to inline it.

Message body is not shown because sender requested not to inline it.

On Thu, Jan 1, 2009 at 11:52 PM, Eric Brine <ikegami@adaelis.com> wrote: Show quoted text
> On Thu, Jan 1, 2009 at 6:51 PM, Jens Rehsack via RT < > bug-SQL-Statement@rt.cpan.org> wrote: >
>> <URL: https://rt.cpan.org/Ticket/Display.html?id=34121 > >> >> Could you please try if 1.16_02 fixes your problems? >> The patches from RT 15688 >> (https://rt.cpan.org/Ticket/Display.html?id=15688): »Columns aliased >> with double quotes are a fatal error« has been applied and the >> description was similar. >>
> > I'm getting a 404 trying to download 1.16_02 (and 1.16_03). I've attached > the test that I would have run. > > With 1.15, the output is: >
> >perl test.pl
> SQL::Statement v1.15 > > DBD::CSV::st execute failed: > Execution ERROR: No such column 'TEST."text"'. > > [for Statement " > SELECT "text" > FROM test > "] at test.pl line 47. > > The desired output is > > foo > bar > baz > Test passed. > >
I am able to download it now. It introduced a bug. Show quoted text
>perl test.pl
SQL::Statement v1.16_02 DBD::CSV::db prepare failed: SQL ERROR: Bad table or column name 'text' is a SQL reserved word! [for Statement " SELECT "text" FROM TestTable "] at test.pl line 42. Note that 'text' was quoted, and thus not a reserved word. If I sidestep the new bug by changing '"text"' to '"foo"' (as in the attached files), the bug I reported is gone. Show quoted text
>perl test2.pl
SQL::Statement v1.16_02 foo bar baz Test passed. The documentation needs to be fixed, however. It currently claims "A delimited identifier is *never* equal to a regular identifer (so "foo" and foo are two different columns). But don't do that :-)." But that's just been fixed - Eric "ikegami" Brine
CC: bug-SQL-Statement [...] rt.cpan.org
Subject: Re: [rt.cpan.org #34121] Confuses literals with identifiers
Date: Fri, 02 Jan 2009 00:05:10 -0800
To: Eric Brine <ikegami [...] adaelis.com>
From: dubzed <dubzed [...] gmail.com>
Eric Brine wrote: Show quoted text
> On Fri, Jan 2, 2009 at 12:46 AM, dubzed <dubzed@gmail.com > <mailto:dubzed@gmail.com>> wrote: > > jZed, here. Unless I'm mistaken you are running afowl of this > line in SQL::Statement::Syntax > "A delimited identifier is *never* equal to a regular identifer > (so "foo" and foo are two different columns). But don't do that :-)." > > > Yes I am. I didn't realize the behaviour for which I filed a bug > report was documented. > > (if it didn't save the quotes around it, how would it know was > delimited the next time)? > > > I don't understand what you are saying. What needs to know how the > table or field name was encoded, and why does it need to know? Even if > I buy into the premise that there is a need to know how the table or > field name was encoded, that's doesn't prevent two equivalent > encodings of the same name from being treated as the same name.
Undelimited names are case insensitve, therefore the column names q{foo}. q{FOO}, and q{FoO} are the same. Which of those should q{SELECT "foo" FROM ...} refer to? The SQL standard, AFAIK doesn't define that. Different implementations do it differently or not at all. (Correct me if you know differently, I looked it all up when I wrote this into S::S, but don't have the references handy). What I define in S::S is that q{"foo"} is always q{"foo"} and never q{anything else}. That way the delimted identifier is case sensitive and the undelimited isn't as per the standard. And therefore S::S expects to see the quote marks in the column name in the .csv file if it is to find it under a delimited name. Seem like a bug? Maybe, but I'm not sure there's a standard way of handling it and given the limits of meta-data-less .csv files, I'm not sure what other option I have without violating case-sensitivity rules which would seem like a much bigger bug to me. Does that make any more sense? -- Jeff Show quoted text
> : > - Eric "ikegami" Brine >
Subject: Re: [rt.cpan.org #34121] Confuses literals with identifiers
Date: Fri, 02 Jan 2009 13:25:17 -0800
To: Eric Brine <ikegami [...] adaelis.com>, bug-SQL-Statement [...] rt.cpan.org, Jens Rehsack <rehsack [...] web.de>
From: dubzed <dubzed [...] gmail.com>
Eric Brine wrote: Show quoted text
> This means that keywords can never be used as field names with > SQL::Statement 1.15.
As I pointed out earlier and as is mentioned IIRC in the docs, one way to use keywords as fieldnames is to use a "DROP KEYWORD foo" statement which allows you to use keywords as column names. Another is to manually set $dbh-> {csv_tables}->{TABLE}->{column_names}. Show quoted text
> This means that spaces can never be present in an identifier unless if > also starts and ends with quotes. This sucks.
No other implementation allows you (or should if it pretends to be valid) to put spaces in column names without delimiting them with quotes. How it stores them internall is its business and the fact that you can see how .csv stores it is kind of irrelevant. Show quoted text
> > You want quoting to denote case sensitivity, so literal q{"foo"} > should represent identifier q{foo} and nothing else. >
Well, unfortunately your intuition here is not the established standard, I don't have the full stuff on hand, but here's part of the story [verbatim from Martin Gruber and Joe Celko (who is on the standards committee and whom I have talked to in person about this),_ SQL Instant Reference_, Sybex] "A regular and a delimited identifier are equal if they contain the same characters, taking case into account, but first converting the regular (but not the delimited) identifier to all uppercase letters. In effect a delimited identifier that contains lowercase letters can never equal a regular identifier although it may equal another delimited one." So that would kind of leave your choice of having it represent q{foo} out on a limb. At least one of the major RDBMS handles it this way with only upper-case matches, another handles it the way you'd like, another handles it as I do by not allowing equations between delimited and regular identifiers. If you think things are as simple as treating q{"foo"} and q{foo} the same, how would you handle this perfectly valid syntax: q{CREATE TABLE bar ("foo" integer, FOO text)} ... q{SELECT "foo" AS foo1, FoO AS foo2 .FROM bar.} If there were no indication in the .csv file that the first of those is delimited, how would the select statement know which to retrieve? I understand that you don't like the way things operate but in this case, you haven't shown that my way of doing it breaks any standard or that you have a solution which would work without breaking the standard. I have made many sloppy decisions in S::S and you've caught a bunch of them. This isn't one of those cases. -- Jeff
CC: bug-SQL-Statement [...] rt.cpan.org, "Jens Rehsack" <rehsack [...] web.de>
Subject: Re: [rt.cpan.org #34121] Confuses literals with identifiers
Date: Fri, 2 Jan 2009 17:36:51 -0500
To: dubzed <dubzed [...] gmail.com>
From: "Eric Brine" <ikegami [...] adaelis.com>

Message body is not shown because sender requested not to inline it.

Message body is not shown because sender requested not to inline it.

Message body is not shown because sender requested not to inline it.

Message body is not shown because sender requested not to inline it.

On Fri, Jan 2, 2009 at 4:25 PM, dubzed <dubzed@gmail.com> wrote: Show quoted text
> Eric Brine wrote: >
>> This means that spaces can never be present in an identifier unless if >> also starts and ends with quotes. This sucks. >>
> No other implementation allows you (or should if it pretends to be valid) > to put spaces in column names without delimiting them with quotes.
That's not what I said. Let's use an example: It's impossible to address field q{foo bar} with SQL::Statement. In another implementation, you'd use q{"foo bar"}. In SQL::Statement, that means something else. "A regular and a delimited identifier are equal if they contain the same Show quoted text
> characters, taking case into account, but first converting the regular (but > not the delimited) identifier to all uppercase letters. In effect a > delimited identifier that contains lowercase letters can never equal a > regular identifier although it may equal another delimited one."
I have no problem with that. I didn't know the specifics. According to that passage, literal q{"FOO"} should equal literal q{foo} and literal q{FOO}. That's not the case in SQL::Statement 1.15 (See attached test3.) It's equal to neither. If you think things are as simple as treating q{"foo"} and q{foo} the same, Show quoted text
> how would you handle this perfectly valid syntax: q{CREATE TABLE bar ("foo" > integer, FOO text)} ... q{SELECT "foo" AS foo1, FoO AS foo2 .FROM bar.} > If there were no indication in the .csv file that the first of those is > delimited, how would the select statement know which to retrieve?
It can't, and this it should give an error. It's possible to have a query that's syntactically valid but cannot be executed. I can't even execute your CREATE TABLE in either MySQL or SQLite ("duplicate column name" for both). What does need to work is SELECT foo, bar as "foo" FROM baz I haven't suggested anything that would prevent that from working. Incidentally, that doesn't work either! (See attached test4.) SQL::Statement v1.15 DBD::CSV::db prepare failed: SQL ERROR: Bad table or column name 'bar AS ?QI0?' has chars not alphanumeric or underscore! [for Statement " SELECT foo, bar AS "foo" FROM TestTable4 "] at C:\Documents and Settings\ikegami\Desktop\New Folder\test4.pl line 42. Show quoted text
> I understand that you don't like the way things operate but in this case, > you haven't shown that my way of doing it breaks any standard or that you > have a solution which would work without breaking the standard.
If I have a column named q{foo}, I cannot access it with q{"foo"} using SQL::Statement. If I have a column named q{foo bar}, I cannot access it using SQL::Statement. If I have a column named q{text}, I cannot access it using SQL::Statement. So which is it? - The standard doesn't have a method of accessing those columns. - SQL::Statement implement the method of accessing those columns. - I don't know how to craft an SQL statement to access those columns.
CC: IKEGAMI [...] cpan.org, Dan [...] dwright.org
Subject: Re: [rt.cpan.org #34121] Confuses literals with identifiers
Date: Fri, 2 Jan 2009 18:36:12 -0500
To: bug-SQL-Statement [...] rt.cpan.org
From: "Eric Brine" <ikegami [...] adaelis.com>
2009/1/2 ikegami@adaelis.com via RT <bug-SQL-Statement@rt.cpan.org> Show quoted text
> > If I have a column named q{foo}, I cannot access it with q{"foo"} using > SQL::Statement. > If I have a column named q{foo bar}, I cannot access it using > SQL::Statement. > If I have a column named q{text}, I cannot access it using SQL::Statement. > > So which is it? > - The standard doesn't have a method of accessing those columns. > - SQL::Statement implement the method of accessing those columns. > - I don't know how to craft an SQL statement to access those columns.
That should be - The standard doesn't have a method of accessing those last two columns. - SQL::Statement doesn't implement the standard method of accessing those last two columns. - I don't know how to craft an SQL statement to access those last two columns.
CC: bug-SQL-Statement [...] rt.cpan.org, Jens Rehsack <rehsack [...] web.de>
Subject: Re: [rt.cpan.org #34121] Confuses literals with identifiers
Date: Fri, 02 Jan 2009 20:40:58 -0800
To: Eric Brine <ikegami [...] adaelis.com>
From: dubzed <dubzed [...] gmail.com>
The most common cases of using delimiters to access table and column names that would otherwise be invalid (e.g. at table name of "test.csv" or a column named "has space" or "text") are handled by S::S as shown in the attached test in which S::S works the same as SQLite and better than MySQL. So everything you ask about is supported in terms of the SQL syntax. What isn't supported is accessing files that were not created with SQL syntax but were instead created by another process or by hand. In those cases you need to either edit the file, change the process, or munge the column names with $dbh->{csv_tables}. If you know of a way that would support both SQL created names and hand-created names and still object when undelimited invalid names are used, please let me know. Jeff Eric Brine wrote: Show quoted text
> > > On Fri, Jan 2, 2009 at 4:25 PM, dubzed <dubzed@gmail.com > <mailto:dubzed@gmail.com>> wrote: > > Eric Brine wrote: > > This means that spaces can never be present in an identifier > unless if also starts and ends with quotes. This sucks. > > No other implementation allows you (or should if it pretends to be > valid) to put spaces in column names without delimiting them with > quotes. > > > That's not what I said. Let's use an example: It's impossible to > address field q{foo bar} with SQL::Statement. In another > implementation, you'd use q{"foo bar"}. In SQL::Statement, that means > something else. > > "A regular and a delimited identifier are equal if they contain > the same characters, taking case into account, but first > converting the regular (but not the delimited) identifier to all > uppercase letters. In effect a delimited identifier that contains > lowercase letters can never equal a regular identifier although it > may equal another delimited one." > > > I have no problem with that. I didn't know the specifics. According to > that passage, literal q{"FOO"} should equal literal q{foo} and literal > q{FOO}. That's not the case in SQL::Statement 1.15 (See attached > test3.) It's equal to neither. > > If you think things are as simple as treating q{"foo"} and q{foo} > the same, how would you handle this perfectly valid syntax: > q{CREATE TABLE bar ("foo" integer, FOO text)} ... q{SELECT "foo" > AS foo1, FoO AS foo2 .FROM bar.} If there were no indication in > the .csv file that the first of those is delimited, how would the > select statement know which to retrieve? > > > It can't, and this it should give an error. It's possible to have a > query that's syntactically valid but cannot be executed. I can't even > execute your CREATE TABLE in either MySQL or SQLite ("duplicate column > name" for both). What does need to work is > > SELECT foo, bar as "foo" FROM baz > > I haven't suggested anything that would prevent that from working. > Incidentally, that doesn't work either! (See attached test4.) > > SQL::Statement v1.15 > > DBD::CSV::db prepare failed: SQL ERROR: Bad table or column name > 'bar AS ?QI0?' has chars not alphanumeric or underscore! > > [for Statement " > SELECT foo, bar AS "foo" > FROM TestTable4 > "] at C:\Documents and Settings\ikegami\Desktop\New > Folder\test4.pl line 42. > > > > I understand that you don't like the way things operate but in > this case, you haven't shown that my way of doing it breaks any > standard or that you have a solution which would work without > breaking the standard. > > > If I have a column named q{foo}, I cannot access it with q{"foo"} > using SQL::Statement. > If I have a column named q{foo bar}, I cannot access it using > SQL::Statement. > If I have a column named q{text}, I cannot access it using SQL::Statement. > > So which is it? > - The standard doesn't have a method of accessing those columns. > - SQL::Statement implement the method of accessing those columns. > - I don't know how to craft an SQL statement to access those columns. >
#!/usr/bin/perl use warnings; use strict; use DBI; my ($user,$pass) = qw( jeff xxx ); test($_) for qw( dbi:CSV: dbi:SQLite: dbi:mysql:database=test ); sub test { my $dsn = shift; my $dbh = DBI->connect( $dsn, $user, $pass, { RaiseError => 1, PrintError => 0, AutoCommit => 1, }); if( $dsn =~ /mysql/ ) { # NOTE : mysql only uses double quotes as delims if in ANSI mode # $dbh->do($_) for split(/;\n/,q{ SET GLOBAL TRANSACTION ISOLATION LEVEL SERIALIZABLE; SET GLOBAL sql_mode = 'ANSI' }); } $dbh->do($_) for split(/;\n/, q{ DROP TABLE IF EXISTS test; CREATE TABLE test ("name with spaces" INT, "text" TEXT); INSERT INTO test VALUES (3, 'foo' ) }); print "$dsn\n"; print " delimited column names :ok!\n" if 'foo' eq $dbh->selectrow_array(q{ SELECT "text" FROM test WHERE "name with spaces" = 3 } ); $dbh->do($_) for split(/;\n/, q{ DROP TABLE IF EXISTS "test.csv"; CREATE TABLE "test.csv" ("name with spaces" INT, "text" TEXT); INSERT INTO "test.csv" VALUES (3, 'bar' ) }); # NOTE : mysql fails this, it doesn't support "test.csv" as a table name # even if delimited, this seems like one of the most likely and useful # uses of delimited identifiers with S::S # print " delimited table names :ok!\n" if 'bar' eq $dbh->selectrow_array(q{ SELECT "text" FROM "test.csv" WHERE "name with spaces" = 3 } ); } __END__
CC: bug-SQL-Statement [...] rt.cpan.org, "Jens Rehsack" <rehsack [...] web.de>
Subject: Re: [rt.cpan.org #34121] Confuses literals with identifiers
Date: Sat, 3 Jan 2009 02:24:54 -0500
To: dubzed <dubzed [...] gmail.com>
From: "Eric Brine" <ikegami [...] adaelis.com>
On Fri, Jan 2, 2009 at 11:40 PM, dubzed <dubzed@gmail.com> wrote: Show quoted text
> The most common cases of using delimiters to access table and column names > that would otherwise be invalid (e.g. at table name of "test.csv" or a > column named "has space" or "text") are handled by S::S as shown in the > attached test
No it doesn't. The attached test works with a column named q{"has space"}, not q{has space} Show quoted text
---BEGIN--- """name with spaces""","""text""" 3,bar ---END--- should be
---BEGIN--- "name with spaces","text" 3,bar ---END---
CC: bug-SQL-Statement [...] rt.cpan.org, Jens Rehsack <rehsack [...] web.de>
Subject: Re: [rt.cpan.org #34121] Confuses literals with identifiers
Date: Fri, 02 Jan 2009 23:35:32 -0800
To: Eric Brine <ikegami [...] adaelis.com>
From: dubzed <dubzed [...] gmail.com>
Eric Brine wrote: Show quoted text
> > > On Fri, Jan 2, 2009 at 11:40 PM, dubzed <dubzed@gmail.com > <mailto:dubzed@gmail.com>> wrote: > > The most common cases of using delimiters to access table and > column names that would otherwise be invalid (e.g. at table name > of "test.csv" or a column named "has space" or "text") are handled > by S::S as shown in the attached test > > > No it doesn't. The attached test works with a column named q{"has > space"}, not q{has space}
You are talking about what the column is named in the text file. I am talking about how the column is referred to in the syntax. One of the points of S::S is to allow similar kinds of syntax to be used as is used in other implementations. It accomplishes that. Because you don't like how the resulting text file looks has nothing to do with how well or poorly the SQL syntax is implemented. Show quoted text
> > ---BEGIN--- > """name with spaces""","""text""" > 3,bar > ---END--- > > should be > > ---BEGIN--- > "name with spaces","text" > 3,bar > ---END--- >
If it was that way, when S::S opened the file, how would it know that it should not object to "name with spaces' - or do you want it not to check for valid names at all? -- Jeff
CC: bug-SQL-Statement [...] rt.cpan.org, "Jens Rehsack" <rehsack [...] web.de>
Subject: Re: [rt.cpan.org #34121] Confuses literals with identifiers
Date: Sat, 3 Jan 2009 02:45:53 -0500
To: dubzed <dubzed [...] gmail.com>
From: "Eric Brine" <ikegami [...] adaelis.com>
[ I rushed reply, so I'm redoing it. ] On Fri, Jan 2, 2009 at 11:40 PM, dubzed <dubzed@gmail.com> wrote: Show quoted text
> The most common cases of using delimiters to access table and column names > that would otherwise be invalid (e.g. at table name of "test.csv" or a > column named "has space" or "text") are handled by S::S as shown in the > attached test in which S::S works the same as SQLite
No it doesn't. When SQLite is used, a column named q{has space} is created. When SQL::Statement is used, a column named q{"has space"} is created. Show quoted text
---BEGIN--- """name with spaces""","""text""" 3,bar ---END--- should be
---BEGIN--- "name with spaces","text" 3,bar ---END--- So everything you ask about is supported in terms of the SQL syntax. SQL::Statement supports the *syntax*, but the *semantics* are different. That's the bug I'm reporting. If you know of a way that would support both SQL created names and
> hand-created names and still object when undelimited invalid names are used, > please let me know.
You said you wanted it to behave like in the passage you quoted, so what's stopping you from doing that? If it's unquoted, make it uppercase (literal q{foo} becomes identifier q{FOO}). If it's quoted, keep the case (literal q{"foo"} becomes identifier q{foo}).
CC: bug-SQL-Statement [...] rt.cpan.org, "Jens Rehsack" <rehsack [...] web.de>
Subject: Re: [rt.cpan.org #34121] Confuses literals with identifiers
Date: Sat, 3 Jan 2009 06:35:42 -0500
To: dubzed <dubzed [...] gmail.com>
From: "Eric Brine" <ikegami [...] adaelis.com>
On Sat, Jan 3, 2009 at 2:35 AM, dubzed <dubzed@gmail.com> wrote: Show quoted text
> Eric Brine wrote: >
No it doesn't. The attached test works with a column named q{"has space"}, Show quoted text
>> not q{has space} >>
> > You are talking about what the column is named in the text file. I am > talking about how the column is referred to in the syntax. One of the > points of S::S is to allow similar kinds of syntax to be used as is used in > other implementations. It accomplishes that. Because you don't like how > the resulting text file looks has nothing to do with how well or poorly the > SQL syntax is implemented.
This bug report is not about the syntax. I don't know why you keep bringing that up. Are you saying the problem is in DBD::CSV, that it should parse the SQL identifier to extract the column name? Show quoted text
> ---BEGIN---
>> """name with spaces""","""text""" >> 3,bar >> ---END--- >> >> should be >> >> ---BEGIN--- >> "name with spaces","text" >> 3,bar >> ---END--- >> >>
> If it was that way, when S::S opened the file, how would it know that it > should not object to "name with spaces' - or do you want it not to check for > valid names at all? >
I don't understand the question. S::S should object to column names it can't handle. S::S shouldn't object to column names it can handle. q{name with spaces} is a valid column name. It would appear as q{"name with spaces"} in a CSV file, but S::S need not ever know that. It would appear as q{"name with spaces"} in an SQL statement. Do you really not know the difference between a literal and an identifier? In Perl, "foo bar" is a 9 character literal that represents a 7 character long string. In CSV, "foo bar" is a 9 character literal that represents a 7 character long column name. In SQL, "foo bar" is a 9 character literal that represents a 7 character long column name. In S::S, "foo bar" is a 9 character literal that represents a 9 character long column name. This is the bug I'm reporting. Eric "ikegami" Brine
CC: dubzed <dubzed [...] gmail.com>, bug-SQL-Statement [...] rt.cpan.org
Subject: Re: [rt.cpan.org #34121] Confuses literals with identifiers
Date: Sat, 03 Jan 2009 12:12:26 +0000
To: Eric Brine <ikegami [...] adaelis.com>
From: Jens Rehsack <rehsack [...] web.de>
Hi Eric, hi Jeff, I read your entire mail tree and must give up understanding your arguments. But I tried the 2 submitted tests Eric provided with 1.16_03 - test3 works, test4 don't. I just ask myself, why does Eric modify the csv_tables in the DBD::CSV-Instance? Eric: SELECT "MY COL WITH SPACES" FROM "MY TABLE WITH SPACES" will select a column q{MY COL WITH SPACES} (as one identifier) from table q{MY TABLE WITH SPACES}, regardless how they are internally represented. If you want to demonstrate an SQL::Statement bug, please don't modify in DBD::CSV, use SQL::Statement as described in http://search.cpan.org/perldoc?SQL::Statement::Structure to create the tables, insert some data and dump them. This time I will do it and add a test for it - it was just for the next time(s). Best regards, Jens
CC: Eric Brine <ikegami [...] adaelis.com>, Jens Rehsack <rehsack [...] web.de>
Subject: Re: [rt.cpan.org #34121] Confuses literals with identifiers
Date: Sat, 03 Jan 2009 10:51:15 -0800
To: bug-SQL-Statement [...] rt.cpan.org
From: dubzed <dubzed [...] gmail.com>
ikegami@adaelis.com via RT wrote: Show quoted text
> Queue: SQL-Statement > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=34121 > > > On Sat, Jan 3, 2009 at 2:35 AM, dubzed <dubzed@gmail.com> wrote: > >
>> Eric Brine wrote: >> >>
> No it doesn't. The attached test works with a column named q{"has space"}, >
>>> not q{has space} >>> >>>
>> You are talking about what the column is named in the text file. I am >> talking about how the column is referred to in the syntax. One of the >> points of S::S is to allow similar kinds of syntax to be used as is used in >> other implementations. It accomplishes that. Because you don't like how >> the resulting text file looks has nothing to do with how well or poorly the >> SQL syntax is implemented. >>
> > > This bug report is not about the syntax. I don't know why you keep bringing > that up. > >
Because we are discussing S::S whose purpose is to provide SQL syntax support. It is used for many purposes only some of which apply to DBD::CSV - other DBDs, parsing of SQL dumps, etc. And what you are reporting is not symantics, it is an internal storage detail. Show quoted text
> Are you saying the problem is in DBD::CSV, that it should parse the SQL > identifier to extract the column name? > > >
>> ---BEGIN--- >>
>>> """name with spaces""","""text""" >>> 3,bar >>> ---END--- >>> >>> should be >>> >>> ---BEGIN--- >>> "name with spaces","text" >>> 3,bar >>> ---END--- >>> >>> >>>
>> If it was that way, when S::S opened the file, how would it know that it >> should not object to "name with spaces' - or do you want it not to check for >> valid names at all? >> >>
> > I don't understand the question. > S::S should object to column names it can't handle. > S::S shouldn't object to column names it can handle.\ >
That's absurd. SQL Statement should behave like every other RDBMS in this respect - it should not accept identifiers that are not valid in the SQL standard. It should tell the user their syntax is broken and refuse to use them. Otherwise it would be completely incompatible with other RDBMSs. Show quoted text
> q{name with spaces} is a valid column name. >
No it is not a SQL '92 valid column unless it is delimited. In what possible sense could you use the word "valid" for it? Show quoted text
> It would appear as q{"name with spaces"} in a CSV file, but S::S need not > ever know that. >
No it can't appear like that in the file. If it appears like that in the file there is no way for S::S to treat it as a valid identifier because it isn't one. (well it can appear in the file but you can't expect S::S to handle it unless you munge it first). Show quoted text
> It would appear as q{"name with spaces"} in an SQL statement. > > Do you really not know the difference between a literal and an identifier? >
Do you really not know the difference between a SQL valid identifier and one that isn't? -- Jeff Show quoted text
> In Perl, "foo bar" is a 9 character literal that represents a 7 character > long string. > In CSV, "foo bar" is a 9 character literal that represents a 7 character > long column name. > In SQL, "foo bar" is a 9 character literal that represents a 7 character > long column name. > In S::S, "foo bar" is a 9 character literal that represents a 9 character > long column name. > This is the bug I'm reporting. > > Eric "ikegami" Brine > > > > ------------------------------------------------------------------------ > > > > On Sat, Jan 3, 2009 at 2:35 AM, dubzed <dubzed@gmail.com > <mailto:dubzed@gmail.com>> wrote: > > Eric Brine wrote: > > No it doesn't. The attached test works with a column named > q{"has space"}, not q{has space} > > > You are talking about what the column is named in the text file. > I am talking about how the column is referred to in the syntax. > One of the points of S::S is to allow similar kinds of syntax to > be used as is used in other implementations. It accomplishes > that. Because you don't like how the resulting text file looks > has nothing to do with how well or poorly the SQL syntax is > implemented. > > > This bug report is not about the syntax. I don't know why you keep > bringing that up. > > Are you saying the problem is in DBD::CSV, that it should parse the > SQL identifier to extract the column name? > > > ---BEGIN--- > """name with spaces""","""text""" > 3,bar > ---END--- > > should be > > ---BEGIN--- > "name with spaces","text" > 3,bar > ---END--- > > > If it was that way, when S::S opened the file, how would it know > that it should not object to "name with spaces' - or do you want > it not to check for valid names at all? > > > I don't understand the question. > S::S should object to column names it can't handle. > S::S shouldn't object to column names it can handle. > > q{name with spaces} is a valid column name. > It would appear as q{"name with spaces"} in a CSV file, but S::S need > not ever know that. > It would appear as q{"name with spaces"} in an SQL statement. > > Do you really not know the difference between a literal and an identifier? > In Perl, "foo bar" is a 9 character literal that represents a 7 > character long string. > In CSV, "foo bar" is a 9 character literal that represents a 7 > character long column name. > In SQL, "foo bar" is a 9 character literal that represents a 7 > character long column name. > In S::S, "foo bar" is a 9 character literal that represents a 9 > character long column name. > This is the bug I'm reporting. > > Eric "ikegami" Brine >
CC: bug-SQL-Statement [...] rt.cpan.org, "Jens Rehsack" <rehsack [...] web.de>
Subject: Re: [rt.cpan.org #34121] Confuses literals with identifiers
Date: Sat, 3 Jan 2009 22:56:41 -0500
To: dubzed <dubzed [...] gmail.com>
From: "Eric Brine" <ikegami [...] adaelis.com>
On Sat, Jan 3, 2009 at 1:51 PM, dubzed <dubzed@gmail.com> wrote: Show quoted text
> Because we are discussing S::S whose purpose is to provide SQL syntax > support. It is used for many purposes only some of which apply to DBD::CSV > - other DBDs, parsing of SQL dumps, etc. And what you are reporting is > not symantics, it is an internal storage detail.
Yes, it's an internal storage detail that leaks out of interface into its users such as DBD::CSV. That's what need to be fixed. S::S should object to column names it can't handle. Show quoted text
>> S::S shouldn't object to column names it can handle. >>
> That's absurd. SQL Statement should behave like every other RDBMS in this > respect - it should not accept identifiers that are not valid in the SQL > standard.
That's exactly what I said, so how is it absurd? q{name with spaces} is a valid column name. Show quoted text
>>
> No it is not a SQL '92 valid column unless it is delimited. In what > possible sense could you use the word "valid" for it?
No! q{name with spaces} is a valid table name in MySQL, SQLite, ProgreSQL, Oracle, DB2, MS SQL, etc. All I'm asking is the same for S::S. Yes, to refer to the name, you need to delimit it in the SQL (q{"name with spaces"}), but the table name is q{name with spaces}. Show quoted text
> It would appear as q{"name with spaces"} in a CSV file, but S::S need not
>> ever know that. >>
> No it can't appear like that in the file. If it appears like that in the > file there is no way for S::S to treat it as a valid identifier because it > isn't one.
You say that, but 1.16_03 proves you wrong. And there is a valid literal for it: q{"name with spaces"} Show quoted text
> Do you really not know the difference between a SQL valid identifier and > one that isn't? >
Do you know the difference between a name and a literal? q{"name with spaces"} is a literal (appears in the SQL) for the name q{name with spaces}.
CC: bug-SQL-Statement [...] rt.cpan.org, "Jens Rehsack" <rehsack [...] web.de>
Subject: Re: [rt.cpan.org #34121] Confuses literals with identifiers
Date: Sat, 3 Jan 2009 23:13:37 -0500
To: dubzed <dubzed [...] gmail.com>
From: "Eric Brine" <ikegami [...] adaelis.com>
What would you think if HTML treated q{abc} differently than q{a&#98;c}? What would you think if Perl treated q{"foo\nbar"} differently than q{"foo\012bar"}? What would you think if S::S treated q{"FOO"} differently than q{foo}? literals appears in source strings they represent -------------------------- ---------------------- q{a&#98;c} (HTML) abc q{"foo\nbar"} (Perl) (something with newlines) q{"name"} (SQL) name name (SQL) NAME q{"name"} (S::S) "name" XXX name (S::S) name(?) XXX(?) Unless you have a question for me, there's really nothing further I can say short of writing the fix. Fortunately, Jens Rehsack seems to understand and already wrote it as 1.16_03. Thanks. - Eric
The original problem is solved and the submitter provides some additional tests to allow fix some more issues test-driven :)