Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 06:35 AM
Ace
 
Posts: n/a
Default how to get Number of rows matched?

Hi Experts,

When issuing updates in mysql (in the console window), mysql will tell
you if any rows matched and how many rows were updated (see below). I
know how to get number of rows udpated using mysql_affected_rows(), but is
there any
way to get the number of rows matched? I want to find out, when rows
updated = 0, if there were no updates because the row wasn't found
(rows matched will = 0) or because the update would not have changed
any data (rows matched = 1).

mysql> select * from test;
+------+------+
| roll | s |
+------+------+
| 1 | new |
+------+------+
1 row in set (0.00 sec)

mysql> update test set roll = 1, s = 'new' where roll = 1;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0

mysql> update test set roll = 1, s = 'new' where roll = 17;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0

mysql> update test set roll = 1, s = 'neww' where roll = 1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

--
Cheers,
Rajan

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 06:35 AM
ViSolve DB Team
 
Posts: n/a
Default Re: how to get Number of rows matched?

Hi

AFAIK, before changing data, the old values are saved in the rollback
segment.
On saving the updated values, from the Buffer to the rollback segment/data
files,
--- it checks if there is any matched row that matches the condition. If
found, then flags "Matched".
---after filtering out the matched row, it check whether there is need to
change the old value to new value. if need then flags "Changed" and rewrite
the same in the datafile/rollback segment.


Thanks
ViSolve DB Team.
----- Original Message -----
From: "Ace" <rajan.halade@gmail.com>
To: <mysql@lists.mysql.com>
Sent: Monday, June 11, 2007 11:41 AM
Subject: how to get Number of rows matched?


> Hi Experts,
>
> When issuing updates in mysql (in the console window), mysql will tell
> you if any rows matched and how many rows were updated (see below). I
> know how to get number of rows udpated using mysql_affected_rows(), but is
> there any
> way to get the number of rows matched? I want to find out, when rows
> updated = 0, if there were no updates because the row wasn't found
> (rows matched will = 0) or because the update would not have changed
> any data (rows matched = 1).
>
> mysql> select * from test;
> +------+------+
> | roll | s |
> +------+------+
> | 1 | new |
> +------+------+
> 1 row in set (0.00 sec)
>
> mysql> update test set roll = 1, s = 'new' where roll = 1;
> Query OK, 0 rows affected (0.00 sec)
> Rows matched: 1 Changed: 0 Warnings: 0
>
> mysql> update test set roll = 1, s = 'new' where roll = 17;
> Query OK, 0 rows affected (0.00 sec)
> Rows matched: 0 Changed: 0 Warnings: 0
>
> mysql> update test set roll = 1, s = 'neww' where roll = 1;
> Query OK, 1 row affected (0.00 sec)
> Rows matched: 1 Changed: 1 Warnings: 0
>
> --
> Cheers,
> Rajan
>



--------------------------------------------------------------------------------


No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.472 / Virus Database: 269.8.13/843 - Release Date: 6/10/2007
1:39 PM

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 06:35 AM
Ace
 
Posts: n/a
Default Re: how to get Number of rows matched?

Ok..thanks! But my problem here is how to check if there were any matched
rows when no rows were changed. mysql_affected_rows() will tell me the
affected rows. Simmly, is there any routine using which one can know if
there were any matched rows?

Cheers,
Rajan

On 6/11/07, ViSolve DB Team <mysqlsupport@visolve.com> wrote:
>
> Hi
>
> AFAIK, before changing data, the old values are saved in the rollback
> segment.
> On saving the updated values, from the Buffer to the rollback segment/data
> files,
> --- it checks if there is any matched row that matches the condition. If
> found, then flags "Matched".
> ---after filtering out the matched row, it check whether there is need to
> change the old value to new value. if need then flags "Changed" and
> rewrite
> the same in the datafile/rollback segment.
>
>
> Thanks
> ViSolve DB Team.
> ----- Original Message -----
> From: "Ace" <rajan.halade@gmail.com>
> To: <mysql@lists.mysql.com>
> Sent: Monday, June 11, 2007 11:41 AM
> Subject: how to get Number of rows matched?
>
>
> > Hi Experts,
> >
> > When issuing updates in mysql (in the console window), mysql will tell
> > you if any rows matched and how many rows were updated (see below). I
> > know how to get number of rows udpated using mysql_affected_rows(), but

