CAM-SQLObject
view release on metacpan or search on metacpan
lib/CAM/SQLObject.pm view on Meta::CPAN
$fullpath .= ".xml";
push @files, $fullpath;
my $shortpath = $fullpath;
$shortpath =~ s/^.*\///;
push @files, $shortpath;
return wantarray ? @files : $files[0];
}
#----------------
=item keyName
Returns the name of the primary key field (needed for save() and
retrieveByKey()). This default method returns the primary key name
from the SQL Manager's XML file, or undef.
=cut
sub keyName
{
my $pkg_or_self = shift;
my $mgr = $pkg_or_self->getMgr();
if ($mgr)
{
return $mgr->keyName() || undef;
}
return undef;
}
#----------------
=item tableName
Returns the name of the SQL table (needed for fieldNames() and
retrieveByKey()). This default method returns the table name from the
SQL Manager's XML file, or undef.
=cut
sub tableName
{
my $pkg_or_self = shift;
my $mgr = $pkg_or_self->getMgr();
if ($mgr)
{
return $mgr->tableName() || undef;
}
return undef;
}
#----------------
=item updateQueryName
Returns the name of the default query to do record updates in SQL XML
file (needed for save()). This default method returns "update".
=cut
sub updateQueryName
{
my $pkg_or_self = shift;
return "update";
}
#----------------
=item insertQueryName
Returns the name of the default query to do record inserts in SQL XML
file (needed for save()). This default method returns "insert".
=cut
sub insertQueryName
{
my $pkg_or_self = shift;
return "insert";
}
#----------------
=item deleteQueryName
Returns the name of the default query to do record deletes in SQL XML
file. This default method returns "delete".
=cut
sub deleteQueryName
{
my $pkg_or_self = shift;
return "delete";
}
#----------------
=item keygenAlgorithm
Returns the name of the algorithm that the newkey() method uses to
generate its keys. This default method returns undef. See newkey()
for more details.
=cut
sub keygenAlgorithm
{
my $pkg_or_self = shift;
return undef;
}
#----------------
=item keygenData
Returns the ancillary data needed to support the algorithm specified
by keygenAlgorithm(). The contents of this data depend on the
algorithm chosen. This default method returns undef. See newkey()
for more details.
lib/CAM/SQLObject.pm view on Meta::CPAN
#----------------
=item query
Run the specified query against this object. All bound SQL parameters
will be read from this object. This is applicable to both SELECT as
well as UPDATE/INSERT queries. While usually called as an instance
method, this can be called as a class method if all you are interested
in is the side effects of the SQL query instead of the data.
NOTE! This method does not retrieve the results of SELECT statements
into the object. If you wish to apply SELECT data to your objects,
use either fill() or retrieve().
=cut
sub query
{
my $pkg_or_self = shift;
my $queryname = shift;
return $pkg_or_self->_runSQL($queryname, @_);
}
#----------------
=item save
Either update or insert this object into the database. The keyname
field must be set so this function can figure out whether to update or
insert.
=cut
sub save
{
my $self = shift;
if (!$self->{keyname})
{
&carp("No keyname defined");
return undef;
}
if (defined $self->{keyvalue})
{
return $self->update();
}
else
{
return $self->insert();
}
}
#----------------
=item update
Run the default update SQL template. This function is usually just
called from the save() function.
=cut
sub update
{
my $self = shift;
my $query = shift || $self->{update_name};
return $self->_runSQL($query);
}
#----------------
=item insert
Run the default insert SQL template. This function is usually just
called from the save() function.
=cut
sub insert
{
my $self = shift;
my $query = shift || $self->{insert_name};
my $result = $self->_runSQL($query);
if ($result && $self->{keyname})
{
# Retrieve the key. Store in both places.
# This is likely dependent on the database. It works on MySQL
$self->{keyvalue} = $self->{lastmgr}->getLastInsertID();
$self->set_key($self->{keyvalue});
}
return $result;
}
#----------------
=item delete
Run the default delete SQL template.
=cut
sub delete
{
my $self = shift;
my $query = shift || $self->{delete_name};
return $self->_runSQL($query);
}
#----------------
=item getAllFields
=item allFields <deprecated>
Returns a hash of all the fields, all retrieved via the accessor
functions. "allFields" is the old name for this function, and is here
for backward compatibility only.
=cut
sub allFields
{
my $self = shift;
( run in 0.340 second using v1.01-cache-2.11-cpan-a1f116cd669 )