| Summary | Package variables | Synopsis | General documentation | Methods |
| Summary | Top |
| Clair::ALE::_SQL - Internal SQL adapter for use by ALE |
| Package variables | Top |
| No package variables defined. |
| Included modules | Top |
| Carp |
| Clair::Utils::ALE(1) |
| Clair::Utils::ALE(2) qw ( %ALE_ENV ) |
| DBI |
| Synopsis | Top |
| This module is used internally by the other ALE modules to connect to an SQL database. Other modules (particularly Clair::ALE::Search) will use this automatically, so you shouldn't have to use it yourself unless you're writing an ALE module. It is a thin frontend for the DBI module. It's main purpose is to make it easy to change databases or database structures without having to change any other code. |
| Description | Top |
| Methods | Top |
| _quote | No description | Code |
| _refresh_tablenames | No description | Code |
| commit | No description | Code |
| connect | No description | Code |
| disconnect | No description | Code |
| do | No description | Code |
| errdie | No description | Code |
| errstr | No description | Code |
| insertid | No description | Code |
| links_table | No description | Code |
| new | No description | Code |
| query | No description | Code |
| querycancel | No description | Code |
| queryone | No description | Code |
| queryresult | No description | Code |
| quote | No description | Code |
| rollback | No description | Code |
| set | No description | Code |
| setdefaults | No description | Code |
| urls_table | No description | Code |
| words_table | No description | Code |
| _quote | description | prev | next | Top |
sub _quote
{
return $_[0]->{_dbh}->quote($_[1]);} |
| _refresh_tablenames | description | prev | next | Top |
sub _refresh_tablenames
{
my $self = shift;
my $alespace_prefix;
if (!$ALE_ENV{ALESPACE} or ($ALE_ENV{ALESPACE} eq 'default'))
{
$alespace_prefix="";
}
else
{
$alespace_prefix="$ALE_ENV{ALESPACE}_";
}
$self->{_links_table} = $alespace_prefix."links";
$self->{_words_table} = $alespace_prefix."words";
$self->{_urls_table} = $alespace_prefix."urls";} |
| commit | description | prev | next | Top |
sub commit
{
my $self = shift;
$self->{_dbh}->commit;} |
| connect | description | prev | next | Top |
sub connect
{
my $self = shift;
if (!$self->{_dbh})
{
#print "$self->{DSN}\n";} |
| disconnect | description | prev | next | Top |
sub disconnect
{
my $self = shift;
if ($self->{_dbh})
{
$self->{_dbh}->disconnect;
delete $self->{_dbh};
}
$self;} |
| do | description | prev | next | Top |
sub do
{
my $self = shift;
if ($ALE_ENV{DEBUGSQL})
{
print "SQL: @_\n";
}
$self->connect;
$self->{_dbh}->do(@_);} |
| errdie | description | prev | next | Top |
sub errdie
{
my $self = shift;
croak join("",@_) . ": Database error ".$self->errstr;} |
| errstr | description | prev | next | Top |
sub errstr
{
my $self = shift;
return $self->{_dbh}->errstr;} |
| insertid | description | prev | next | Top |
sub insertid
{
my $self = shift;
return $self->{_dbh}->{mysql_insertid};} |
| links_table | description | prev | next | Top |
sub links_table
{ my $self = shift;
$self->_refresh_tablenames();
return $self->{_links_table};} |
| new | description | prev | next | Top |
sub new
{
my $class = shift;
my $self = {};
bless $self,$class;
$self->setdefaults;
$self->set(@_);
$self;} |
| query | description | prev | next | Top |
sub query
{
my $self = shift;
my($sql)=@_;
$self->{_sql}=$sql;
if ($ALE_ENV{SQLDEBUG}) { print "SQL: $sql\n"; }
$self->connect;
$self->{_sth} = $self->{_dbh}->prepare($sql)
or croak "Error preparing SQL statement '$sql': ".$self->{_dbh}->errstr;
$self->{_sth}{mysql_use_result}=1;
$self->{_sth}->execute
or croak "Error executing SQL statement '$sql': ".$self->{_dbh}->errstr;
$self;} |
| querycancel | description | prev | next | Top |
sub querycancel
{
my $self = shift;
$self->{_sth}->finish
or croak "Error finishing SQL statement '$self->{_sql}': ".$self->{_dbh}->errstr;} |
| queryone | description | prev | next | Top |
sub queryone
{
my $self = shift;
$self->query(@_);
my $r = $self->queryresult;
if ($r)
{
$self->querycancel;
}
$r;} |
| queryresult | description | prev | next | Top |
sub queryresult
{
my $self = shift;
$self->{_sth}
or croak "Attempted to get query results without running query!";
my $row = $self->{_sth}->fetchrow_hashref;
if (!$row)
{
$self->{_sth}->finish
or croak "Error finishing SQL statement '$self->{_sql}': ".$self->{_dbh}->errstr;
}
return $row;} |
| quote | description | prev | next | Top |
sub quote
{my $self = shift; $self->connect; return $self->_quote(@_);} |
| rollback | description | prev | next | Top |
sub rollback
{
my $self = shift;
$self->{_dbh}->rollback;} |
| set | description | prev | next | Top |
sub set
{
my $self = shift;
my($var,$val);
while($var=shift)
{
$val = shift;
if ($SETTABLE{$var})
{
$self->{$var}=$val;
}
}
$self;} |
| setdefaults | description | prev | next | Top |
sub setdefaults
{
my $self = shift;
my $user = 'root';
my $pass = '';
if ($ALE_ENV{ALE_DB_USER}) {
$user = $ALE_ENV{ALE_DB_USER};
}
if ($ALE_ENV{ALE_DB_PASS}) {
$pass = $ALE_ENV{ALE_DB_PASS};
}
return $self->set(
DSN => 'DBI:mysql:database=clair',
username => $user,
password => $pass,
AutoCommit => 1,
);} |
| urls_table | description | prev | next | Top |
sub urls_table
{ my $self = shift;
$self->_refresh_tablenames();
return $self->{_urls_table};} |
| words_table | description | prev | next | Top |
sub words_table
{ my $self = shift;
$self->_refresh_tablenames();
return $self->{_words_table};} |