DBIx-Broker
view release on metacpan or search on metacpan
} # i personally have no use for fetchrow[_array]... ( does anybody? )
}
sub rows {
my $self = shift;
if ( $self->{'statement'} ) {
return $self->{'statement'}->rows();
}
else {
return 0;
}
}
sub count {
my $self = shift;
my $tables = shift;
my $stipulations = shift;
my ( @tables );
$self->__add_to_array( $tables, \@tables );
if ( ! defined($self->{'db'}) ) {
die "There is not a valid DB handle from which to select a count.\n";
}
local $" = ", ";
$self->{'sql'} = "SELECT COUNT(*) FROM @tables $stipulations";
print { $self->{'debug_handle'} } "$self->{'sql'}\n" if $self->{'debug'};
my @query_results = $self->__sql_execute();
return $query_results[0]->[0];
}
sub insert {
my $self = shift;
my $table = shift; # send only one table
my %new_data = %{ shift @_ };
my @fields = keys( %new_data ); # these are promised to be in the same order,
my @values = values( %new_data ); # according to the docs
my @question_marks = ( "?" ) x @values;
if ( ! defined($self->{'db'}) ) {
die "There is not a valid DB handle into which to insert data.\n\n";
}
local $" = ", ";
$self->{'sql'} = "INSERT INTO $table ( @fields ) VALUES ( @question_marks )";
print { $self->{'debug_handle'} } "sql: $self->{'sql'}\nvalues: @values\n" if $self->{'debug'};
$self->__sql_execute( \@values );
return $self->{'statement'}->{'mysql_insertid'} if ( $self->{'driver'} eq 'mysql' );
}
sub update {
my $self = shift;
my $table = shift; # send only one table
my %new_data = %{ shift @_ };
my $stipulations = shift;
my @fields = keys( %new_data ); # these are promised to be in the same order,
my @values = values( %new_data ); # according to the docs
if ( ! defined($self->{'db'}) ) {
die "There is not a valid DB handle to update.\n";
}
$self->{'sql'} = "UPDATE $table SET ";
foreach ( @fields ) {
$self->{'sql'} .= "$_ = ?, ";
}
$self->{'sql'} =~ s/\,\s$/ /; # chop off the last comma
$self->{'sql'} .= $stipulations if $stipulations;
print { $self->{'debug_handle'} } "sql: $self->{'sql'}\nvalues: @values\n" if $self->{'debug'};
$self->__sql_execute( \@values );
}
sub delete {
my $self = shift;
my $table = shift;
my $stipulations = shift;
if ( ! defined($self->{'db'}) ) {
die "There is not a valid DB handle from which to delete data.\n";
}
$self->{'sql'} = "DELETE FROM $table $stipulations";
print { $self->{'debug_handle'} } "$self->{'sql'}\n" if $self->{'debug'};
$self->__sql_execute();
}
sub delete_all {
my $self = shift;
my $table = shift;
if ( ! defined($self->{'db'}) ) {
die "There is not a valid DB handle from which to delete data.\n";
}
$self->{'sql'} = "DELETE FROM $table";
print { $self->{'debug_handle'} } "$self->{'sql'}\n" if $self->{'debug'};
$self->__sql_execute();
}
sub get_table_schema {
my $self = shift;
my $table = shift;
( run in 0.743 second using v1.01-cache-2.11-cpan-5b529ec07f3 )