DBD::CSV and multi character separator

DBD::CSV and multi character separator

am 26.04.2007 23:34:04 von pathaksantosh

------=_Part_7128_32749930.1177623244104
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi,

I read on following site that DBD::CSV supports multi-character separator.
But I am not able to use it. my separator is |++|
http://www.annocpan.org/~JZUCKER/DBD-CSV-0.22/lib/DBD/CSV.pm

Even after setting sep_char to |++|, it doesn't work.
Am I missing something?

Thanks
- Santosh

------=_Part_7128_32749930.1177623244104--

Re: DBD::CSV and multi character separator

am 27.04.2007 10:19:41 von rroggenb

Hi,

can You show us a relevant code snippet (connecting and querying) and a snippet
of Your CSV-Data? Which kind of line separator are You using?

Best Regards

Robert

----

Santosh Pathak schrieb:
> Hi,
>
> I read on following site that DBD::CSV supports multi-character separator.
> But I am not able to use it. my separator is |++|
> http://www.annocpan.org/~JZUCKER/DBD-CSV-0.22/lib/DBD/CSV.pm
>
>
> Even after setting sep_char to |++|, it doesn't work.
> Am I missing something?
>
> Thanks
> - Santosh
>

--

===================================================
Robert Roggenbuck, M.A.
Konrad Zuse Zentrum fuer Informationstechnik Berlin
Takustr. 7 D-14195 Berlin
roggenbuck@zib.de
http://www.mathematik-21.de/
http://www.zib.de/

Buero:
Universitaet Osnabrueck
Fachbereich Mathematik / Informatik
Albrechtstr. 28a Fon: ++49 (0)541/969-2735
D-49069 Osnabrueck Fax: ++49 (0)541/969-2770
http://www.mathematik.uni-osnabrueck.de/
===================================================

RE: :CSV and multi character separator

am 27.04.2007 15:35:04 von Philip.Garrett

Santosh Pathak wrote:
> Hi,
>=20
> I read on following site that DBD::CSV supports multi-character
> separator. But I am not able to use it. my separator is |++|
>
http://www.annocpan.org/~JZUCKER/DBD-CSV-0.22/lib/DBD/CSV.pm annocpan.org/%7EJZUCKER/DBD-CSV-0.22/lib/DBD/CSV.pm>
>=20
> Even after setting sep_char to |++|, it doesn't work.
> Am I missing something?

The current released version of DBD::CSV does not support this. The
author says he's added support to the next version, but I don't see it
on CPAN yet.

The problem is that DBD::CSV uses Text::CSV_XS to parse the CSV files --
and that module does not support multi-char separators. The newer
version (not yet released) allows you to specify your own CSV parser,
bypassing that limitation.

- Philip

RE: :CSV and multi character separator

am 27.04.2007 15:41:12 von Philip.Garrett

Garrett, Philip (MAN-Corporate) wrote:
> Santosh Pathak wrote:
>> Hi,
>>=20
>> I read on following site that DBD::CSV supports multi-character
>> separator. But I am not able to use it. my separator is |++|
>>=20
>
http://www.annocpan.org/~JZUCKER/DBD-CSV-0.22/lib/DBD/CSV.pm > annocpan.org/%7EJZUCKER/DBD-CSV-0.22/lib/DBD/CSV.pm>
>>=20
>> Even after setting sep_char to |++|, it doesn't work.
>> Am I missing something?
>=20
> The current released version of DBD::CSV does not support this. The
> author says he's added support to the next version, but I don't see it
> on CPAN yet.

Oops! Wrong on that one. The current released version DOES have that
support, using the csv_class or csv_csv parameters.

Now the problem becomes finding a CSV parser that will do that, and
matches the interface of Text::CSV_XS. I haven't found one yet...

- Philip

Re: :CSV and multi character separator

am 27.04.2007 16:33:29 von pathaksantosh

------=_Part_18071_26905187.1177684409832
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Thanks for the reply!

Yes. Author has mentioned about its availability in next version. But I was
wondering how it is not yet released because comment was made in 2005.

BTW I have a follow-up question,

I would like to use a DBI that works on flat files (with custom separator
i.e. |++|) and supports following,

