List:General Discussion« Previous MessageNext Message »
From:Michael Dykman Date:November 17 2009 3:32pm
Subject:Re: Query!
View as plain text  
I'm sorry, you are way off here in what this actually does.

mysql_affected_rows is only going to tell you how many rows were
affected by the execution of the last statement made on your current
connection.  It is not an interface to a magic genie maintaining watch
over the state of your entire database.

The only ways you might accomplish anything even remotely like what
you have in mind are:
         have your watcher thread thread make a snapshot of the entire
db and run a diff on every cycle which would be ridiculously expensive
in terms of execution time not to mention locking up database access
pretty good.

OR
        have the external updating process record a log of changes to
a  particular table, then you monitor thread can scan that table for
new entries.


 - michael dykman

On Tue, Nov 17, 2009 at 7:06 AM, Gaurav Nigam (TMP-Japan)
<G.Nigam@stripped> wrote:
> Can somebody please help!
>
> There are two queries -
> 1. How can I detect from my code whether a table has been updated in the Database
> manually (I am firing delete from testtable where SrNo>=9; on the Database server) and
> not from the code itself. I am running this code -
>
> conn = mysql_init(NULL);
>
>            /* Connect to database */
>            if (!mysql_real_connect(conn, server, user,
> password, database, 0, NULL, 0)) {
>              fprintf(stderr, "%s\n",
> mysql_error(conn));
>              exit(1);
>            }
>
>            my_ulonglong affect_fields;
>            while(1)
>            {
>                      
>  affect_fields = mysql_affected_rows(conn);
>                        if
> ((long) affect_fields >=1)
>                        {
>                        
>            printf("%ld products updated\n\n",  (long)
> affect_fields);
>                        }
>            }
>
> 2. And if the table is really updated/inserted/deleted for any record then how to
> check which that record was.
>
> Regards,
> Gaurav.
>



-- 
 - michael dykman
 - mdykman@stripped

"May you live every day of your life."
    Jonathan Swift

Larry's First Law of Language Redesign: Everyone wants the colon.
Thread
Query!TMP-Japan)17 Nov
  • Re: Query!Michael Dykman17 Nov
    • Re: Query!Peter Brawley17 Nov