I have run into a problem in my web application where I create an entry in the database, then move to another area of the site and list the rows and my created entry is missing. If I use the command line mysql or query-browser I see that the entry was created....So the only thing I can currently guess is that this is caused by the mysql query cache. I'm creating the entry using transactions. I wondered if there is a best practices way of checking/clearing the cache when a new entry has been created.
The following is how the entries are created as well as the list_all attempt to grab the rows.
#*********************************************************************
+********
# public create
# *************
# Uses: Saves the given object into the database
# Params: HASH with new object attributes
# Return: The inserted object, or undef if the Object can't be inse
+rted
#*********************************************************************
+********
sub create {
my $class = shift;
my ($param) = @_;
my $dbh = Jnms::Database::Control::DatabaseManager->get_database->
+{dbh};
my $id;
my $error;
# check if the required fields are there and insert on the db
#print STDERR Dumper($class,$param);
$class->_check_required_create_fields($param);
eval{
$id = $class->_insert_into_database($param);
$dbh->commit;
};
if ($@) {
warn "Transaction aborted because $@";
$error = $@;
# now rollback to undo the incomplete changes
# but do it in an eval{} as it may also fail
eval { $dbh->rollback };
die "Transaction aborted because of $error";
# add other application on-error-clean-up code here
}
#return the inserted object
return $class->find($id);
}
#*********************************************************************
+********
# public list_all
# ***************
# Uses: gets all Objects that matches the child class type from th
+e db
# Params: None.
# Return: an ARRAY of all Objects of the requested type
#*********************************************************************
+********
sub list_all {
my $class = shift;
my ($param) = @_;
my $dbh = Jnms::Database::Control::DatabaseManager->get_database->
+{dbh};
# get the constants specified on the child class
my $columns = join(', ', $class->TABLE_COLUMNS);
my $table = $class->TABLE_NAME;
my $order = $class->LIST_ORDER;
my @column_values = ();
my $objects = $dbh->selectall_arrayref("SELECT $columns FROM $tabl
+e ORDER BY $order", {Slice=>{}}, @column_values);
bless($_, ref($class) || $class) foreach @$objects;
my $depth = 0;
if (ref $param eq 'HASH') {
$depth = $param->{depth};
}
elsif($param) {
$depth = $param;
}
unless(defined $depth){ $depth = 0; }
$objects = $class->_find_foreign_keys($objects, $depth);
return $objects;
}