From: Michael Dykman Date: November 17 2009 3:32pm Subject: Re: Query! List-Archive: http://lists.mysql.com/mysql/219393 Message-Id: <814b9a820911170732l1f9e24d4h1ec47fa4c1bc3e1a@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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) 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>=3D9; on th= e Database server) and not from the code itself. I am running this code - > > conn =3D mysql_init(NULL); > > =A0 =A0 =A0 =A0 =A0 =A0/* Connect to database */ > =A0 =A0 =A0 =A0 =A0 =A0if (!mysql_real_connect(conn, server, user, passwo= rd, database, 0, NULL, 0)) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0fprintf(stderr, "%s\n", mysql_error(conn)); > =A0 =A0 =A0 =A0 =A0 =A0 =A0exit(1); > =A0 =A0 =A0 =A0 =A0 =A0} > > =A0 =A0 =A0 =A0 =A0 =A0my_ulonglong affect_fields; > =A0 =A0 =A0 =A0 =A0 =A0while(1) > =A0 =A0 =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0affect_fields =3D mysql_af= fected_rows(conn); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if ((long) affect_fields >= =3D1) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pr= intf("%ld products updated\n\n", =A0(long) affect_fields); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} > =A0 =A0 =A0 =A0 =A0 =A0} > > 2. And if the table is really updated/inserted/deleted for any record the= n how to check which that record was. > > Regards, > Gaurav. > --=20 - 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.