> is
> > there any
> > way to get the number of rows matched? I want to find out, when rows
> > updated = 0, if there were no updates because the row wasn't found
> > (rows matched will = 0) or because the update would not have changed
> > any data (rows matched = 1).
> >
> > mysql> select * from test;
> > +------+------+
> > | roll | s |
> > +------+------+
> > | 1 | new |
> > +------+------+
> > 1 row in set (0.00 sec)
> >
> > mysql> update test set roll = 1, s = 'new' where roll = 1;
> > Query OK, 0 rows affected (0.00 sec)
> > Rows matched: 1 Changed: 0 Warnings: 0
> >
> > mysql> update test set roll = 1, s = 'new' where roll = 17;
> > Query OK, 0 rows affected (0.00 sec)
> > Rows matched: 0 Changed: 0 Warnings: 0
> >
> > mysql> update test set roll = 1, s = 'neww' where roll = 1;
> > Query OK, 1 row affected (0.00 sec)
> > Rows matched: 1 Changed: 1 Warnings: 0
> >
> > --
> > Cheers,
> > Rajan
> >

>
>
>
> --------------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.472 / Virus Database: 269.8.13/843 - Release Date: 6/10/2007
> 1:39 PM
>
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 06:35 AM
ViSolve DB Team
 
Posts: n/a
Default Re: how to get Number of rows matched?

Hi

Simple.. The query "feedback" will depict the matched & changed numbers.
mysql> update test set roll = 1, s = 'new' where roll = 1;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0


Thanks
ViSolve DB Team.
----- Original Message -----
From: "Ace" <rajan.halade@gmail.com>
To: "ViSolve DB Team" <mysqlsupport@visolve.com>
Cc: <mysql@lists.mysql.com>
Sent: Monday, June 11, 2007 5:04 PM
Subject: Re: how to get Number of rows matched?


> Ok..thanks! But my problem here is how to check if there were any matched
> rows when no rows were changed. mysql_affected_rows() will tell me the
> affected rows. Simmly, is there any routine using which one can know if
> there were any matched rows?
>
> Cheers,
> Rajan
>
> On 6/11/07, ViSolve DB Team <mysqlsupport@visolve.com> wrote:
>>
>> Hi
>>
>> AFAIK, before changing data, the old values are saved in the rollback
>> segment.
>> On saving the updated values, from the Buffer to the rollback segment/data
>> files,
>> --- it checks if there is any matched row that matches the condition. If
>> found, then flags "Matched".
>> ---after filtering out the matched row, it check whether there is need to
>> change the old value to new value. if need then flags "Changed" and
>> rewrite
>> the same in the datafile/rollback segment.
>>
>>
>> Thanks
>> ViSolve DB Team.
>> ----- Original Message -----
>> From: "Ace" <rajan.halade@gmail.com>
>> To: <mysql@lists.mysql.com>
>> Sent: Monday, June 11, 2007 11:41 AM
>> Subject: how to get Number of rows matched?
>>
>>
>> > Hi Experts,
>> >
>> > When issuing updates in mysql (in the console window), mysql will tell
>> > you if any rows matched and how many rows were updated (see below). I
>> > know how to get number of rows udpated using mysql_affected_rows(), but

