App-Framework
view release on metacpan or search on metacpan
examples/eg-sql.pl view on Meta::CPAN
my %opts = $app->options() ;
# All named transactions use the values stored in this hash
my %sql_vars ;
# Set up database access
$app->sql(
'database' => $opts{'database'},
'table' => $opts{'table'},
'user' => $opts{'user'},
'password' => $opts{'password'},
# Option to do some Sql debugging by tracing transactions to a file
'trace' => $opts{'debug'} ? 4 : 0,
'trace_file'=> 'logsql.log',
'debug' => $opts{'debug'},
# Prepare some named transactions
'prepare' => {
'check', {
'limit' => 1,
examples/eg-sql.pl view on Meta::CPAN
Specify the database name to use
-table=s Table name [default=listings2]
Specify a different table (note that this example will only ensure that table 'listings2' is created')
-user=s User
Your MySql user
-password=s Pass
Your MySql password
__#=============================================================================================================================
__DATA__ listings2.sql
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Feb 26, 2009 at 12:13 PM
-- Server version: 5.0.51
lib/App/Framework/Feature/Sql.pm view on Meta::CPAN
=item B<host> - MySql host [default=localhost]
=item B<database> - Database name (required)
=item B<table> - Table name
=item B<user> - User name
=item B<password> - Password
=item B<trace> - Sql debug trace level [default=0]
=item B<trace_file> - If specified, output trace information to file (default=STDOUT)
=item B<sql_vars> - Default HASH used to store 'prepare' values
=item B<prepare> - Create one or more queries
lib/App/Framework/Feature/Sql.pm view on Meta::CPAN
=cut
my %FIELDS = (
# Object Data
'dbh' => undef,
'host' => 'localhost',
'database' => undef,
'table' => undef,
'user' => undef,
'password' => undef,
'trace' => 0,
'trace_file' => undef,
'prepare' => undef, # Special 'parameter' used to create STHs
'sql_vars' => {},
'_sth' => {},
) ;
# ensure these fields are set before starting to process the 'prepare' values
my @PRIORITY_FIELDS = qw/database user password table sql_vars/ ;
# Default STH
my $DEFAULT_STH_NAME = "_current" ;
#* DELETE
#
#DELETE [LOW_PRIORITY] [QUICK] [IGNORE]
# FROM tbl_name
# [WHERE where_condition]
# [ORDER BY ...]
lib/App/Framework/Feature/Sql.pm view on Meta::CPAN
return $trace_file ;
}
#----------------------------------------------------------------------------
=item B<connect(%args)>
Connects to database. Either uses pre-set values for user/password/database,
or can use optionally specified args
=cut
sub connect
{
my $this = shift ;
my (%args) = @_ ;
$this->set(%args) ;
lib/App/Framework/Feature/Sql.pm view on Meta::CPAN
my $dbh ;
eval
{
# Disconnect if already connected
$this->disconnect() ;
# Connect
$dbh = DBI->connect("DBI:mysql:database=".$this->database().
";host=".$this->host(),
$this->user(), $this->password(),
{'RaiseError' => 1}) or $this->throw_fatal( $DBI::errstr ) ;
$this->dbh($dbh) ;
};
if ($@)
{
$this->throw_fatal("SQL connect error: $@", 1000) ;
}
my $dbh_dbg = $dbh || "" ;
$this->_dbg_prt([" + connected dbh=$dbh_dbg : db=",$this->database()," user=",$this->user()," pass=",$this->password(),"\n"]) ;
return $dbh ;
}
#----------------------------------------------------------------------------
=item B<disconnect()>
Disconnect from database (if connected)
t/100-Feature-Sql.t view on Meta::CPAN
#----------------------------------------------------------------------
# Main execution
#
sub app
{
my ($app, $opts_href) = @_ ;
my $host = $opts_href->{host} ;
my $test_db = $opts_href->{database} ;
my $test_user = $opts_href->{user} || $ENV{USER} || $ENV{USERNAME} ;
my $test_password = $opts_href->{password} ;
my $test_table = $opts_href->{table} ;
my $test_dsn = "DBI:mysql:database=$test_db;host=$host" ;
## do some sanity checks
diag("Checking can connect to database") ;
my $dbh;
eval {
$dbh=DBI->connect($test_dsn, $test_user, $test_password,
{ RaiseError => 1, PrintError => 1, AutoCommit => 0 });
};
if ($@) {
plan skip_all => "Failed to connect to database : can't continue";
return 0 ;
}
diag("Checking user \"$test_user\" has sufficient privileges") ;
eval {
$dbh->do("DROP TABLE IF EXISTS $test_table") ;
t/100-Feature-Sql.t view on Meta::CPAN
# Set up database access
my $sql = $app->sql() ;
ok($sql, "Got object") ;
my %sql_vars_internal ;
$sql->set(
'host' => $host,
'database' => $test_db,
'table' => $test_table,
'user' => $test_user,
'password' => $test_password,
'sql_vars' => \%sql_vars_internal,
# Option to do some Sql debugging by tracing transactions to a file
'trace' => $opts_href->{'debug'} ? 4 : 0,
'trace_file'=> 'logsql.log',
'debug' => $opts_href->{'debug'},
# Prepare some named transactions
'prepare' => {
'check', {
t/100-Feature-Sql.t view on Meta::CPAN
Specify the database name to use
-table=s Table name [default=sqltest]
Specify a different table (note that this example will only ensure that table 'sqltest' is created')
-user=s User
Your MySql user
-password=s Pass
Your MySql password
__#=============================================================================================================================
__DATA__ sqltest.sql
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Feb 26, 2009 at 12:13 PM
-- Server version: 5.0.51
t/config2/20-Feature-Config.conf view on Meta::CPAN
# port = 2001
# # Expected prompt from the connected device
# prompt = /SC2-HWTC\s*>\s*$/i
#
# Along with mandatory setting, if the target device requires a login then the following must also
# be specified:
#
# # User name
# user = sdprice1
# # Password
# password = password
#
[tty]
name = SC2-1
host = tty-server2
port = 2011
prompt = /SC2-HWTC\s*>/i
timeout = 90
[tty]
( run in 0.641 second using v1.01-cache-2.11-cpan-49f99fa48dc )