$names[$i] \n ";
}
}
if ($sql =~ /(table.*)/i) { #Is this "show tables"?
@names = $dbh->tables();
print "tables \n";
for ($i=0; $i<@names; $i++) {
print " |
---|
$names[$i] \n ";
}
}
if ($sql =~ /(column.?)(\s+from\s+)(\w+)/i #Is this "show columns"?
or $sql =~ /(desc)(\s+)(\w+)/i) { # or "desc columns"?
$request = $1; #Grab which type of request from the match above
$table = $3; #Grab the table name
$buf = $dbh->prepare("select * from $table limit 1");
$rc = $buf->execute();
$nameref = $buf->{'NAME'};
@names = @$nameref;
$typeref = $buf->{'TYPE'};
@types = @$typeref;
$lgthref = $buf->{'PRECISION'};
@lengths = @$lgthref;
$scleref = $buf->{'SCALE'};
@scales = @$scleref;
$nullref = $buf->{'NULLABLE'};
@nulls = @$nullref;
$buf->finish();
%descT = (1=>char,2=>numeric,3=>decimal,4=>integer,5=>smallint,6=>float,
7=>real,8=>double,9=>date,10=>time,11=>timestamp,12=>varchar,
-1=>longvarchar,-2=>binary,-3=>varbinary,-4=>longvarbinary,
-5=>bigint,-6=>tinyint,-7=>bit,-8=>wchar,-9=>wvchar,
-10=>wlgvchar);
%descN = (0=>'no',1=>'yes',2=>'unknown',''=>'no');
print " $table $request | type ";
print " | length | decimal | nulls? \n";
for ($i=0; $i<@names; $i++) {
print " | $names[$i] | $descT{$types[$i]} ";
print " | $lengths[$i] | $scales[$i] | $descN{$nulls[$i]}\n";
}
}
}
############################################################################
| | |