>> is
>> > there any
>> > way to get the number of rows matched? I want to find out, when rows
>> > updated = 0, if there were no updates because the row wasn't found
>> > (rows matched will = 0) or because the update would not have changed
>> > any data (rows matched = 1).
>> >
>> > mysql> select * from test;
>> > +------+------+
>> > | roll | s |
>> > +------+------+
>> > | 1 | new |
>> > +------+------+
>> > 1 row in set (0.00 sec)
>> >
>> > mysql> update test set roll = 1, s = 'new' where roll = 1;
>> > Query OK, 0 rows affected (0.00 sec)
>> > Rows matched: 1 Changed: 0 Warnings: 0
>> >
>> > mysql> update test set roll = 1, s = 'new' where roll = 17;
>> > Query OK, 0 rows affected (0.00 sec)
>> > Rows matched: 0 Changed: 0 Warnings: 0
>> >
>> > mysql> update test set roll = 1, s = 'neww' where roll = 1;
>> > Query OK, 1 row affected (0.00 sec)
>> > Rows matched: 1 Changed: 1 Warnings: 0
>> >
>> > --
>> > Cheers,
>> > Rajan
>> >

>>
>>
>>
>> --------------------------------------------------------------------------------
>>
>>
>> No virus found in this incoming message.
>> Checked by AVG Free Edition.
>> Version: 7.5.472 / Virus Database: 269.8.13/843 - Release Date: 6/10/2007
>> 1:39 PM
>>
>>

>



--------------------------------------------------------------------------------


No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.472 / Virus Database: 269.8.13/843 - Release Date: 6/10/2007 1:39 PM

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 06:35 AM
Ace
 
Posts: n/a
Default Re: how to get Number of rows matched?

ok...That I know but I need it to check in my code...

On 6/11/07, ViSolve DB Team <mysqlsupport@visolve.com> wrote:
>
> Hi
>
> Simple.. The query "feedback" will depict the matched & changed numbers.
> mysql> update test set roll = 1, s = 'new' where roll = 1;
> Query OK, 0 rows affected (0.00 sec)
> * Rows matched: 1 Changed: 0 Warnings: 0
> *
>
> Thanks
> ViSolve DB Team.
> ----- Original Message ----- From: "Ace" <rajan.halade@gmail.com>
> To: "ViSolve DB Team" <mysqlsupport@visolve.com>
> Cc: <mysql@lists.mysql.com>
> Sent: Monday, June 11, 2007 5:04 PM
> Subject: Re: how to get Number of rows matched?
>
> > Ok..thanks! But my problem here is how to check if there were any

> matched
> > rows when no rows were changed. mysql_affected_rows() will tell me the
> > affected rows. Simmly, is there any routine using which one can know if
> > there were any matched rows?
> >
> > Cheers,
> > Rajan
> >
> > On 6/11/07, ViSolve DB Team <mysqlsupport@visolve.com> wrote:
> >>
> >> Hi
> >>
> >> AFAIK, before changing data, the old values are saved in the rollback
> >> segment.
> >> On saving the updated values, from the Buffer to the rollback

> segment/data
> >> files,
> >> --- it checks if there is any matched row that matches the condition.

> If
> >> found, then flags "Matched".
> >> ---after filtering out the matched row, it check whether there is need

> to
> >> change the old value to new value. if need then flags "Changed" and
> >> rewrite
> >> the same in the datafile/rollback segment.
> >>
> >>
> >> Thanks
> >> ViSolve DB Team.
> >> ----- Original Message -----
> >> From: "Ace" <rajan.halade@gmail.com>
> >> To: <mysql@lists.mysql.com>
> >> Sent: Monday, June 11, 2007 11:41 AM
> >> Subject: how to get Number of rows matched?
> >>
> >>
> >> > Hi Experts,
> >> >
> >> > When issuing updates in mysql (in the console window), mysql will

> tell
> >> > you if any rows matched and how many rows were updated (see below).

> I
> >> > know how to get number of rows udpated using mysql_affected_rows(),

