PHP-1294: Emtpy Query Result should still return QueryResult

This commit is contained in:
Hannes Magnusson
2014-11-26 13:03:18 -08:00
parent 183286a2fc
commit bccdd2771f
3 changed files with 27 additions and 10 deletions

View File

@@ -219,8 +219,7 @@ void phongo_result_init(zval *return_value, zend_class_entry *result_class, mong
} else {
result->hint = server_hint;
}
/* FIXME: Support empty result cursor. eg. when there simply aren't any matches for a query */
result->firstBatch = bson_copy(bson);
result->firstBatch = bson ? bson_copy(bson) : NULL;
} /* }}} */
void phongo_server_init(zval *return_value, int hint, mongoc_host_list_t *host TSRMLS_DC) /* {{{ */
@@ -580,14 +579,13 @@ int phongo_execute_query(mongoc_client_t *client, char *namespace, php_phongo_qu
if (!mongoc_cursor_next(cursor, &doc)) {
bson_error_t error;
/* Could simply be no docs, which is not an error */
if (mongoc_cursor_error(cursor, &error)) {
phongo_throw_exception_from_bson_error_t(&error TSRMLS_CC);
mongoc_cursor_destroy(cursor);
return false;
}
mongoc_cursor_destroy(cursor);
return false;
}
if (!return_value_used) {

View File

@@ -20,12 +20,7 @@ printWriteResult($result);
echo "\n===> Collection\n";
$cursor = $manager->executeQuery(NS, new MongoDB\Query(array()));
/* FIXME: Returns NULL, not empty iterator when nothing matches */
if ($cursor) {
var_dump(iterator_to_array($cursor));
} else {
var_dump(array());
}
var_dump(iterator_to_array($cursor));
?>
===DONE===

View File

@@ -0,0 +1,24 @@
--TEST--
MongoDB\Manager::executeDelete() multiple documents
--SKIPIF--
<?php require "tests/utils/basic-skipif.inc" ?>
--FILE--
<?php
require_once "tests/utils/basic.inc";
$manager = new MongoDB\Manager(MONGODB_URI);
$manager->executeInsert(NS, array('_id' => 1, 'x' => 1));
$manager->executeInsert(NS, array('_id' => 2, 'x' => 1));
$cursor = $manager->executeQuery(NS, new MongoDB\Query(array("x" => 2)));
var_dump(iterator_to_array($cursor));
?>
===DONE===
<?php exit(0); ?>
--EXPECT--
array(0) {
}
===DONE===