From 440d46262c903b057ab5f88005af11b698e2ec5e Mon Sep 17 00:00:00 2001
From: Konstantin Shulgin <konstantin.shulgin@gmail.com>
Date: Mon, 19 Dec 2011 17:24:17 +0400
Subject: [PATCH] feature-php-driver-refactoring:

Error test from server's responce was added to exceptions.
---
 connector/php/tarantool.c                     | 33 +++++++++++++++----
 connector/php/test/call.phpt                  |  2 +-
 connector/php/test/delete.phpt                |  2 +-
 connector/php/test/insert.phpt                |  4 +--
 .../php/test/lib/php/tarantool_utest.php      |  4 +--
 connector/php/test/update_fields.phpt         |  2 +-
 6 files changed, 33 insertions(+), 14 deletions(-)

diff --git a/connector/php/tarantool.c b/connector/php/tarantool.c
index 90283c99ec..e28f70396b 100644
--- a/connector/php/tarantool.c
+++ b/connector/php/tarantool.c
@@ -125,8 +125,12 @@ struct tnt_call_request {
 struct tnt_response {
 	/* return code */
 	int32_t return_code;
-	/* count */
-	int32_t count;
+	union {
+		/* count */
+		int32_t count;
+		/* error message */
+		char return_msg[0];
+	};
 } __attribute__((packed));
 
 
@@ -585,7 +589,10 @@ PHP_METHOD(tarantool_class, select)
 	if (response->return_code) {
 		/* error happen, throw exceprion */
 		zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_DC,
-								"select failed: %"PRIi32, response->return_code);
+								"select failed: %"PRIi32"(0x%08"PRIx32"): %s",
+								response->return_code,
+								response->return_code,
+								response->return_msg);
 		return;
 	}
 
@@ -703,7 +710,10 @@ PHP_METHOD(tarantool_class, insert)
 	if (response->return_code) {
 		/* error happen, throw exceprion */
 		zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_DC,
-								"insert failed: %"PRIi32, response->return_code);
+								"insert failed: %"PRIi32"(0x%08"PRIx32"): %s",
+								response->return_code,
+								response->return_code,
+								response->return_msg);
 		return;
 	}
 	
@@ -947,7 +957,10 @@ PHP_METHOD(tarantool_class, update_fields)
 	if (response->return_code) {
 		/* error happen, throw exceprion */
 		zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_DC,
-								"update fields failed: %"PRIi32, response->return_code);
+								"update fields failed: %"PRIi32"(0x%08"PRIx32"): %s",
+								response->return_code,
+								response->return_code,
+								response->return_msg);
 		return;
 	}
 	
@@ -1059,7 +1072,10 @@ PHP_METHOD(tarantool_class, delete)
 	if (response->return_code) {
 		/* error happen, throw exceprion */
 		zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_DC,
-								"delete failed: %"PRIi32, response->return_code);
+								"delete failed: %"PRIi32"(0x%08"PRIx32"): %s",
+								response->return_code,
+								response->return_code,
+								response->return_msg);
 		return;
 	}
 	
@@ -1174,7 +1190,10 @@ PHP_METHOD(tarantool_class, call)
 	if (response->return_code) {
 		/* error happen, throw exceprion */
 		zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_DC,
-								"call failed: %"PRIi32, response->return_code);
+								"call failed: %"PRIi32"(0x%08"PRIx32"): %s",
+								response->return_code,
+								response->return_code,
+								response->return_msg);
 		return;
 	}
 
diff --git a/connector/php/test/call.phpt b/connector/php/test/call.phpt
index 5a28f0a8dc..3268d55592 100644
--- a/connector/php/test/call.phpt
+++ b/connector/php/test/call.phpt
@@ -87,7 +87,7 @@ freedom to the galaxy....
 
 ---------- test begin ----------
 test call: call undefined function (expected error exception)
-catched exception: call failed: 12802
+catched exception: call failed: 12802(0x00003202): Procedure 'fafagaga' is not defined
 ----------- test end -----------
 
 ===DONE===
\ No newline at end of file
diff --git a/connector/php/test/delete.phpt b/connector/php/test/delete.phpt
index 7b37a7ba93..6258697895 100644
--- a/connector/php/test/delete.phpt
+++ b/connector/php/test/delete.phpt
@@ -54,7 +54,7 @@ catched exception: unsupported field type
 
 ---------- test begin ----------
 test delete: invalid key (expected error exception)
-catched exception: delete failed: 514
+catched exception: delete failed: 514(0x00000202): Illegal parameters, key must be single valued
 ----------- test end -----------
 
 ---------- test begin ----------
diff --git a/connector/php/test/insert.phpt b/connector/php/test/insert.phpt
index 047db2a297..20a8512b60 100644
--- a/connector/php/test/insert.phpt
+++ b/connector/php/test/insert.phpt
@@ -100,12 +100,12 @@ count = 1
 
 ---------- test begin ----------
 test insert: add existed tuple (expected error exception)
-catched exception: insert failed: 14082
+catched exception: insert failed: 14082(0x00003702): Tuple already exists
 ----------- test end -----------
 
 ---------- test begin ----------
 test insert: replace not existed tuple (expected error exception)
-catched exception: insert failed: 12546
+catched exception: insert failed: 12546(0x00003102): Tuple doesn't exist
 ----------- test end -----------
 
 ---------- test begin ----------
diff --git a/connector/php/test/lib/php/tarantool_utest.php b/connector/php/test/lib/php/tarantool_utest.php
index 6371d7cef1..7e4de7aac4 100644
--- a/connector/php/test/lib/php/tarantool_utest.php
+++ b/connector/php/test/lib/php/tarantool_utest.php
@@ -160,9 +160,9 @@ function test_delete($tarantool, $space_no, $key, $flags) {
     }
 }
 
-function test_call($tarantool, $proc, $key, $flags) {
+function test_call($tarantool, $proc, $tuple_args, $flags) {
     try {
-        $result = $tarantool->call($proc, $key, $flags);
+        $result = $tarantool->call($proc, $tuple_args, $flags);
         echo "result:\n";
         echo "count = ", $result["count"], "\n";
         $tuples_list = $result["tuples_list"];
diff --git a/connector/php/test/update_fields.phpt b/connector/php/test/update_fields.phpt
index d9a02ef041..620a7e4cc7 100644
--- a/connector/php/test/update_fields.phpt
+++ b/connector/php/test/update_fields.phpt
@@ -57,7 +57,7 @@ test_clean($tarantool, 0);
 --EXPECT--
 ---------- test begin ----------
 test update fields: do update w/o operations (expected error exception)
-catched exception: update fields failed: 514
+catched exception: update fields failed: 514(0x00000202): Illegal parameters, no operations for update
 ----------- test end -----------
 
 ---------- test begin ----------
-- 
GitLab