Browse code

- check_result_columns renamed to check_result - bind_result ignores empty result sets without indicating errors

Jan Janak authored on 16/01/2008 15:27:06
Showing 1 changed files
... ...
@@ -857,7 +857,7 @@ static int bind_mysql_params(MYSQL_STMT* st, db_fld_t* params1, db_fld_t* params
857 857
  * in every context, otherwise it would initialize the result set
858 858
  * from the first connection in the context.
859 859
  */
860
-static int check_result_columns(db_cmd_t* cmd, struct my_cmd* payload)
860
+static int check_result(db_cmd_t* cmd, struct my_cmd* payload)
861 861
 {
862 862
 	int i, n;
863 863
 	MYSQL_FIELD *fld;
... ...
@@ -950,7 +950,8 @@ error:
950 950
 
951 951
 
952 952
 /* FIXME: Add support for DB_NONE, in this case the function should determine
953
- * the type of the column in the database and set the field type appropriately
953
+ * the type of the column in the database and set the field type appropriately.
954
+ * This function must be called after check_result.
954 955
  */
955 956
 static int bind_result(MYSQL_STMT* st, db_fld_t* fld)
956 957
 {
... ...
@@ -960,6 +961,9 @@ static int bind_result(MYSQL_STMT* st, db_fld_t* fld)
960 961
 
961 962
 	/* Calculate the number of fields in the result */
962 963
 	for(n = 0; !DB_FLD_EMPTY(fld) && !DB_FLD_LAST(fld[n]); n++);
964
+	/* Return immediately if there are no fields in the result set */
965
+	if (n == 0) return 0;
966
+
963 967
 	result = (MYSQL_BIND*)pkg_malloc(sizeof(MYSQL_BIND) * n);
964 968
 	if (result == NULL) {
965 969
 		ERR("mysql: No memory left\n");
... ...
@@ -1101,7 +1105,7 @@ static int upload_cmd(db_cmd_t* cmd)
1101 1105
 	if (err) goto error;
1102 1106
 
1103 1107
 	if (cmd->type == DB_GET || cmd->type == DB_SQL) {
1104
-		err = check_result_columns(cmd, res);
1108
+		err = check_result(cmd, res);
1105 1109
 		if (err) goto error;
1106 1110
 		err = bind_result(res->st, cmd->result);
1107 1111
 		if (err) goto error;