Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Can $links_db->do_query() result counted?

Quote Reply
Can $links_db->do_query() result counted?
Hi!

I execute an SQL statement:
Code:
UPDATE $links_db SET col2 = col1
WHERE col2 IS NULL or col2 LIKE '0000-00-00%') and (col3 = '2')

The perl query looks like this:
Code:
$links_db->do_query("UPDATE apro_links SET col2 = col1
WHERE col2 IS NULL or col2 LIKE '0000-00-00%') and (col3 = '2')");

I do not think I can replace this query with another GT::SQL method. GT::SQL::Condition seems does not know how to get a value from a column to another column. If yes, let me know, how!

Now I would like to count it using hits() method:
$hits = $links_db->hits;
But there is no any result counted.

How to count the result of the do_query?

Please help! Thanks!

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Can $links_db->do_query() result counted? In reply to
Quote:
UPDATE $links_db SET col2 = col1 WHERE col2 IS NULL or col2 LIKE '0000-00-00%') and (col3 = '2')

Code:
my $links_db = $DB->table('Links');
my $cond1 = GT::SQL::Condition->new( 'col3', '=', 2 );
my $cond2 = GT::SQL::Condition->new( 'col2', 'IS', \'NULL', 'col2', 'LIKE', '0000-00-00%' );
$cond2->bool('OR');
$cond2->add($cond1);

$links_db->update( { col2 => \'col1' }, $cond2 );

Untested but try that.

Last edited by:

Paul: Nov 28, 2002, 2:57 AM
Quote Reply
Re: [Paul] Can $links_db->do_query() result counted? In reply to
Yogi suggested the same solution to pass as reference.
I answered there, and the same answer would come here, too.
To avoid the duplicate posting here is the link, read this:
http://www.gossamer-threads.com/...?post=224193;#224193

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Can $links_db->do_query() result counted? In reply to
Quote:
To avoid the duplicate posting

You created it Tongue
Quote Reply
Re: [Paul] Can $links_db->do_query() result counted? In reply to
Not really.
One thread was about a do_query, how to solve in GT::SQL.
The other was about hits() method problem. And you suggested the same solution as Yogi.
2 different topics resulted the same suggestion, so I pointed an URL to another thread to read the answer.

But to stick to the topic, unfortunately the $hits = $links_db->hits; still does not give me result after update.
I can get the result, only if I do count the results with: $count = $links_db->count ($cond);

Any idea, why the hits() does not work after update?
May I forgot to load a module? Any idea?

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Can $links_db->do_query() result counted? In reply to
Try $link_db->rows

Not sure though.
Quote Reply
Re: [Paul] Can $links_db->do_query() result counted? In reply to
I tried rows() earlier, but it's not available. It available only in DBI, as I know. Unsure

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [Paul] hits() method NOT working for do_query(), update(), modify() methods! In reply to
Thanks, Paul!

It seems the hits() method is not working for do_query(), update(), modify() methods!
Only the rows() method works for update().

Do the following with do_query():
Code:
my $links_sth = $links_db->do_query("UPDATE apro_links SET col = 1 WHERE col IS NULL);
my $hits = $links_db->hits;
my $rows = $links_sth->rows; # will result error Unknown method 'rows'
The result of $hits will be 0, even if there was a lot hits.
hits() not working. rows() not available, error.
It seems query result number can not counted at all.
A workaround would be to create a condition obkect with same where clause, and then count with $links_db->count ($cond); But this means an additional, unnecessary query.


Do the following with update():
Code:
my $cond1 = GT::SQL::Condition->new( "col", 'IS', \'NULL' );
my $links_sth = $links_db->update ( {"col" => 1}, $cond1);
my $hits = $links_db->hits;
my $rows = $links_sth->rows;
The result of $hits will be 0, even if there was a lot hits. $rows has correct result.
hits() not working. rows() works.


Did not test modify(), but very likely will get the same result as update().


hits() method reads the hits number from $self->{last_hits}.
Final conclusion is: do_query(), update(), modify() are not updating the $self->{last_hits}, therefore the hits() method can not read the hits number from it.

Would be fine to correct these bugs (if are bugs) in GT::SQL::Table module!

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...

Last edited by:

webmaster33: Dec 1, 2002, 7:27 PM