Query!
am 17.11.2009 13:06:27 von G.Nigam
--_000_05380BF7E839E0458273644FF680C24909E4DBFEE7ZE42CM01ind ze_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Can somebody please help!
There are two queries -
1. How can I detect from my code whether a table has been updated in the Da=
tabase manually (I am firing delete from testtable where SrNo>=3D9; on the =
Database server) and not from the code itself. I am running this code -
conn =3D 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 =3D mysql_affected_rows(conn);
if ((long) affect_fields >=3D1)
{
printf("%ld products updated\n\n", (lo=
ng) 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.
--_000_05380BF7E839E0458273644FF680C24909E4DBFEE7ZE42CM01ind ze_--
Re: Query!
am 17.11.2009 16:32:18 von Michael Dykman
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@gmail.com
"May you live every day of your life."
Jonathan Swift
Larry's First Law of Language Redesign: Everyone wants the colon.
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=3Dgcdmg-mysql-2@m.gmane.o rg
Re: Query!
am 17.11.2009 16:50:58 von Peter Brawley
--------------090303020203050909040802
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Gaurav,
>How can I detect from my code whether a table has been updated in the
Database manually
Have a look at "Transaction Time Validity" in
http://www.osdbzine.net/issue6.pdf and http://www.osdbzine.net/issue7.pdf.
PB
-----
Michael Dykman wrote:
> 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>=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.
>>
>>
>
>
>
>
> ------------------------------------------------------------ ------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 8.5.425 / Virus Database: 270.14.67/2506 - Release Date: 11/16/09 07:43:00
>
>
--------------090303020203050909040802--