new.spirit
view release on metacpan or search on metacpan
bin/dbshell.pl view on Meta::CPAN
}
$shell = new NewSpirit::SqlShell::Text (
source => $source,
username => $username,
password => $password,
selected_db => $selected_db,
autocommit => 1,
echo => 0,
get_line_cb => $get_line_cb,
preference_file => home_dir()."/.dbshell_prefs"
);
$shell->{abort_mode} = $opts_href->{x};
if ( $initialize_history ) {
$shell->info ("Initializing command history");
initialize_history (
$term, $shell->get_preference('history_size')
)
}
cgi-bin/admin.cgi view on Meta::CPAN
my $passwd_h = new NewSpirit::Passwd ($q);
my $method = "event_$event";
$passwd_h->$method();
}
sub pref_event {
my $q = shift;
my ($event) = @_;
my $prefs_h = new NewSpirit::Prefs ($q);
my $method = "event_$event";
$prefs_h->$method();
}
sub changes {
my $q = shift;
NewSpirit::std_header (
page_title => "CHANGES of new.spirit version $CFG::VERSION",
window_title => "CHANGES of new.spirit version $CFG::VERSION",
);
lib/NewSpirit/SqlShell.pm view on Meta::CPAN
sub new {
my $type = shift;
my %par = @_;
my $source = $par{source};
my $username = $par{username};
my $password = $par{password};
my $autocommit = $par{autocommit};
my $selected_db = $par{selected_db};
my $prefs_file = $par{preference_file};
my $sql = $par{sql};
my $get_line_cb = $par{get_line_cb};
my $echo = $par{echo};
my $self = {
sql_sref => $sql,
abort_mode => 0,
current_command => undef,
errors => [],
command_cnt => 0,
get_line_cb => $get_line_cb,
echo => $echo,
command_completed => 1,
source => $source,
username => $username,
selected_db => $selected_db,
preference_file => $prefs_file,
preferences => {
'display_style' => 'auto',
'screen_width' => 0,
'prefs_autosave' => 'on',
'history_size' => 100,
},
preferences_declaration => {
'display_style' => {
'boxed' => 1,
'row' => 1,
'auto' => 1,
'tab' => 1,
},
'screen_width' => 'integer',
'history_size' => 'integer',
'prefs_autosave' => {
'on' => 1,
'off' => 1
},
}
};
${$self->{sql_sref}} .= "\n";
bless $self, $type;
lib/NewSpirit/SqlShell.pm view on Meta::CPAN
}
$self->load_preferences;
return $self;
}
sub DESTROY {
my $self = shift;
if ( $self->get_preference ('prefs_autosave') eq 'on' ) {
$self->save_preferences;
}
$self->info ("Disconnecting from '$self->{source}'");
if ( defined $self->{dbh} ) {
$self->{dbh}->disconnect;
}
}
sub load_preferences {
my $self = shift;
my $prefs_file = $self->{preference_file};
return if not -f $self->{preference_file};
$self->info ("Loading preferences from '$prefs_file'...");
my $prefs_href;
{
no strict 'vars';
$prefs_href = do $prefs_file;
}
foreach my $key ( keys %{$self->{preferences_declaration}} ) {
if ( exists $prefs_href->{$key} ) {
$self->set_preference ( $key, $prefs_href->{$key} );
}
}
}
sub save_preferences {
my $self = shift;
my $prefs_file = $self->{preference_file};
open (FH, "> $prefs_file") or
return $self->error ("Can't write '$prefs_file'");
print FH Dumper ($self->{preferences});
close FH;
$self->info ("Preferences successfully saved to '$prefs_file'...");
1;
}
sub get_next_command_line {
my $self = shift;
# return if we are already at EOF
return if $self->{eof};
lib/NewSpirit/SqlShell.pm view on Meta::CPAN
if ( $command =~ /^\s*;\n$/ ) {
# print "got empty command!<br>\n";
$command = '';
next;
}
# a semicolon a the end of the line terminates a command
last if $command =~ /;\n$/;
# internal commands need no semicolon
last if $command =~ /^\s*(quit|exit|help|reload|saveprefs)\s*$/;
last if $command =~ /^\s*(desc|autocommit|abort|set|\!)\s*([^\s]+\s*)*$/;
}
$command =~ s/^\s+//;
$command =~ s/\s$//;
$command =~ s/;$//;
return $command;
}
lib/NewSpirit/SqlShell.pm view on Meta::CPAN
# display style is always 'row'
my $old_pref = $self->get_preference ('display_style');
$self->set_preference ('display_style', 'row');
# print column titles
$self->print_query_result_start (
title_lref => [qw(NAME VALUE)]
);
my $prefs = $self->{preferences};
my $i = 0;
foreach my $key (sort keys %{$prefs} ) {
$self->print_query_result_row (
row_lref => [
$key,
$key eq 'display_style' ? $old_pref : $prefs->{$key},
]
);
++$i;
}
$self->print_query_result_end;
# restore display style
lib/NewSpirit/SqlShell.pm view on Meta::CPAN
These commands are recognized by the shell, all other commands are
passed through the database without change:
---------------------------------------------------------------------
autocommit {on|off} Switch AutoCommit on or off
abort {on|off} Switch 'abort on error' on or off
desc table Show definition of this table
exit | quit Exit the shell
help This help page
reload Reload SqlShell modules (for debugging only)
saveprefs Save preferences
set [par=value] Sets user preferences. Currently possible
parameters are:
display_style = {row|boxed|auto|tab}
history_size = number
prefs_autosafe = {on|off}
screen_width = number (0 for autosize)
If you ommit par=value a table of the
current settings is printed
! [command] Executes command with system shell.
Starts a system shell, if command is omitted.
---------------------------------------------------------------------
SQL statements must be terminated with a ; sign and may be continued
over several lines. The internal commands described above may be
optionally terminated with a ; sign, if you like it.
lib/NewSpirit/SqlShell.pm view on Meta::CPAN
"Preference value '$value' is not a number!"
);
}
}
$self->{preferences}->{$key} = $value;
$self->info ("Preference '$key' set to '$value'");
}
sub cmd_saveprefs {
my $self = shift;
$self->save_preferences;
}
sub cmd_system {
my $self = shift;
my ($command) = @_;
( run in 2.750 seconds using v1.01-cache-2.11-cpan-8f98c5d2c55 )