1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
my $database = 'database';
my $table = 'table';
(
#{
# error => sub { get('username') ne 'myuser' ? "Access denied -- username must be 'myuser'." : undef },
#},
#
# The queries below are sent by various connectors as part of connection establishment.
# We provide canned answers for those
#
{ command => DBIx::MyServer::COM_PING, ok => 1 },
{ command => DBIx::MyServer::COM_INIT_DB, ok => 1 },
{ match => 'SET SQL_AUTO_IS_NULL=0;', ok => 1 },
{ match => 'set autocommit=1', ok => 1 },
{
match => 'SELECT Config, nValue FROM MSysConf',
error => ["MSysConf does not exist", 1146, '42S02'],
},
{
match => qr{^(select database|show databases)}sio,
columns => 'Database',
data => $database,
},
{
match => qr{^(show tables|show tables like '%')}io,
columns => 'Tables_in_'.$database,
data => $table,
},
{
match => "SHOW TABLES FROM `mysql` like '%'",
columns => 'Tables_in_mysql (%)',
data => ['user','host'],
},
{
match => qr{^show keys from},
columns => 'Keys',
data => [],
},
{
match => qr{^select.*from\s+nosuchtable(\d*).*$}io,
error => sub {[qq{Table '$database.nosuchtable$_[1]' doesn't exist},1146,'42S02']},
},
{
match => qr{^select\s+(.*)\s+from(.*)$}io,
columns => sub {
if ($_[2]=~/delay(\d+)/) {
sleep $1;
}
return [split(/,/,$_[1])],
},
data => sub {
my ($cmdline,$cols,$rest) = @_;
my $numr=2;
my $numc=scalar split(/,/,$cols);
if ($rest=~/rows(\d+)/) {
$numr=$1;
}
if ($rest=~/limit\s+(\d+)/i) {
$numr = $numr > $1 ? $1 : $numr;
}
return [ ([ ('datum') x $numc ] ) x $numr ];
},
},
{
match => qr{(.*)}o,
error => 'not supported',
},
);
|