Permalink
Browse files

fixed key index bug in rds_json's result

  • Loading branch information...
1 parent 8f303ee commit d660cbf98cc671ecd2d9f07b40226aa8e9ddc63b @liseen liseen committed May 22, 2012
Showing with 47 additions and 46 deletions.
  1. +44 −43 src/ngx_http_rds_json_output.c
  2. +3 −3 t/property.t
@@ -140,27 +140,10 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r,
size = sizeof("{") - 1
+ conf->errcode_key.len
+ sizeof(":") - 1
-- + ngx_get_num_size(header->std_errcode)
+ + ngx_get_num_size(header->std_errcode)
+ sizeof("}") - 1
;
- if (header->errstr.len) {
- escape = ngx_http_rds_json_escape_json_str(NULL, header->errstr.data,
- header->errstr.len);
-
- size += sizeof(",") - 1
- + conf->errstr_key.len
- + sizeof(":") - 1
- + sizeof("\"") - 1
- + header->errstr.len
- + escape
- + sizeof("\"") - 1
- ;
-
- } else {
- escape = (uintptr_t) 0;
- }
-
if (conf->success.len) {
size += conf->success.len + sizeof(":,") - 1;
if (header->std_errcode == 0) {
@@ -199,6 +182,24 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r,
}
}
+
+ if (header->errstr.len) {
+ escape = ngx_http_rds_json_escape_json_str(NULL, header->errstr.data,
+ header->errstr.len);
+
+ size += sizeof(",") - 1
+ + conf->errstr_key.len
+ + sizeof(":") - 1
+ + sizeof("\"") - 1
+ + header->errstr.len
+ + escape
+ + sizeof("\"") - 1
+ ;
+
+ } else {
+ escape = (uintptr_t) 0;
+ }
+
if (header->insert_id) {
size += sizeof(",\"insert_id\":") - 1
+ ngx_get_num_size(header->insert_id)
@@ -223,31 +224,6 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r,
/* fill up the buffer */
*last++ = '{';
- last = ngx_copy(last, conf->errcode_key.data, conf->errcode_key.len);
- *last++ = ':';
-
- last = ngx_snprintf(last, NGX_UINT16_LEN, "%uD",
- (uint32_t) header->std_errcode);
-
- if (header->errstr.len) {
- *last++ = ',';
- last = ngx_copy(last,
- conf->errstr_key.data, conf->errstr_key.len);
- *last++ = ':';
- *last++ = '"';
-
- if (escape == 0) {
- last = ngx_copy(last, header->errstr.data,
- header->errstr.len);
-
- } else {
- last = (u_char *) ngx_http_rds_json_escape_json_str(last,
- header->errstr.data, header->errstr.len);
- }
-
- *last++ = '"';
- }
-
if (conf->success.len) {
last = ngx_copy(last, conf->success.data, conf->success.len);
@@ -279,6 +255,31 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r,
}
}
+ last = ngx_copy(last, conf->errcode_key.data, conf->errcode_key.len);
+ *last++ = ':';
+
+ last = ngx_snprintf(last, NGX_UINT16_LEN, "%uD",
+ (uint32_t) header->std_errcode);
+
+ if (header->errstr.len) {
+ *last++ = ',';
+ last = ngx_copy(last,
+ conf->errstr_key.data, conf->errstr_key.len);
+ *last++ = ':';
+ *last++ = '"';
+
+ if (escape == 0) {
+ last = ngx_copy(last, header->errstr.data,
+ header->errstr.len);
+
+ } else {
+ last = (u_char *) ngx_http_rds_json_escape_json_str(last,
+ header->errstr.data, header->errstr.len);
+ }
+
+ *last++ = '"';
+ }
+
if (header->insert_id) {
last = ngx_copy_literal(last, ",\"insert_id\":");
last = ngx_snprintf(last, NGX_UINT64_LEN, "%uL",
View
@@ -215,7 +215,7 @@ GET /mysql
GET /mysql
--- response_body chop
{"success":true,"errcode":0,"errstr":"Rows matched: 1 Changed: 0 Warnings: 0"}
---- ONLY
+
=== TEST 12: update (user property)
@@ -537,6 +537,7 @@ GET /mysql
{"name":"Jimmy\"","age":"32","\"code\"":0,"\"str\"":"Rows matched: 1 Changed: 0 Warnings: 0"}
+
=== TEST 30: select - custom errstr_key
--- http_config eval: $::http_config
--- config
@@ -557,5 +558,4 @@ GET /mysql
--- request
GET /mysql
--- response_body chop
-{"name":"Jimmy\"","age":"32", "data": [ ] }
-
+{"name":"Jimmy\"","age":"32","data":[{"a":"aaa","b":"bbb"}]}

0 comments on commit d660cbf

Please sign in to comment.