> but
> >> is
> >> > there any
> >> > way to get the number of rows matched? I want to find out, when rows
> >> > updated = 0, if there were no updates because the row wasn't found
> >> > (rows matched will = 0) or because the update would not have changed
> >> > any data (rows matched = 1).
> >> >
> >> > mysql> select * from test;
> >> > +------+------+
> >> > | roll | s |
> >> > +------+------+
> >> > | 1 | new |
> >> > +------+------+
> >> > 1 row in set (0.00 sec)
> >> >
> >> > mysql> update test set roll = 1, s = 'new' where roll = 1;
> >> > Query OK, 0 rows affected (0.00 sec)
> >> > Rows matched: 1 Changed: 0 Warnings: 0
> >> >
> >> > mysql> update test set roll = 1, s = 'new' where roll = 17;
> >> > Query OK, 0 rows affected (0.00 sec)
> >> > Rows matched: 0 Changed: 0 Warnings: 0
> >> >
> >> > mysql> update test set roll = 1, s = 'neww' where roll = 1;
> >> > Query OK, 1 row affected (0.00 sec)
> >> > Rows matched: 1 Changed: 1 Warnings: 0
> >> >
> >> > --
> >> > Cheers,
> >> > Rajan
> >> >
> >>
> >>
> >>
> >>

> --------------------------------------------------------------------------------
> >>
> >>
> >> No virus found in this incoming message.
> >> Checked by AVG Free Edition.
> >> Version: 7.5.472 / Virus Database: 269.8.13/843 - Release Date:

> 6/10/2007
> >> 1:39 PM
> >>
> >>

> >

>
> ------------------------------
>
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.472 / Virus Database: 269.8.13/843 - Release Date: 6/10/2007
> 1:39 PM
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 06:35 AM
Jerry Schwartz
 
Posts: n/a
Default RE: how to get Number of rows matched?

Have you looked at mysql_info()? The format of the return value might not be
the most useful, but it should give you what you need.

Regards,

Jerry Schwartz
The Infoshop by Global Information Incorporated
195 Farmington Ave.
Farmington, CT 06032

860.674.8796 / FAX: 860.674.8341

www.the-infoshop.com
www.giiexpress.com
www.etudes-marche.com


> -----Original Message-----
> From: ViSolve DB Team [mailto:mysqlsupport@visolve.com]
> Sent: Monday, June 11, 2007 6:15 AM
> To: Ace; mysql@lists.mysql.com
> Subject: Re: how to get Number of rows matched?
>
> Hi
>
> AFAIK, before changing data, the old values are saved in the rollback
> segment.
> On saving the updated values, from the Buffer to the rollback
> segment/data
> files,
> --- it checks if there is any matched row that matches the
> condition. If
> found, then flags "Matched".
> ---after filtering out the matched row, it check whether
> there is need to
> change the old value to new value. if need then flags
> "Changed" and rewrite
> the same in the datafile/rollback segment.
>
>
> Thanks
> ViSolve DB Team.
> ----- Original Message -----
> From: "Ace" <rajan.halade@gmail.com>
> To: <mysql@lists.mysql.com>
> Sent: Monday, June 11, 2007 11:41 AM
> Subject: how to get Number of rows matched?
>
>
> > Hi Experts,
> >
> > When issuing updates in mysql (in the console window),

> mysql will tell
> > you if any rows matched and how many rows were updated (see

> below). I
> > know how to get number of rows udpated using

> mysql_affected_rows(), but is
> > there any
> > way to get the number of rows matched? I want to find out,

