<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: possible bug in sa16 PHP sasql_affected_rows? in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/possible-bug-in-sa16-php-sasql-affected-rows/qaa-p/13846342#M4877185</link>
    <description>&lt;P&gt;Here's a better example: change the above query to:&lt;/P&gt;
&lt;PRE&gt;UPDATE SalesOrderItems SET Quantity = Quantity + 1;
&lt;/PRE&gt;

&lt;P&gt;It gives the results:&lt;/P&gt;
&lt;PRE&gt;sasql_query() UPDATE SalesOrderItems SET Quantity = Quantity + 1;
sasql_affected_rows()=1097
sasql_stmt_execute() UPDATE SalesOrderItems SET Quantity = Quantity + 1;
sasql_affected_rows()=0
&lt;/PRE&gt;

&lt;P&gt;1097 for sasql_query() and 0 for sasql_stmt_execute().&lt;/P&gt;</description>
    <pubDate>Tue, 04 Nov 2014 15:06:24 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2014-11-04T15:06:24Z</dc:date>
    <item>
      <title>possible bug in sa16 PHP sasql_affected_rows?</title>
      <link>https://community.sap.com/t5/technology-q-a/possible-bug-in-sa16-php-sasql-affected-rows/qaq-p/13846338</link>
      <description>&lt;P&gt;I'm getting different results from sasql_affected_rows() with sasql_query() vs sasql_stmt_execute() and I can't see what I'm doing wrong.  (I use sasql_stmt_execute() because I use prepared statements.)&lt;/P&gt;
&lt;P&gt;After sasql_query, I get the proper number of rows, while after sasql_stmt_execute, the affected rows are always zero.
Here's my test code:
&lt;/P&gt;&lt;PRE&gt;    $cstring = "DSN=demo16;UID=DBA;PWD=sql";
    $sql = "UPDATE Customers SET ID = ID;";&lt;P&gt;&lt;/P&gt;
&lt;PRE class="codehilite"&gt;&lt;CODE&gt;//test 1
$conn = sasql_connect( $cstring );
sasql_set_option( $conn, "auto_commit", "off" );
print "sasql_query() $sql\\n";
$rs = sasql_query( $conn, $sql );
print "sasql_affected_rows()=".sasql_affected_rows($conn)."\\n";
sasql_close( $conn );

//test 2
$conn = sasql_connect( $cstring );
sasql_set_option( $conn, "auto_commit", "off" );
print "sasql_stmt_execute() $sql\\n";
$pstmt = sasql_prepare( $conn, $sql );
sasql_stmt_execute( $pstmt );   
print "sasql_affected_rows()=".sasql_affected_rows($conn)."\\n";
sasql_close( $conn );


&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and the output is:
&lt;/P&gt;&lt;PRE&gt;sasql_query() UPDATE Customers SET ID = ID;
sasql_affected_rows()=126
sasql_stmt_execute() UPDATE Customers SET ID = ID;
sasql_affected_rows()=0
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Has anyone else seen this?  &lt;/P&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Nov 2014 16:18:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/possible-bug-in-sa16-php-sasql-affected-rows/qaq-p/13846338</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-11-03T16:18:08Z</dc:date>
    </item>
    <item>
      <title>Re: possible bug in sa16 PHP sasql_affected_rows?</title>
      <link>https://community.sap.com/t5/technology-q-a/possible-bug-in-sa16-php-sasql-affected-rows/qaa-p/13846339#M4877182</link>
      <description>&lt;P&gt;Maybe I missed something important but the operation&lt;/P&gt;
&lt;PRE class="codehilite"&gt;&lt;CODE&gt;UPDATE Customers SET ID = ID;


&lt;P&gt;by definition makes no changes.  In SQL anywhere that will always affect 0 rows, and will not even get logged.&lt;/P&gt;
&lt;P&gt;The difference here is that the sasql_stmt_execute() execution only performs the update (thus rowcount==0) where as the sasql_affected_rows() execution returns the result set of candidate rows (thus a rowcount &amp;gt;0).  &lt;/P&gt;
&lt;P&gt;This difference is because of a new feature introduced in version 12.0 documented as &lt;A href="http://dcx.sybase.com/index.html#sa160/en/sachanges/newinnsbruck-sectc-3659400.html"&gt;"Support for selecting from DML statements"&lt;/A&gt; . Look to the 3rd from last item near the bottom.&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Nov 2014 12:16:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/possible-bug-in-sa16-php-sasql-affected-rows/qaa-p/13846339#M4877182</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-11-04T12:16:41Z</dc:date>
    </item>
    <item>
      <title>Re: possible bug in sa16 PHP sasql_affected_rows?</title>
      <link>https://community.sap.com/t5/technology-q-a/possible-bug-in-sa16-php-sasql-affected-rows/qaa-p/13846341#M4877184</link>
      <description>&lt;P&gt;Thanks for the answer, Nick - however, I probably used too simple an example.  In my real use-case, the update does in fact change some column values, but I still get sasql_affected_rows() returning 0;&lt;/P&gt;
