I misstyped something trying to make the message shorter.
 New piece of code below is "copy and paste".
 The variable $filecontent is printed into the file then, which I compared
 with another file created by mysqldump.
About placeholders, it is good idea but it won't change the output.


 (DBI version is 1.13)

 --------------------

 (
     PrintError => 0,
     RaiseError => 0
 );
 .......

  foreach my $table (@tablelist) {
   $filecontent .= "\n#\tTABLE $table \n";
   $filecontent .= createTableSQL ([$table],$dropifexists) unless ($include
 eq 'data');
   unless ($include eq 'structure') {
       $filecontent .= "\n#\tDUMPING DATA\n\n";
       my $query = "SELECT * FROM $table";
       my ($sth, $res) = prepare_execute($query);
       while (my @row = $sth->fetchrow_array){
        $filecontent .= "INSERT INTO $table VALUES ( ";
        my @rowdata;
        for (my $i = 0; $i < @row; $i++) {
         push @rowdata, $dbh->quote($row[$i]);
        }
        $filecontent .= join (', ', @rowdata);
        $filecontent .= ");\n";

       }
       $sth->finish;
   }
   $filecontent .=
 "\n#--------------------------------------------------------\n";
  }

 .......

 sub prepare_execute {
  my $sth = $dbh->prepare($_[0]) or bail_out ("Cannot prepare
 query:\n$query");
  my $res = $sth->execute()  or bail_out ("Cannot execute query:\n$query");
 return ($sth, $res)
 }

> ----- Original Message -----
> From: "Sterin, Ilya" <[EMAIL PROTECTED]>
> To: "LIBASOV IOANNIS" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> Sent: Tuesday, May 08, 2001 4:55 AM
> Subject: RE: quoting binaries (MYSQL)
>
>
> > First you are providing an arg to your execute, though I don't see you
> using
> > any placeholder.  See perldoc for prepare() and execute() statements, so
I
> > don't even know how you are able to run the script.  Do you have
> RaiseError
> > => 1 and PrintError => 1.  Also what is the error message you are
getting?
> > You never provided that to us.
> >
> > Ilya Sterin
> >
> >
> >
> > -----Original Message-----
> > From: LIBASOV IOANNIS [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, May 07, 2001 8:18 PM
> > To: Sterin Ilya; [EMAIL PROTECTED]
> > Subject: Re: quoting binaries (MYSQL)
> >
> >
> > Hi!
> > (Sorry for delay!)
> >
> > The fragment below shows how I made data dump of the table, containing
> > binary data.
> > Then, using editor (Ultraedit) I compared the content of the output file
> > with the file created by mysqldump.
> > The difference is that the DBI->quote() did not escape some characters
> that
> > were escaped by mysqldump. (for example double quotes or some characters
> > that I can not )
> > As the result, the file created by my script could not run.
> >
> >  foreach $table (@tablelist) {
> >       $sth = $dbh->prepare("SELECT * FROM $table");
> >       $sth->execute();
> >       while (my @row = $sth->fetchrow_array){
> >        $datadump .= "INSERT INTO $table VALUES ( ";
> >        my @rowdata;
> >        for (my $i = 0; $i < @row; $i++) {
> >         push @rowdata, $dbh->quote($row[$i]);
> >        }
> >        $datadump .= join (', ', @rowdata) . ");\n";
> >       }
> >       $sth->finish;
> >  }
> >
> >
> >
> > ----- Original Message -----
> > From: Sterin, Ilya <[EMAIL PROTECTED]>
> > To: 'Yannis Livassof ' <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> > Sent: Wednesday, May 02, 2001 4:03 PM
> > Subject: RE: quoting binaries (MYSQL)
> >
> >
> > > We need more code than (SELECT... and INSERT...).  How did you see the
> > funny
> > > unescaped character?  Did you print them out, in that case did you
> binmode
> > > STDOUT?
> > >
> > > Use trace() to see exactly what is going on.  Also an error message on
> > > insert would be very helpful to us.
> > >
> > > Ilya Sterin
> > >
> > > -----Original Message-----
> > > From: Yannis Livassof
> > > To: [EMAIL PROTECTED]
> > > Sent: 05/02/2001 3:28 AM
> > > Subject: quoting binaries (MYSQL)
> > >
> > > Hi!
> > >
> > > Does anybody knows how to quote the binarie fields properly using the
> > > DBI.pm (on Mysql)?
> > >
> > > I used "SELECT ..." ,
> > > then
> > > $dnh->quote(some data),
> > > then
> > > $dbh->do("INSERT ...")
> > > The last "do" leads to error.
> > >
> > >
> > > As I see, some funny characters selected from binary fields are not
> > > escaped. I compared it with the output generated with "mysqldump".
> > >
> > > Plese help!!!!!
> > >
> > > Yannis Livassov
>

Reply via email to