#!/usr/local/bin/perl

print <<EOF;

DROP TABLE IF EXISTS duptest;

CREATE TABLE duptest (
        c1      VARCHAR(1),
        c2      VARCHAR(1)
);

INSERT INTO duptest VALUES
EOF

for($i = 0; $i <= 255; $i++) {
  $ti = chr($i);
  $ti = q|\0|   if $i == 0;
  $ti = q|\"|   if $i == 34;
  $ti = q|\'|   if $i == 39;
  $ti = q|\\\\| if $i == 92;
  for($j = $i+1; $j <= 255; $j++) {
    $tj = chr($j);
    $tj = q|\0|   if $j == 0;
    $tj = q|\"|   if $j == 34;
    $tj = q|\'|   if $j == 39;
    $tj = q|\\\\| if $j == 92;
    printf( qq|  ("%s", "%s")%s\n|,
            $ti, $tj, ($i+$j!=509 ? ',' : ';') );
  }
}

print <<EOF;

DROP TABLE IF EXISTS duplist;

CREATE TABLE duplist (
        t1      INT,
        c1      VARCHAR(1),
        t2      INT,
        c2      VARCHAR(1)
);

INSERT INTO duplist
  SELECT DISTINCT
    ASCII(LOWER(c1)), LOWER(c1), ASCII(LOWER(c2)), LOWER(c2)
  FROM duptest
  WHERE c1 = c2
    AND ASCII(LOWER(c1)) < ASCII(LOWER(c2));

SELECT * FROM duplist
GROUP BY t2;

EOF