> when rows
> > updated = 0, if there were no updates because the row wasn't found
> > (rows matched will = 0) or because the update would not have changed
> > any data (rows matched = 1).
> >
> > mysql> select * from test;
> > +------+------+
> > | roll | s |
> > +------+------+
> > | 1 | new |
> > +------+------+
> > 1 row in set (0.00 sec)
> >
> > mysql> update test set roll = 1, s = 'new' where roll = 1;
> > Query OK, 0 rows affected (0.00 sec)
> > Rows matched: 1 Changed: 0 Warnings: 0
> >
> > mysql> update test set roll = 1, s = 'new' where roll = 17;
> > Query OK, 0 rows affected (0.00 sec)
> > Rows matched: 0 Changed: 0 Warnings: 0
> >
> > mysql> update test set roll = 1, s = 'neww' where roll = 1;
> > Query OK, 1 row affected (0.00 sec)
> > Rows matched: 1 Changed: 1 Warnings: 0
> >
> > --
> > Cheers,
> > Rajan
> >

>
>
> --------------------------------------------------------------
> ------------------
>
>
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.472 / Virus Database: 269.8.13/843 - Release
> Date: 6/10/2007
> 1:39 PM
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
> http://lists.mysql.com/mysql?unsub=j...e-infoshop.com
>
>




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-28-2008, 06:35 AM
Ace
 
Posts: n/a
Default Re: how to get Number of rows matched?

Yes, you are right! mysql_info() is not most useful. It does give me number
of rows matched but will involve complications of parsing the string.

Is there no other way to this? How can this be missed? I am not so
convinienced on mysql_info()!


On 6/11/07, Jerry Schwartz <jschwartz@the-infoshop.com> wrote:
>
> Have you looked at mysql_info()? The format of the return value might not
> be
> the most useful, but it should give you what you need.
>
> Regards,
>
> Jerry Schwartz
> The Infoshop by Global Information Incorporated
> 195 Farmington Ave.
> Farmington, CT 06032
>
> 860.674.8796 / FAX: 860.674.8341
>
> www.the-infoshop.com
> www.giiexpress.com
> www.etudes-marche.com
>
>
> > -----Original Message-----
> > From: ViSolve DB Team [mailto:mysqlsupport@visolve.com]
> > Sent: Monday, June 11, 2007 6:15 AM
> > To: Ace; mysql@lists.mysql.com
> > Subject: Re: how to get Number of rows matched?
> >
> > Hi
> >
> > AFAIK, before changing data, the old values are saved in the rollback
> > segment.
> > On saving the updated values, from the Buffer to the rollback
> > segment/data
> > files,
> > --- it checks if there is any matched row that matches the
> > condition. If
> > found, then flags "Matched".
> > ---after filtering out the matched row, it check whether
> > there is need to
> > change the old value to new value. if need then flags
> > "Changed" and rewrite
> > the same in the datafile/rollback segment.
> >
> >
> > Thanks
> > ViSolve DB Team.
> > ----- Original Message -----
> > From: "Ace" <rajan.halade@gmail.com>
> > To: <mysql@lists.mysql.com>
> > Sent: Monday, June 11, 2007 11:41 AM
> > Subject: how to get Number of rows matched?
> >
> >
> > > Hi Experts,
> > >
> > > When issuing updates in mysql (in the console window),

> > mysql will tell
> > > you if any rows matched and how many rows were updated (see

> > below). I
> > > know how to get number of rows udpated using

> > mysql_affected_rows(), but is
> > > there any
> > > way to get the number of rows matched? I want to find out,

> > when rows
> > > updated = 0, if there were no updates because the row wasn't found
> > > (rows matched will = 0) or because the update would not have changed
> > > any data (rows matched = 1).
> > >
> > > mysql> select * from test;
> > > +------+------+
> > > | roll | s |
> > > +------+------+
> > > | 1 | new |
> > > +------+------+
> > > 1 row in set (0.00 sec)
> > >
> > > mysql> update test set roll = 1, s = 'new' where roll = 1;
> > > Query OK, 0 rows affected (0.00 sec)
> > > Rows matched: 1 Changed: 0 Warnings: 0
> > >
> > > mysql> update test set roll = 1, s = 'new' where roll = 17;
> > > Query OK, 0 rows affected (0.00 sec)
> > > Rows matched: 0 Changed: 0 Warnings: 0
> > >
> > > mysql> update test set roll = 1, s = 'neww' where roll = 1;
> > > Query OK, 1 row affected (0.00 sec)
> > > Rows matched: 1 Changed: 1 Warnings: 0
> > >
> > > --
> > > Cheers,
> > > Rajan
> > >

