Re: dbd::csv with col_names but insert / delete / update fail



aclhkaclhk wrote:
I have a csv file. I defined the column names inside the perl script
but "sql insert" does not work.
That's because you defined the column names for a table called "passwd" and then tried to do an insert on a table called "b". You need to define the column names for the table you are trying to insert into.

--
Jeff

If the csv has column names, the
script (without col names defined) works.

sql select works on both csv with or without column names.

***** not working ****
/root/csv/db/b
1,peter
2,wilson

insert.pl
use DBI;
$dbh = DBI->connect("DBI:CSV:f_dir=/root/csv/
db;csv_sep_char=",";csv_quote_char=;csv_eol=\n")
or die "Cannot connect: " . $DBI::errstr;
$dbh->{'csv_tables'}->{'passwd'} = {'col_names' => ["id","passwd"]};
$dbh->do("insert into b (id, passwd) values (10,3333)");

[root@localhost csv]# perl insert.pl

Execution ERROR: No such column 'B.ID' called from insert.pl at 6.

***** working without error*******
id,passwd
1,peter
2,wilson

insert.pl
use DBI;
$dbh = DBI->connect("DBI:CSV:f_dir=/root/csv/
db;csv_sep_char=",";csv_quote_char=;csv_eol=\n")
or die "Cannot connect: " . $DBI::errstr;
$dbh->do("insert into b (id, passwd) values (10,3333)");




.



Relevant Pages

  • dbd::csv with col_names but insert / delete / update fail
    ... I have a csv file. ... I defined the column names inside the perl script ... sql select works on both csv with or without column names. ... use DBI; ...
    (perl.dbi.users)
  • RE: Question with DBI versus PERL
    ... Question with DBI versus PERL ... statement at once (if I parse my SQL file) my pl/sql will work? ... All spool statements will turn to Perl print() calls. ... I want to know how can i run this sql script with DBI. ...
    (perl.dbi.users)
  • RE: how to invoke .sql file from dbi
    ... recommended changing all the SQL*Plus scripts into DBI calls. ... The sql statements are SELECT statements and we are expecting plain (no ... to just point the dbi to a sql file and dbi taking care of it. ...
    (perl.dbi.users)
  • Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
    ... T> expected a mature library like DBI to behave like this. ... I learned plenty about the perl side of things from her posts. ... closely represent the SQL idea of a null. ... trivially easy to perform bulk loads using the DB's particular ...
    (comp.lang.perl.misc)
  • Re: What is the logic of storing XML in a Database?
    ... will trap most major errors. ... In fact one does, XML. ... CSV is useful for unloading an SQL table into a text ...
    (comp.databases.theory)