Re: Loading calendar database

Jan Eden <[email protected]>
Newsgroups gmane.comp.db.mysql.perl
Message-ID <r02010400-1037-40DBFA33533711D986BD000A959B4026@[10.149.23.154]>
Hi Peter,

Peter Pentchev wrote on 21.12.2004:

>Disclaimer: none of the below pieces of code were actually tested :)
>
>Well then, you might want to try something like:
>
>my ($month, $day, $sth);
>
>$sth = $dbh->prepare("INSERT INTO tablename(datecolumn) VALUES
>(?)"); foreach $month (keys %{$hash}) { foreach $day (keys
>%{$hash->{$month}->[1]}) { $sth->execute(sprintf('2004-%02d-%02d',
>$month, $day)) or die "Inserting 2004/$month/$day failed:
>".$dbh->errstr();
>}
>}
>$sth->finish();
>
>This will have a slight disadvantage with older versions of MySQL,
>where prepare() is not really implemented in the server, but
>simulated by the DBD driver, but it would have the advantage of
>being portable to other SQL servers.  Alternatively, you might
>decide to use MySQL's extended insert capabilities and insert all
>the dates in one fell swoop:
>
>@dates = (); foreach $month (keys %{$hash}) { foreach $day (keys
>%{$hash->{$month}->[1]}) { push @dates, sprintf('"2004-%02d-%02d"',
>$month, $day);
>}
>}
>$dbh->do('INSERT INTO tablename(datecolumn) VALUES ('. join(', ',
>@dates).')') or die $dbh->errstr();
>
>With this option, you might want to make a query per month though,
>or you might run into limits such as the MySQL client query buffer
>size or something similar.
>
>Hope this helps :)

It certainly does. Thanks!

- Jan
-- 
I'd never join any club that would have the likes of me as a member. - Groucho Marx

-- 
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe:    http://lists.mysql.com/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.