> >
> >
> > --------------------------------------------------------------
> > ------------------
> >
> >
> > No virus found in this incoming message.
> > Checked by AVG Free Edition.
> > Version: 7.5.472 / Virus Database: 269.8.13/843 - Release
> > Date: 6/10/2007
> > 1:39 PM
> >
> >
> > --
> > MySQL General Mailing List
> > For list archives: http://lists.mysql.com/mysql
> > To unsubscribe:
> > http://lists.mysql.com/mysql?unsub=j...e-infoshop.com
> >
> >

>
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-28-2008, 06:36 AM
Ace
 
Posts: n/a
Default Re: how to get Number of rows matched?

Thanks All for your help!

If someone from MySQL team is looking at this mail thread, we request to
include this feature in future release.

Cheers,
Rajan
On 6/11/07, Michael Dykman <mdykman@gmail.com> wrote:
>
> no, there is nothing else. There are cleaner interfaces to this
> information but, for PHP. the string returned by mysql_info() is all
> you get. The format of that string is very regular and we have been
> using it in production software for well over a year now with no
> issues.
>
> - michael
>
>
> On 6/11/07, Ace <rajan.halade@gmail.com> wrote:
> > Yes, you are right! mysql_info() is not most useful. It does give me

> number
> > of rows matched but will involve complications of parsing the string.
> >
> > Is there no other way to this? How can this be missed? I am not so
> > convinienced on mysql_info()!
> >
> >
> > On 6/11/07, Jerry Schwartz <jschwartz@the-infoshop.com> wrote:
> > >
> > > Have you looked at mysql_info()? The format of the return value might

> not
> > > be
> > > the most useful, but it should give you what you need.
> > >
> > > Regards,
> > >
> > > Jerry Schwartz
> > > The Infoshop by Global Information Incorporated
> > > 195 Farmington Ave.
> > > Farmington, CT 06032
> > >
> > > 860.674.8796 / FAX: 860.674.8341
> > >
> > > www.the-infoshop.com
> > > www.giiexpress.com
> > > www.etudes-marche.com
> > >
> > >
> > > > -----Original Message-----
> > > > From: ViSolve DB Team [mailto:mysqlsupport@visolve.com]
> > > > Sent: Monday, June 11, 2007 6:15 AM
> > > > To: Ace; mysql@lists.mysql.com
> > > > Subject: Re: how to get Number of rows matched?
> > > >
> > > > Hi
> > > >
> > > > AFAIK, before changing data, the old values are saved in the

> rollback
> > > > segment.
> > > > On saving the updated values, from the Buffer to the rollback
> > > > segment/data
> > > > files,
> > > > --- it checks if there is any matched row that matches the
> > > > condition. If
> > > > found, then flags "Matched".
> > > > ---after filtering out the matched row, it check whether
> > > > there is need to
> > > > change the old value to new value. if need then flags
> > > > "Changed" and rewrite
> > > > the same in the datafile/rollback segment.
> > > >
> > > >
> > > > Thanks
> > > > ViSolve DB Team.
> > > > ----- Original Message -----
> > > > From: "Ace" <rajan.halade@gmail.com>
> > > > To: <mysql@lists.mysql.com>
> > > > Sent: Monday, June 11, 2007 11:41 AM
> > > > Subject: how to get Number of rows matched?
> > > >
> > > >
> > > > > Hi Experts,
> > > > >
> > > > > When issuing updates in mysql (in the console window),
> > > > mysql will tell
> > > > > you if any rows matched and how many rows were updated (see
> > > > below). I
> > > > > know how to get number of rows udpated using
> > > > mysql_affected_rows(), but is
> > > > > there any
> > > > > way to get the number of rows matched? I want to find out,
> > > > when rows
> > > > > updated = 0, if there were no updates because the row wasn't found
> > > > > (rows matched will = 0) or because the update would not have

