App-AltSQL
view release on metacpan or search on metacpan
lib/App/AltSQL/Model/MySQL.pm view on Meta::CPAN
$type{$key} = $type_info_all->[$i][$index];
}
$types{$i} = \%type;
}
$self->{db_types} = \%types;
}
sub db_type_info {
my ($self, $type) = @_;
my $info = $self->{db_types}{$type};
if (! $info) {
#$self->log_error("No such type info for $type");
return $self->{db_types}{unknown};
}
return $info;
}
sub show_sql_error {
my ($self, $input, $char_number, $line_number) = @_;
my @lines = split /\n/, $input;
my $line = $lines[ $line_number - 1 ];
$self->log_error("There was an error parsing the SQL statement on line $line_number:");
$self->log_error($line);
$self->log_error(('-' x ($char_number - 1)) . '^');
}
my %prompt_substitutions = (
S => ';',
"'" => "'",
'"' => '"',
v => 'TODO-server-version',
p => sub { shift->{self}->port },
'\\' => '\\',
n => "\n",
t => "\t",
'_' => ' ',
' ' => ' ',
d => '%d',
h => '%h',
c => '%e{ ++( shift->{self}{_statement_counter} ) }',
u => '%u',
U => '%u@%h',
D => '%t{%a, %d %b %H:%M:%S %Y}',
w => '%t{%a}',
y => '%t{%y}',
Y => '%t{%Y}',
o => '%t{%m}',
O => '%t{%b}',
R => '%t{%k}',
r => '%t{%I}',
m => '%t{%M}',
s => '%t{%S}',
P => '%t{%p}',
);
=cut
Take a .my.cnf prompt format and convert it into Term escape options
Reference:
http://www.thegeekstuff.com/2010/02/mysql_ps1-6-examples-to-make-your-mysql-prompt-like-angelina-jolie/
=cut
sub parse_prompt {
my $self = shift;
my $parsed_prompt = $self->prompt;
$parsed_prompt =~ s{\\\\(.)}{
my $substitute = $prompt_substitutions{$1};
if (! $substitute) {
"$1";
}
elsif (ref $substitute) {
$substitute->($self);
}
else {
$substitute;
}
}exg;
return $parsed_prompt;
}
no Moose;
__PACKAGE__->meta->make_immutable;
=head1 COPYRIGHT
Copyright (c) 2012 Eric Waters and Shutterstock Images (http://shutterstock.com). All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
=head1 AUTHOR
Eric Waters <ewaters@gmail.com>
=cut
1;
( run in 0.528 second using v1.01-cache-2.11-cpan-39bf76dae61 )