Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Deleting a Record?

Quote Reply
Deleting a Record?
Hi,

Can anyone help me out with this one. All I want to do is delete a record depending on a condition, but I can't get it to work - it's giving me the following errors:

Can't use an undefined value as a HASH reference at /path/to/admin/GT/SQL/Table.pm line 2219.
[Tue Aug 28 20:13:16 2001] [error] [client 192.168.1.224] Premature end of script headers: /path/to/myscript.cgi

I have a field in my db called "Created" that is a type timestamp(10). What I want to do is delete any records in the database that are more than 15 minutes old. This is what I've got so far - first getting the time and then deleting the record. If I'm going about it the wrong way please let me know...

my $oldtime = GT::Date::date_get (time - 60, "%yy%%mm%%dd%%HH%%MM%");

my $condition = new GT::SQL::Condition ( 'Created', '<', "$oldtime" );
my $result = $adb->delete ( $condition );



Cheers,
Regan.
Quote Reply
Re: Deleting a Record? In reply to
Hi,

Can you try:

my $oldtime = GT::Date::date_get (time - 60, "%yy%%mm%%dd%%HH%%MM%");
my $condition = new GT::SQL::Condition ( 'Created', '<', "$oldtime" );
my $sth = $adb->select (['ID'], $condition);
while (my $id = $sth->fetchrow) {
$adb->delete($id);
}

And see if that works?

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Deleting a Record? In reply to
Hi Alex,

I pasted that code into my script, and replaced one of the calls to be in line with my table:

my $adb = $DB->table('Users_Postcards');
my $oldtime = GT::Date::date_get (time - 60, "%yy%%mm%%dd%%HH%%MM%");
my $condition = new GT::SQL::Condition ( 'Created', '<', "$oldtime" );
my $sth = $adb->select (['PostcardID'], $condition);
while (my $id = $sth->fetchrow) {
$adb->delete($id);
}

But it's still returning the following error in my log:

GT::SQL::Table (19600): Wrong argument passed to this subroutine. Usage: Could not create a condition object out of arguments.
at /mnt/raid/www/newzealand/kiwicards/cgi/kiwicards.cgi line 108.

Line 108 is the delete line = $adb->delete($id);

Any ideas?

Cheers,
Regan.

Quote Reply
Re: Deleting a Record? In reply to
Hi,

What is $adb? Is it a Links table or a relation?

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Deleting a Record? In reply to
Hi Alex,

Its a new table I've created - not part of the original Links install. This is the def file for it if that helps?


{
'index' => {
'emailndx' => [
'Email'
]
},
'subclass' => {
'table' => {
'Users' => 'Links::Users'
},
'html' => {
'Users' => 'Links::Users::HTML'
}
},
'fk' => {},
'cols' => {
'Created' => {
'type' => 'TIMESTAMP',
'pos' => '7',
'not_null' => '0',
'default' => ''
},
'r_email' => {
'type' => 'VARCHAR',
'pos' => '5',
'size' => '50',
'not_null' => '1',
'binary' => '0',
'default' => ''
},
's_email' => {
'type' => 'VARCHAR',
'pos' => '4',
'size' => '50',
'not_null' => '1',
'binary' => '0',
'default' => ''
},
's_name' => {
'type' => 'VARCHAR',
'pos' => '3',
'size' => '50',
'not_null' => '1',
'binary' => '0',
'default' => ''
},
'LinkID' => {
'type' => 'INT',
'pos' => '2',
'not_null' => '0',
'unsigned' => '0',
'default' => '',
'zerofill' => '0'
},
'PostcardID' => {
'type' => 'VARCHAR',
'pos' => '1',
'size' => '150',
'not_null' => '1',
'binary' => '0',
'default' => ''
},
'msg' => {
'type' => 'TEXT',
'pos' => '6',
'not_null' => '1',
'default' => ''
}
},
'ai' => '',
'fk_tables' => [
'Links',
'Changes',
'Editors'
],
'pk' => [
'PostcardID'
],
'unique' => {}
};


Regan.


Quote Reply
Re: Deleting a Record? In reply to
In Reply To:
'subclass' => {
'table' => {
'Users' => 'Links::Users'
},
'html' => {
'Users' => 'Links::Users::HTML'
}
Any reason it's subclassing the Users table?! This is probably where the error is.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Deleting a Record? In reply to
Doh!

That fixed it. I had duplicated one of the other def files originally, and that was a reminant.

Thanks Alex!

Regan.