> changed
> > > > > any data (rows matched = 1).
> > > > >
> > > > > mysql> select * from test;
> > > > > +------+------+
> > > > > | roll | s |
> > > > > +------+------+
> > > > > | 1 | new |
> > > > > +------+------+
> > > > > 1 row in set (0.00 sec)
> > > > >
> > > > > mysql> update test set roll = 1, s = 'new' where roll = 1;
> > > > > Query OK, 0 rows affected (0.00 sec)
> > > > > Rows matched: 1 Changed: 0 Warnings: 0
> > > > >
> > > > > mysql> update test set roll = 1, s = 'new' where roll = 17;
> > > > > Query OK, 0 rows affected (0.00 sec)
> > > > > Rows matched: 0 Changed: 0 Warnings: 0
> > > > >
> > > > > mysql> update test set roll = 1, s = 'neww' where roll = 1;
> > > > > Query OK, 1 row affected (0.00 sec)
> > > > > Rows matched: 1 Changed: 1 Warnings: 0
> > > > >
> > > > > --
> > > > > Cheers,
> > > > > Rajan
> > > > >
> > > >
> > > >
> > > > --------------------------------------------------------------
> > > > ------------------
> > > >
> > > >
> > > > No virus found in this incoming message.
> > > > Checked by AVG Free Edition.
> > > > Version: 7.5.472 / Virus Database: 269.8.13/843 - Release
> > > > Date: 6/10/2007
> > > > 1:39 PM
> > > >
> > > >
> > > > --
> > > > MySQL General Mailing List
> > > > For list archives: http://lists.mysql.com/mysql
> > > > To unsubscribe:
> > > > http://lists.mysql.com/mysql?unsub=j...e-infoshop.com
> > > >
> > > >
> > >
> > >

> >

>
>
> --
> - michael dykman
> - mdykman@gmail.com
>
> - All models are wrong. Some models are useful.
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-28-2008, 06:40 AM
Paul DuBois
 
Posts: n/a
Default Re: how to get Number of rows matched?

At 11:11 PM -0700 6/10/07, Ace wrote:
>Hi Experts,
>
>When issuing updates in mysql (in the console window), mysql will tell
>you if any rows matched and how many rows were updated (see below). I
>know how to get number of rows udpated using mysql_affected_rows(), but is
>there any
>way to get the number of rows matched? I want to find out, when rows
>updated = 0, if there were no updates because the row wasn't found
>(rows matched will = 0) or because the update would not have changed
>any data (rows matched = 1).


Pass the CLIENT_FOUND_ROWS flag value to mysql_real_connect() when
you connect to the server.

http://dev.mysql.com/doc/refman/5.0/...l-connect.html

>
>mysql> select * from test;
>+------+------+
>| roll | s |
>+------+------+
>| 1 | new |
>+------+------+
>1 row in set (0.00 sec)
>
>mysql> update test set roll = 1, s = 'new' where roll = 1;
>Query OK, 0 rows affected (0.00 sec)
>Rows matched: 1 Changed: 0 Warnings: 0
>
>mysql> update test set roll = 1, s = 'new' where roll = 17;
>Query OK, 0 rows affected (0.00 sec)
>Rows matched: 0 Changed: 0 Warnings: 0
>
>mysql> update test set roll = 1, s = 'neww' where roll = 1;
>Query OK, 1 row affected (0.00 sec)
>Rows matched: 1 Changed: 1 Warnings: 0
>
>--
>Cheers,
>Rajan



--
Paul DuBois, MySQL Documentation Team
Madison, Wisconsin, USA
MySQL AB, www.mysql.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:42 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 34