1. Multiple joins in single SELECT statement (Note its not just one LEFT or
RIGHT, there could be multiple joins)
2. Tables having self relationship
3. Supports Table aliases (Not a hard requirement)

I tried DBD::AnyData, DBD::CSV, DBD::RAM but none of them meet my
requirements.

Does somebody know any DBD for flat files that will meet above requirements?

Thanks
- Santosh

On 4/27/07, Garrett, Philip (MAN-Corporate)
wrote:
>
> Santosh Pathak wrote:
> > Hi,
> >
> > I read on following site that DBD::CSV supports multi-character
> > separator. But I am not able to use it. my separator is |++|
> >
> http://www.annocpan.org/~JZUCKER/DBD-CSV-0.22/lib/DBD/CSV.pm > annocpan.org/%7EJZUCKER/DBD-CSV-0.22/lib/DBD/CSV.pm>
> >
> > Even after setting sep_char to |++|, it doesn't work.
> > Am I missing something?
>
> The current released version of DBD::CSV does not support this. The
> author says he's added support to the next version, but I don't see it
> on CPAN yet.
>
> The problem is that DBD::CSV uses Text::CSV_XS to parse the CSV files --
> and that module does not support multi-char separators. The newer
> version (not yet released) allows you to specify your own CSV parser,
> bypassing that limitation.
>
> - Philip
>

------=_Part_18071_26905187.1177684409832--

Re: DBD::CSV and multi character separator

am 27.04.2007 16:52:31 von pathaksantosh

------=_Part_18643_13436487.1177685551018
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Here is my code,

use DBI;

$dbh = DBI->connect(qq{DBI:CSV:});
$dbh->{'csv_tables'}->{'host'} = {
'col_names' => ["Id", "Name", "IP", "OS", "VERSION", "ARCH"],
'sep_char' => "|++|",
'eol' => "\n",
'file' => './foo'
};
my $sth = $dbh->prepare("SELECT * FROM host");
$sth->execute() or die "Cannot execute: " . $sth->errstr();
while (my $row = $sth->fetchrow_hashref) {
print("Id = ", $row->{'Id'});
print("\nName=", $row->{'Name'});
print("\nIP=", $row->{'IP'});
print("\nOS=", $row->{'OS'});
print("\nVersion=", $row->{'VERSION'});
print("\nARCH=", $row->{'ARCH'});
}
$sth->finish();
$dbh->disconnect();

and my data,

100|++|abc|++|1.2.3.4|++|SunOS|++|5.10|++|sparc
101|++|abd|++|1.2.3.5|++|SunOS|++|5.10|++|sparc
102|++|abe|++|1.2.3.6|++|SunOS|++|5.10|++|sparc
103|++|abf|++|1.2.3.7|++|SunOS|++|5.10|++|sparc

Column separator is (|++|) and Line separator is newline (\n)

Thanks
- Santosh

On 4/27/07, Robert Roggenbuck wrote:
>
> Hi,
>
> can You show us a relevant code snippet (connecting and querying) and a
> snippet
> of Your CSV-Data? Which kind of line separator are You using?
>
> Best Regards
>
> Robert
>
> ----
>
> Santosh Pathak schrieb:
> > Hi,
> >
> > I read on following site that DBD::CSV supports multi-character
> separator.
> > But I am not able to use it. my separator is |++|
> > http://www.annocpan.org/~JZUCKER/DBD-CSV-0.22/lib/DBD/CSV.pm<
> http://www.annocpan.org/%7EJZUCKER/DBD-CSV-0.22/lib/DBD/CSV. pm>
> >
> >
> > Even after setting sep_char to |++|, it doesn't work.
> > Am I missing something?
> >
> > Thanks
> > - Santosh
> >
>
> --
>
> ===================================================
> Robert Roggenbuck, M.A.
> Konrad Zuse Zentrum fuer Informationstechnik Berlin
> Takustr. 7 D-14195 Berlin
> roggenbuck@zib.de
> http://www.mathematik-21.de/
> http://www.zib.de/
>
> Buero:
> Universitaet Osnabrueck
> Fachbereich Mathematik / Informatik
> Albrechtstr. 28a Fon: ++49 (0)541/969-2735
> D-49069 Osnabrueck Fax: ++49 (0)541/969-2770
> http://www.mathematik.uni-osnabrueck.de/
> ===================================================
>

