Home » Database » DB_DataObject » Bug #3979
find() always returns 1
Details
| Submitted | 2005-03-28 17:01 UTC |
|---|---|
| From | roger dot gibby at lsvi dot com |
| Assigned | alan_k |
| Status | Closed |
| Package | DB_DataObject |
| PHP Version | 4.3.8 |
| OS | Windows 2000 |
| Roadmaps | (Not assigned) |
Comments
[2005-03-28 17:01 UTC] roger dot gibby at lsvi dot com
Description:
------------
I have the latest version of db_dataobject installed, 1.7.13.
I am using SQLServer as my database.
I am using odbc to connect to the database.
I am using whereAdd's to build my where clause.
On an empty result (no records found), I still get a 1 as the returned result. Even when I pass true to fetch the first result, I still get 1 returned, but as expected no values are fetched.
I would expect 0 to be returned if there are no rows found matching the where clause.
Here is my dataobject:
dataobjects_incident_relations Object
(
[_DB_DataObject_version] => 1.7.13
[__table] => incident_relations
[N] => 1
[_database_dsn] =>
[_database_dsn_md5] => 71831719a973a04dbcf505df88c0a1c2
[_database] => lsvismp
[_query] => Array
(
[condition] => WHERE cust_id = 18 AND master_ticket = 10 AND related_ticket = 9
[group_by] =>
[order_by] =>
[having] =>
[limit_start] =>
[limit_count] =>
[data_select] => *
)
[_DB_resultid] => 1
[_link_loaded] =>
[_join] =>
[_lastError] =>
[cust_id] =>
[master_ticket] =>
[related_ticket] =>
)
I've also tried as where clause that would return mutiple rows, but 1 is also returned, not the true row count.
Reproduce code:
---------------
Create a table: incident_relations
3 columns all integer: cust_id, master_ticket, related_ticket
require_once(DBOBJECTS . "Incident_relations.php");
$inc = new DataObjects_Incident_relations();
$inc->whereAdd("cust_id = ".$cust_id);
$inc->whereAdd("master_ticket = ".$ticket_id);
$inc->whereAdd("related_ticket = ".$related);
$numRows = $inc->find();
Expected result:
----------------
I expect a 0 to be returned when no rows are found.
Actual result:
--------------
The actual result is 1
[2005-03-31 00:46 UTC] roger dot gibby at lsvi dot com
The documentation does not mention that 1 would be returned if numrows is not supported by the db. How does one know if there is one row found or numrows is not supported? It seems that if it is not supported it should return something other than 1. One is interpreted as true, so even when no rows are found it returns true. I workaround has been to fetch the first row with the find and check the key data to see if it is set.
if ($v->find(TRUE) && isset($v->key_data))
Documentation should be changed to reflect the real return results, so programmers can predict the outcome.