Skip Menu |

This queue is for tickets about the DBD-CSV CPAN distribution.

Report information
The Basics
Id: 106529
Status: rejected
Priority: 0/
Queue: DBD-CSV

People
Owner: Nobody in particular
Requestors: blake.adkins [...] intel.com
Cc:
AdminCc:

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



Subject: Bug Report
Date: Tue, 18 Aug 2015 23:05:47 +0000
To: "bug-DBD-CSV [...] rt.cpan.org" <bug-DBD-CSV [...] rt.cpan.org>
From: "Adkins, Blake" <blake.adkins [...] intel.com>
Submitting a bug report with using -SELECT and when columns of the .csv file are reserved words in SQL. I have a case where a column is named "DESC" in the database, not SQL, it's being exported to a .csv file from. However, if I try to select the column in the SQL query using DBI, like SELECT "PT_ID,'DESC'" it doesn't complain but it returns something like PT_ID,DESC PT_1,DESC PT_2,DESC Instead of PT_ID,DESC PT_1,FOO PT_2,BAR. Let me know if I can provide more information. Thanks, Blake Adkins
Subject: wrong results when columns have reserved words in header
The problem here is not in DBD::CSV, but in SQL::Statement. DBD::CSV however offers you the tools to work around the issue. You can set your own column headers. $ cat test.csv id,count,desc,asc,row 1,2,foo,bar,10 -> Bad table or column name: 'desc' is a SQL reserved word! at /pro/lib/perl5/site_perl/5.22.0/SQL/Statement.pm line 88. ^^^^^^^^^^^^^ col_names skip_first_row By default DBD::CSV assumes that column names are stored in the first row of the CSV file and sanitizes them (see "raw_header" below). If this is not the case, you can supply an array ref of table names with the col_names attribute. In that case the attribute skip_first_row will be set to FALSE. If you supply an empty array ref, the driver will read the first row for you, count the number of columns and create column names like "col0", "col1", ...
Blaming SQL::Statement here is a bit to simple. DESC is a reserved word and it's not possible to use it as table/column name - writing as literal or not ... What you showed as workaround is not a workaround, it's the solution to this unfortunate situation. It's not a CSV bug, it's a glue bug - where SQL meets CSV. Another option for Adkins could be writing his own SQL dialect (https://metacpan.org/pod/SQL::Parser#dialect).
On Wed Aug 19 03:49:34 2015, REHSACK wrote: Show quoted text
> Blaming SQL::Statement here is a bit to simple. DESC is a reserved > word and it's not possible to use it as table/column name - writing as > literal or not ... > > What you showed as workaround is not a workaround, it's the solution > to this unfortunate situation. It's not a CSV bug, it's a glue bug - > where SQL meets CSV. > > Another option for Adkins could be writing his own SQL dialect > (https://metacpan.org/pod/SQL::Parser#dialect).
We can add a list of reserved words that would conflict with levels below (SQL::Statement) into the glue layer (DBD::CSV) that would automatically be quoted or replaced with something we could define right here and now
That's likely a follow-up for DBI::DBD::SqlEngine :) query me on freenode if you like ...
Subject: RE: [rt.cpan.org #106529] Bug Report
Date: Wed, 19 Aug 2015 15:39:56 +0000
To: "bug-DBD-CSV [...] rt.cpan.org" <bug-DBD-CSV [...] rt.cpan.org>
From: "Adkins, Blake" <blake.adkins [...] intel.com>
Jens, So is this an issue that doesn't currently have a solution? You mentioned writing my own SQL dialect, is that something that can be included in this script? I'd like to make it flexible if possible so the users don't have to think about not using the natural column names. Show quoted text
-----Original Message----- From: Jens Rehsack via RT [mailto:bug-DBD-CSV@rt.cpan.org] Sent: Wednesday, August 19, 2015 2:13 AM To: Adkins, Blake Subject: [rt.cpan.org #106529] Bug Report <URL: https://rt.cpan.org/Ticket/Display.html?id=106529 > That's likely a follow-up for DBI::DBD::SqlEngine :) query me on freenode if you like ...
Adkins, there are reserved words in a language which cannot be used to name user defined content: perl -e 'sub sub { print "Hello world\n" }; sub' You won't name this an issue of Perl, would you?
Subject: RE: [rt.cpan.org #106529] Bug Report
Date: Mon, 24 Aug 2015 15:34:15 +0000
To: "'bug-DBD-CSV [...] rt.cpan.org'" <bug-DBD-CSV [...] rt.cpan.org>
From: "Adkins, Blake" <blake.adkins [...] intel.com>
Using col_names, I've essentially patched the problem. If there exists a method in the future to avoid this I'll change my script. Thanks for the help here. Show quoted text
-----Original Message----- From: Jens Rehsack via RT [mailto:bug-DBD-CSV@rt.cpan.org] Sent: Wednesday, August 19, 2015 9:10 AM To: Adkins, Blake Subject: [rt.cpan.org #106529] Bug Report <URL: https://rt.cpan.org/Ticket/Display.html?id=106529 > Adkins, there are reserved words in a language which cannot be used to name user defined content: perl -e 'sub sub { print "Hello world\n" }; sub' You won't name this an issue of Perl, would you?