Subject: Where can I get converters for the pod?

    perl comes with a program pod2man and another one called
    pod2html. Both reside in the pod/ subdirectory of the perl source
    tree. The current version of perl (5.001L) installs both programs
    by default.


=head2 I don't understand how you retrieve the data from a SELECT Query with MySQL Perl.

Precanned reply:

    read the README

    read the manpage

    read the FAQ that comes with MysqlPerl

    read the examples in t/mysql.t or t/mysql2.t

subscribe to the mysql@tcx.se mailing list.

=head2 How do I get the names of the fields after a listfields?

Please, read the manpage. Try 'perldoc Mysql'.

=head2 Where can I find more documentation?

Mysql.pm IS the manpage in pod format. If you're on UNIX you should be
able to read it with 'man Mysql'. On other operating systems try
'perldoc Mysql'. Also, the test script, t/msql.t might help you to sort
things out. The most recent addition is the pmsql program which may
also help you to learning by example.

=head2 HPUX compilation goes wrong!!!

     From: Yiorgos Adamopoulos <Y.Adamopoulos@noc.ntua.gr>

     I successfully compiled MysqlPerl for a HP817 (HP-UX 9.04/s800) using Perl5.002,
     msql-1.0.14 and gcc-2.7.2.  I added CC_ONLY = -fPIC to site.mm after running
     setup.

=head2 How do I retrieve fields by name?

The internal fetchhash routine is quite good. If you need speed, you
should hardcode your column names into a hash slice. Everything else
is a terrible waste.

		     closure:  8 secs ( 7.47 usr  0.03 sys =  7.50 cpu)
	  hashslice via name: 10 secs ( 9.51 usr  0.04 sys =  9.55 cpu)
	  internal_fetchhash:  7 secs ( 7.05 usr  0.03 sys =  7.08 cpu)
       brute force fetchhash: 15 secs (13.90 usr  0.05 sys = 13.95 cpu)
     hashslice via constants:  6 secs ( 5.57 usr  0.02 sys =  5.59 cpu)

     #!/usr/bin/perl

     use Mysql;
     my $db = Mysql->Connect("","mod");
     $sth = $db->Query("select * from mods");


     sub Mysql::Statement::brute_fetchhash {
	 my $self = shift;
	 my %hash;
	 @hash{ $self->name } = $self->FetchRow and \%hash;
     }

     sub Mysql::Statement::gimme_a_fetchhash_routine {
	 my $self = shift;
	 my @z = $sth->name;
	 sub { my %hash; @hash{@z} = $self->FetchRow and \%hash;};
     }

     use Benchmark;

     timethese(20, {
     'hashslice via constants' => q{
	 $sth->DataSeek(0);
	 while (@row{qw/modid userid maillistid chapterid seqdummy statd stats statl stati description changed changedby/} = $sth->FetchRow){
	     $X = $row{modid};
	     print "$X\n" ;
	 }
     },

     '     hashslice via name' => q{
	 $sth->DataSeek(0);
	 while (@row{$sth->name} = $sth->FetchRow){
	     $X = $row{modid};
	     print "$X\n" ;
	 }
     },

     '  brute force fetchhash' => q{
	 $sth->DataSeek(0);
	 while ($hashref = $sth->brute_fetchhash){
	     $X = $hashref->{modid};
	     print "$X\n" ;
	 }
     },
     '                closure' => q{
	 $sth->DataSeek(0);
	 $clos = $sth->gimme_a_fetchhash_routine;
	 while ($hashref = &$clos){
	     $X = $hashref->{modid};
	     print "$X\n" ;
	 }
     },
     '     internal_fetchhash' => q{
	 $sth->DataSeek(0);
	 while (%hash = $sth->fetchhash){
	     $X = $hash{modid};
	     print "$X\n" ;
	 }
     },
     });


=head2 Dynamic Loading

Hello I am running XXX and would really like to use Mysqlperl but I am
getting this error message.

 Can't load module Mysql, dynamic loading not available in this perl.
   (You may need to build a new perl executable which either supports
	dynamic loading or has the Mysql module statically linked into it.)
  at /usr/lib/perl5/site_perl/Mysql.pm line 56
 BEGIN failed--compilation aborted at ./sql.pl line 5.

There is a manpage dedicated to building and installing modules:
ExtUtils::MakeMaker. The long answer is in there. The short answer is:
run 'make perl' in the MysqlPerl build directory. The third answer is,
get an operating system that supports dynamic loading. With Linux it's
already quite standard to have dynamic loading, and so is with many
other OSs. Check out the newgroups for your OS and consult the FAQs
there.


=head2 How can I construct an insert statement from an array?

The icc routine below should do what you want. It's hardly tested and
I'm reluctant to add it to the distribution. But feel free to convince
me that including it is a good thing.

    #!/usr/bin/perl -w
    use Mysql;
    use strict;

    sub Mysql::icc {
	my($db,$table,@fields)=@_;
	my($s,@types)=$db->listfields($table) or return;
	if (@fields){
	    # The user wants to input the fields in a different order
	    my(@tfields,@ttypes,%tfields);
	    @tfields = $s->name;
	    @ttypes = $s->type;
	    @tfields{@tfields} = @ttypes;
	    @types = @tfields{@ttypes};
	} else {
	    # They are gonna give the arguments in table's order
	    @fields = $s->name;
	    @types = $s->type;
	}
	# return a subroutine reference.
	sub {
	    my(@arr)=@_;
	    return join " ",
	    "insert into $table values (",
	    join(
		 ",",
		 map {
		     defined $arr[$_] ?
			 $types[$_] == &Mysql::REAL_TYPE
			     ||
			 $types[$_] == &Mysql::INT_TYPE ?
			     $arr[$_]+0 :
				 Mysql->quote($arr[$_]) :
				     "NULL"
				 }
		 0..$#types
		),
		     ")\n";
	}
    }

    # Example for usage:
    {
	my $dbh=Mysql->connect("","test");
	my $f=$dbh->icc("pwent");
	my(@info,$query,$sth);
	while (@info = getpwent()) {
	    print $query =&$f(@info);
	    $sth = $dbh->query($query) or die Mysql->errmsg;
	}
    }