------=_Part_18643_13436487.1177685551018--

Re: DBD::CSV and multi character separator

am 27.04.2007 17:15:19 von rroggenb

This looks clean too me - and Philip points already to the main reason for which
Your code fails.

BTW: Did You get an error message while connecting / querying or did You just
get no results?

Greetings

Robert

-----


Santosh Pathak schrieb:
> Here is my code,
>
> use DBI;
>
> $dbh = DBI->connect(qq{DBI:CSV:});
> $dbh->{'csv_tables'}->{'host'} = {
> 'col_names' => ["Id", "Name", "IP", "OS", "VERSION", "ARCH"],
> 'sep_char' => "|++|",
> 'eol' => "\n",
> 'file' => './foo'
> };
> my $sth = $dbh->prepare("SELECT * FROM host");
> $sth->execute() or die "Cannot execute: " . $sth->errstr();
> while (my $row = $sth->fetchrow_hashref) {
> print("Id = ", $row->{'Id'});
> print("\nName=", $row->{'Name'});
> print("\nIP=", $row->{'IP'});
> print("\nOS=", $row->{'OS'});
> print("\nVersion=", $row->{'VERSION'});
> print("\nARCH=", $row->{'ARCH'});
> }
> $sth->finish();
> $dbh->disconnect();
>
> and my data,
>
> 100|++|abc|++|1.2.3.4|++|SunOS|++|5.10|++|sparc
> 101|++|abd|++|1.2.3.5|++|SunOS|++|5.10|++|sparc
> 102|++|abe|++|1.2.3.6|++|SunOS|++|5.10|++|sparc
> 103|++|abf|++|1.2.3.7|++|SunOS|++|5.10|++|sparc
>
> Column separator is (|++|) and Line separator is newline (\n)
>
> Thanks
> - Santosh
>
> On 4/27/07, Robert Roggenbuck
> wrote:
>>
>> Hi,
>>
>> can You show us a relevant code snippet (connecting and querying) and a
>> snippet
>> of Your CSV-Data? Which kind of line separator are You using?
>>
>> Best Regards
>>
>> Robert
>>
>> ----
>>
>> Santosh Pathak schrieb:
>> > Hi,
>> >
>> > I read on following site that DBD::CSV supports multi-character
>> separator.
>> > But I am not able to use it. my separator is |++|
>> > http://www.annocpan.org/~JZUCKER/DBD-CSV-0.22/lib/DBD/CSV.pm<
>> http://www.annocpan.org/%7EJZUCKER/DBD-CSV-0.22/lib/DBD/CSV. pm>
>> >
>> >
>> > Even after setting sep_char to |++|, it doesn't work.
>> > Am I missing something?
>> >
>> > Thanks
>> > - Santosh
>> >
>>
>> --
>>
>> ===================================================
>> Robert Roggenbuck, M.A.
>> Konrad Zuse Zentrum fuer Informationstechnik Berlin
>> Takustr. 7 D-14195 Berlin
>> roggenbuck@zib.de
>> http://www.mathematik-21.de/
>> http://www.zib.de/
>>
>> Buero:
>> Universitaet Osnabrueck
>> Fachbereich Mathematik / Informatik
>> Albrechtstr. 28a Fon: ++49 (0)541/969-2735
>> D-49069 Osnabrueck Fax: ++49 (0)541/969-2770
>> http://www.mathematik.uni-osnabrueck.de/
>> ===================================================
>>
>

--

===================================================
Robert Roggenbuck, M.A.
Konrad Zuse Zentrum fuer Informationstechnik Berlin
Takustr. 7 D-14195 Berlin
roggenbuck@zib.de
http://www.mathematik-21.de/
http://www.zib.de/

Buero:
Universitaet Osnabrueck
Fachbereich Mathematik / Informatik
Albrechtstr. 28a Fon: ++49 (0)541/969-2735
D-49069 Osnabrueck Fax: ++49 (0)541/969-2770
http://www.mathematik.uni-osnabrueck.de/
===================================================