my $database = 'database';
my $table = 'table';
(
#
# Provide a sample answer to a query in the form of SELECT * FROM `table`
#
{
match => qr{SELECT .* FROM .*`(.*)`},
columns => ["field1", "field2"],
data => sub { [ [ "value1","value2" ] ] },
},
{
match => qr{^SHOW COLUMNS FROM (.*?) FROM (.*?)}io,
columns => ['Field','Type','Null','Key','Default','Extra'],
data => [
['field1','text','YES','','NULL',''],
['field2','text','YES','','NULL','']
]
},
#
# 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 => []
},
#
# Final rule - Forward all other queries as they are to the default DBH
#
{
match => qr{.*}o,
error => ["Unsupported query"]
}
);