&lt;P&gt;Also, if it really has something to do with ID not changing in my example above, why does get sasql_affected_rows() return 126 after sasql_query() in test1, but 0 after sasql_stmt_execute() in test2?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Nov 2014 13:13:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/possible-bug-in-sa16-php-sasql-affected-rows/qaa-p/13846341#M4877184</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-11-04T13:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: possible bug in sa16 PHP sasql_affected_rows?</title>
      <link>https://community.sap.com/t5/technology-q-a/possible-bug-in-sa16-php-sasql-affected-rows/qaa-p/13846342#M4877185</link>
      <description>&lt;P&gt;Here's a better example: change the above query to:&lt;/P&gt;
&lt;PRE&gt;UPDATE SalesOrderItems SET Quantity = Quantity + 1;
&lt;/PRE&gt;

&lt;P&gt;It gives the results:&lt;/P&gt;
&lt;PRE&gt;sasql_query() UPDATE SalesOrderItems SET Quantity = Quantity + 1;
sasql_affected_rows()=1097
sasql_stmt_execute() UPDATE SalesOrderItems SET Quantity = Quantity + 1;
sasql_affected_rows()=0
&lt;/PRE&gt;

&lt;P&gt;1097 for sasql_query() and 0 for sasql_stmt_execute().&lt;/P&gt;</description>
      <pubDate>Tue, 04 Nov 2014 15:06:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/possible-bug-in-sa16-php-sasql-affected-rows/qaa-p/13846342#M4877185</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-11-04T15:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: possible bug in sa16 PHP sasql_affected_rows?</title>
      <link>https://community.sap.com/t5/technology-q-a/possible-bug-in-sa16-php-sasql-affected-rows/qaa-p/13846343#M4877186</link>
      <description>&lt;P&gt;It looks like I (or someone else) will need to take a closer/deeper look at this ...&lt;/P&gt;</description>
      <pubDate>Wed, 05 Nov 2014 10:51:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/possible-bug-in-sa16-php-sasql-affected-rows/qaa-p/13846343#M4877186</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-11-05T10:51:55Z</dc:date>
    </item>
    <item>
      <title>Re: possible bug in sa16 PHP sasql_affected_rows?</title>
      <link>https://community.sap.com/t5/technology-q-a/possible-bug-in-sa16-php-sasql-affected-rows/qaa-p/13846340#M4877183</link>
      <description>&lt;P&gt;The function you need to use for the sasql_stmt_execute() case is a different one &lt;/P&gt;
&lt;PRE class="codehilite"&gt;&lt;CODE&gt; int sasql_stmt_affected_rows( sasql_stmt $stmt )


&lt;P&gt;&lt;A href="http://dcx.sybase.com/index.html#sa160/en/dbprogramming/php-stmt-affected-rows.html"&gt;http://dcx.sybase.com/index.html#sa160/en/dbprogramming/php-stmt-affected-rows.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Calling sasql_affected_rows() is picking up the result set from the connection object and thus the last query.&lt;/P&gt;
&lt;P&gt;Hopefully this will make this a little clearer.&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Dec 2014 16:01:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/possible-bug-in-sa16-php-sasql-affected-rows/qaa-p/13846340#M4877183</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-12-01T16:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: possible bug in sa16 PHP sasql_affected_rows?</title>
      <link>https://community.sap.com/t5/technology-q-a/possible-bug-in-sa16-php-sasql-affected-rows/qaa-p/13846344#M4877187</link>
      <description>&lt;P&gt;Nick, thanks a lot for looking into this - big help!  I should have been able to see that &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Dec 2014 17:18:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/possible-bug-in-sa16-php-sasql-affected-rows/qaa-p/13846344#M4877187</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-12-01T17:18:19Z</dc:date>
    </item>
  </channel>
</rss>

