pp wrote:

> > Nope, but see explanation earlier. Older versions of Midgard did allow
> > creating duplicate or empty article names. If you want to I can create
> > an SQL query that will find them, or explain how to disable the check in
> > midgard-php4.
>
> No! I do not want to reinstall midgard-php4. All but not this.
>  Do not make me to spend all night at work :))

See attached script. You'll need to comment out the marked line to make
it actually work, this way you can test before you run it. It works for
me here.

Emile
#!/usr/bin/perl

use DBI;
use Getopt::Std;

getopts('td:u:p:U:P:');

$database = $opt_d ? $opt_d : "midgard";
$user = $opt_u ? $opt_u : "midgard";
$password = $opt_p ? $opt_p : "midgard";

######

$driver=0;
foreach (DBI->available_drivers) {
   ($_ eq 'mysql') && ($driver = 1) && last;
}
if (!$driver) { fail("The MySQL DBD driver is not installed"); }

$dsn = "DBI:mysql:database=$database";
($dbh = DBI->connect($dsn, $user, $password)) || fail("Failed to connect as $user");

$sth = $dbh->prepare("SELECT id FROM article WHERE name=''");
($sth && $sth->execute()) || die "Could not select\n";

while (($id) = $sth->fetchrow_array()) {
   $uname = uniqname();
   if ($uname eq '') {
      print "Couldn't find unique name for article $id\n";
      next;
   }

   $cmd = "UPDATE article SET name='$uname' WHERE id=$id";
   print "$cmd\n";
   ## UNCOMMENT THIS ## $dbh->do($cmd);
}

my $seq = 0;
sub uniqname
{
my $lsth;
my $lid;
my $attempts = 100;

   while (1) {
      $seq++;
      $attempts--;
      $name = "<empty.$seq>";

      $lsth = $dbh->prepare("SELECT id FROM article WHERE name='$name'");
      ($lsth && $lsth->execute()) || return '';

      ($lid) = $lsth->fetchrow_array();
      if (!$lid) { return $name; }
      if (!$attempts) { return ''; }
   }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to