Commit 9dbeb988 authored by unknown's avatar unknown

MDEV-4993:Impossible to free a dynamic column

Fix of API of dynamic columns (it made uniform and real function used to free the string).
parent ce0d5539
...@@ -126,7 +126,7 @@ dynamic_column_get(DYNAMIC_COLUMN *org, uint column_nr, ...@@ -126,7 +126,7 @@ dynamic_column_get(DYNAMIC_COLUMN *org, uint column_nr,
/* new functions */ /* new functions */
enum enum_dyncol_func_result enum enum_dyncol_func_result
mariadb_dyncol_create_many(DYNAMIC_COLUMN *str, mariadb_dyncol_create_many_num(DYNAMIC_COLUMN *str,
uint column_count, uint column_count,
uint *column_numbers, uint *column_numbers,
DYNAMIC_COLUMN_VALUE *values, DYNAMIC_COLUMN_VALUE *values,
...@@ -140,7 +140,7 @@ mariadb_dyncol_create_many_named(DYNAMIC_COLUMN *str, ...@@ -140,7 +140,7 @@ mariadb_dyncol_create_many_named(DYNAMIC_COLUMN *str,
enum enum_dyncol_func_result enum enum_dyncol_func_result
mariadb_dyncol_update_many(DYNAMIC_COLUMN *str, mariadb_dyncol_update_many_num(DYNAMIC_COLUMN *str,
uint add_column_count, uint add_column_count,
uint *column_keys, uint *column_keys,
DYNAMIC_COLUMN_VALUE *values); DYNAMIC_COLUMN_VALUE *values);
...@@ -152,13 +152,13 @@ mariadb_dyncol_update_many_named(DYNAMIC_COLUMN *str, ...@@ -152,13 +152,13 @@ mariadb_dyncol_update_many_named(DYNAMIC_COLUMN *str,
enum enum_dyncol_func_result enum enum_dyncol_func_result
mariadb_dyncol_exists(DYNAMIC_COLUMN *org, uint column_nr); mariadb_dyncol_exists_num(DYNAMIC_COLUMN *org, uint column_nr);
enum enum_dyncol_func_result enum enum_dyncol_func_result
mariadb_dyncol_exists_named(DYNAMIC_COLUMN *str, MYSQL_LEX_STRING *name); mariadb_dyncol_exists_named(DYNAMIC_COLUMN *str, MYSQL_LEX_STRING *name);
/* List of not NULL columns */ /* List of not NULL columns */
enum enum_dyncol_func_result enum enum_dyncol_func_result
mariadb_dyncol_list(DYNAMIC_COLUMN *str, uint *count, uint **nums); mariadb_dyncol_list_num(DYNAMIC_COLUMN *str, uint *count, uint **nums);
enum enum_dyncol_func_result enum enum_dyncol_func_result
mariadb_dyncol_list_named(DYNAMIC_COLUMN *str, uint *count, mariadb_dyncol_list_named(DYNAMIC_COLUMN *str, uint *count,
MYSQL_LEX_STRING **names); MYSQL_LEX_STRING **names);
...@@ -167,7 +167,7 @@ mariadb_dyncol_list_named(DYNAMIC_COLUMN *str, uint *count, ...@@ -167,7 +167,7 @@ mariadb_dyncol_list_named(DYNAMIC_COLUMN *str, uint *count,
if the column do not exists it is NULL if the column do not exists it is NULL
*/ */
enum enum_dyncol_func_result enum enum_dyncol_func_result
mariadb_dyncol_get(DYNAMIC_COLUMN *org, uint column_nr, mariadb_dyncol_get_num(DYNAMIC_COLUMN *org, uint column_nr,
DYNAMIC_COLUMN_VALUE *store_it_here); DYNAMIC_COLUMN_VALUE *store_it_here);
enum enum_dyncol_func_result enum enum_dyncol_func_result
mariadb_dyncol_get_named(DYNAMIC_COLUMN *str, MYSQL_LEX_STRING *name, mariadb_dyncol_get_named(DYNAMIC_COLUMN *str, MYSQL_LEX_STRING *name,
...@@ -181,8 +181,8 @@ mariadb_dyncol_check(DYNAMIC_COLUMN *str); ...@@ -181,8 +181,8 @@ mariadb_dyncol_check(DYNAMIC_COLUMN *str);
enum enum_dyncol_func_result enum enum_dyncol_func_result
mariadb_dyncol_json(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json); mariadb_dyncol_json(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json);
#define dynamic_column_initialize(A) memset((A), 0, sizeof(*(A))) #define mariadb_dyncol_init(A) memset((A), 0, sizeof(*(A)))
#define dynamic_column_column_free(V) dynstr_free(V) void mariadb_dyncol_free(DYNAMIC_COLUMN *str);
/* conversion of values to 3 base types */ /* conversion of values to 3 base types */
enum enum_dyncol_func_result enum enum_dyncol_func_result
......
...@@ -223,15 +223,16 @@ dynamic_column_exists ...@@ -223,15 +223,16 @@ dynamic_column_exists
dynamic_column_list dynamic_column_list
dynamic_column_get dynamic_column_get
dynamic_column_prepare_decimal dynamic_column_prepare_decimal
mariadb_dyncol_create_many mariadb_dyncol_create_many_num
mariadb_dyncol_create_many_named mariadb_dyncol_create_many_named
mariadb_dyncol_update_many mariadb_dyncol_update_many_num
mariadb_dyncol_update_many_named mariadb_dyncol_update_many_named
mariadb_dyncol_exists mariadb_dyncol_exists_num
mariadb_dyncol_exists_named mariadb_dyncol_exists_named
mariadb_dyncol_list mariadb_dyncol_free
mariadb_dyncol_list_num
mariadb_dyncol_list_named mariadb_dyncol_list_named
mariadb_dyncol_get mariadb_dyncol_get_num
mariadb_dyncol_get_named mariadb_dyncol_get_named
mariadb_dyncol_has_names mariadb_dyncol_has_names
mariadb_dyncol_check mariadb_dyncol_check
......
...@@ -1632,7 +1632,7 @@ dynamic_new_column_store(DYNAMIC_COLUMN *str, ...@@ -1632,7 +1632,7 @@ dynamic_new_column_store(DYNAMIC_COLUMN *str,
} }
else else
{ {
dynamic_column_initialize(str); mariadb_dyncol_init(str);
} }
} }
else else
...@@ -1789,7 +1789,7 @@ dynamic_column_create_many_internal_fmt(DYNAMIC_COLUMN *str, ...@@ -1789,7 +1789,7 @@ dynamic_column_create_many_internal_fmt(DYNAMIC_COLUMN *str,
if (new_str) if (new_str)
{ {
/* to make dynstr_free() working in case of errors */ /* to make dynstr_free() working in case of errors */
bzero(str, sizeof(DYNAMIC_COLUMN)); mariadb_dyncol_init(str);
} }
if ((rc= calc_var_sizes(&header, column_count, column_keys, values)) < 0) if ((rc= calc_var_sizes(&header, column_count, column_keys, values)) < 0)
...@@ -1838,13 +1838,13 @@ dynamic_column_create_many(DYNAMIC_COLUMN *str, ...@@ -1838,13 +1838,13 @@ dynamic_column_create_many(DYNAMIC_COLUMN *str,
*/ */
enum enum_dyncol_func_result enum enum_dyncol_func_result
mariadb_dyncol_create_many(DYNAMIC_COLUMN *str, mariadb_dyncol_create_many_num(DYNAMIC_COLUMN *str,
uint column_count, uint column_count,
uint *column_numbers, uint *column_numbers,
DYNAMIC_COLUMN_VALUE *values, DYNAMIC_COLUMN_VALUE *values,
my_bool new_string) my_bool new_string)
{ {
DBUG_ENTER("mariadb_dyncol_create_many"); DBUG_ENTER("mariadb_dyncol_create_many_num");
DBUG_RETURN(dynamic_column_create_many_internal_fmt(str, column_count, DBUG_RETURN(dynamic_column_create_many_internal_fmt(str, column_count,
column_numbers, values, column_numbers, values,
new_string, FALSE)); new_string, FALSE));
...@@ -2199,7 +2199,7 @@ dynamic_column_get(DYNAMIC_COLUMN *str, uint column_nr, ...@@ -2199,7 +2199,7 @@ dynamic_column_get(DYNAMIC_COLUMN *str, uint column_nr,
} }
enum enum_dyncol_func_result enum enum_dyncol_func_result
mariadb_dyncol_get(DYNAMIC_COLUMN *str, uint column_nr, mariadb_dyncol_get_num(DYNAMIC_COLUMN *str, uint column_nr,
DYNAMIC_COLUMN_VALUE *store_it_here) DYNAMIC_COLUMN_VALUE *store_it_here)
{ {
return dynamic_column_get_internal(str, store_it_here, column_nr, NULL); return dynamic_column_get_internal(str, store_it_here, column_nr, NULL);
...@@ -2328,7 +2328,7 @@ dynamic_column_exists(DYNAMIC_COLUMN *str, uint column_nr) ...@@ -2328,7 +2328,7 @@ dynamic_column_exists(DYNAMIC_COLUMN *str, uint column_nr)
} }
enum enum_dyncol_func_result enum enum_dyncol_func_result
mariadb_dyncol_exists(DYNAMIC_COLUMN *str, uint column_nr) mariadb_dyncol_exists_num(DYNAMIC_COLUMN *str, uint column_nr)
{ {
return dynamic_column_exists_internal(str, column_nr, NULL); return dynamic_column_exists_internal(str, column_nr, NULL);
} }
...@@ -2438,7 +2438,7 @@ dynamic_column_list(DYNAMIC_COLUMN *str, DYNAMIC_ARRAY *array_of_uint) ...@@ -2438,7 +2438,7 @@ dynamic_column_list(DYNAMIC_COLUMN *str, DYNAMIC_ARRAY *array_of_uint)
@return ER_DYNCOL_* return code @return ER_DYNCOL_* return code
*/ */
enum enum_dyncol_func_result enum enum_dyncol_func_result
mariadb_dyncol_list(DYNAMIC_COLUMN *str, uint *count, uint **nums) mariadb_dyncol_list_num(DYNAMIC_COLUMN *str, uint *count, uint **nums)
{ {
DYN_HEADER header; DYN_HEADER header;
uchar *read; uchar *read;
...@@ -2841,11 +2841,11 @@ dynamic_column_update_copy(DYNAMIC_COLUMN *str, PLAN *plan, ...@@ -2841,11 +2841,11 @@ dynamic_column_update_copy(DYNAMIC_COLUMN *str, PLAN *plan,
} }
} }
} }
dynamic_column_column_free(str); mariadb_dyncol_free(str);
*str= tmp; *str= tmp;
return ER_DYNCOL_OK; return ER_DYNCOL_OK;
err: err:
dynamic_column_column_free(&tmp); mariadb_dyncol_free(&tmp);
return ER_DYNCOL_FORMAT; return ER_DYNCOL_FORMAT;
} }
...@@ -3257,7 +3257,7 @@ dynamic_column_update_many(DYNAMIC_COLUMN *str, ...@@ -3257,7 +3257,7 @@ dynamic_column_update_many(DYNAMIC_COLUMN *str,
} }
enum enum_dyncol_func_result enum enum_dyncol_func_result
mariadb_dyncol_update_many(DYNAMIC_COLUMN *str, mariadb_dyncol_update_many_num(DYNAMIC_COLUMN *str,
uint add_column_count, uint add_column_count,
uint *column_numbers, uint *column_numbers,
DYNAMIC_COLUMN_VALUE *values) DYNAMIC_COLUMN_VALUE *values)
...@@ -4336,3 +4336,12 @@ mariadb_dyncol_column_count(DYNAMIC_COLUMN *str, uint *column_count) ...@@ -4336,3 +4336,12 @@ mariadb_dyncol_column_count(DYNAMIC_COLUMN *str, uint *column_count)
*column_count= header.column_count; *column_count= header.column_count;
return rc; return rc;
} }
/**
Free dynamic column
@param str The packed string
*/
void mariadb_dyncol_free(DYNAMIC_COLUMN *str)
{
dynstr_free(str);
}
...@@ -6309,7 +6309,7 @@ longlong Item_func_dyncol_exists::val_int() ...@@ -6309,7 +6309,7 @@ longlong Item_func_dyncol_exists::val_int()
/* We do not change the string, so could do this trick */ /* We do not change the string, so could do this trick */
col.str= (char *)str->ptr(); col.str= (char *)str->ptr();
rc= ((name == NULL) ? rc= ((name == NULL) ?
mariadb_dyncol_exists(&col, (uint) num) : mariadb_dyncol_exists_num(&col, (uint) num) :
mariadb_dyncol_exists_named(&col, name)); mariadb_dyncol_exists_named(&col, name));
if (rc < 0) if (rc < 0)
{ {
......
...@@ -4220,11 +4220,11 @@ String *Item_func_dyncol_create::val_str(String *str) ...@@ -4220,11 +4220,11 @@ String *Item_func_dyncol_create::val_str(String *str)
if ((rc= ((names || force_names) ? if ((rc= ((names || force_names) ?
mariadb_dyncol_create_many_named(&col, column_count, keys_str, mariadb_dyncol_create_many_named(&col, column_count, keys_str,
vals, TRUE) : vals, TRUE) :
mariadb_dyncol_create_many(&col, column_count, keys_num, mariadb_dyncol_create_many_num(&col, column_count, keys_num,
vals, TRUE)))) vals, TRUE))))
{ {
dynamic_column_error_message(rc); dynamic_column_error_message(rc);
dynamic_column_column_free(&col); mariadb_dyncol_free(&col);
res= NULL; res= NULL;
null_value= TRUE; null_value= TRUE;
} }
...@@ -4363,11 +4363,11 @@ String *Item_func_dyncol_add::val_str(String *str) ...@@ -4363,11 +4363,11 @@ String *Item_func_dyncol_add::val_str(String *str)
if ((rc= ((names || force_names) ? if ((rc= ((names || force_names) ?
mariadb_dyncol_update_many_named(&col, column_count, mariadb_dyncol_update_many_named(&col, column_count,
keys_str, vals) : keys_str, vals) :
mariadb_dyncol_update_many(&col, column_count, mariadb_dyncol_update_many_num(&col, column_count,
keys_num, vals)))) keys_num, vals))))
{ {
dynamic_column_error_message(rc); dynamic_column_error_message(rc);
dynamic_column_column_free(&col); mariadb_dyncol_free(&col);
goto null; goto null;
} }
...@@ -4470,7 +4470,7 @@ bool Item_dyncol_get::get_dyn_value(DYNAMIC_COLUMN_VALUE *val, String *tmp) ...@@ -4470,7 +4470,7 @@ bool Item_dyncol_get::get_dyn_value(DYNAMIC_COLUMN_VALUE *val, String *tmp)
dyn_str.str= (char*) res->ptr(); dyn_str.str= (char*) res->ptr();
dyn_str.length= res->length(); dyn_str.length= res->length();
if ((rc= ((name == NULL) ? if ((rc= ((name == NULL) ?
mariadb_dyncol_get(&dyn_str, (uint) num, val) : mariadb_dyncol_get_num(&dyn_str, (uint) num, val) :
mariadb_dyncol_get_named(&dyn_str, name, val)))) mariadb_dyncol_get_named(&dyn_str, name, val))))
{ {
dynamic_column_error_message(rc); dynamic_column_error_message(rc);
......
...@@ -42,17 +42,17 @@ void test_value_single_null() ...@@ -42,17 +42,17 @@ void test_value_single_null()
val.type= DYN_COL_NULL; val.type= DYN_COL_NULL;
mariadb_dyncol_value_init(&res); mariadb_dyncol_value_init(&res);
/* create column */ /* create column */
if (mariadb_dyncol_create_many(&str, 1, ids, &val, 1)) if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err; goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */ /* read column */
if (mariadb_dyncol_get(&str, 1, &res)) if (mariadb_dyncol_get_num(&str, 1, &res))
goto err; goto err;
rc= (res.type == DYN_COL_NULL); rc= (res.type == DYN_COL_NULL);
err: err:
ok(rc, "%s", "NULL"); ok(rc, "%s", "NULL");
/* cleanup */ /* cleanup */
dynamic_column_column_free(&str); mariadb_dyncol_free(&str);
} }
void test_value_single_uint(ulonglong num, const char *name) void test_value_single_uint(ulonglong num, const char *name)
...@@ -66,18 +66,18 @@ void test_value_single_uint(ulonglong num, const char *name) ...@@ -66,18 +66,18 @@ void test_value_single_uint(ulonglong num, const char *name)
val.x.ulong_value= num; val.x.ulong_value= num;
mariadb_dyncol_value_init(&res); mariadb_dyncol_value_init(&res);
/* create column */ /* create column */
if (mariadb_dyncol_create_many(&str, 1, ids, &val, 1)) if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err; goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */ /* read column */
if (mariadb_dyncol_get(&str, 1, &res)) if (mariadb_dyncol_get_num(&str, 1, &res))
goto err; goto err;
rc= (res.type == DYN_COL_UINT) && (res.x.ulong_value == num); rc= (res.type == DYN_COL_UINT) && (res.x.ulong_value == num);
num= res.x.ulong_value; num= res.x.ulong_value;
err: err:
ok(rc, "%s - %llu", name, num); ok(rc, "%s - %llu", name, num);
/* cleanup */ /* cleanup */
dynamic_column_column_free(&str); mariadb_dyncol_free(&str);
} }
void test_value_single_sint(longlong num, const char *name) void test_value_single_sint(longlong num, const char *name)
...@@ -91,18 +91,18 @@ void test_value_single_sint(longlong num, const char *name) ...@@ -91,18 +91,18 @@ void test_value_single_sint(longlong num, const char *name)
val.x.long_value= num; val.x.long_value= num;
mariadb_dyncol_value_init(&res); mariadb_dyncol_value_init(&res);
/* create column */ /* create column */
if (mariadb_dyncol_create_many(&str, 1, ids, &val, 1)) if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err; goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */ /* read column */
if (mariadb_dyncol_get(&str, 1, &res)) if (mariadb_dyncol_get_num(&str, 1, &res))
goto err; goto err;
rc= (res.type == DYN_COL_INT) && (res.x.long_value == num); rc= (res.type == DYN_COL_INT) && (res.x.long_value == num);
num= res.x.ulong_value; num= res.x.ulong_value;
err: err:
ok(rc, "%s - %lld", name, num); ok(rc, "%s - %lld", name, num);
/* cleanup */ /* cleanup */
dynamic_column_column_free(&str); mariadb_dyncol_free(&str);
} }
...@@ -117,18 +117,18 @@ void test_value_single_double(double num, const char *name) ...@@ -117,18 +117,18 @@ void test_value_single_double(double num, const char *name)
val.x.double_value= num; val.x.double_value= num;
mariadb_dyncol_value_init(&res); mariadb_dyncol_value_init(&res);
/* create column */ /* create column */
if (mariadb_dyncol_create_many(&str, 1, ids, &val, 1)) if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err; goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */ /* read column */
if (mariadb_dyncol_get(&str, 1, &res)) if (mariadb_dyncol_get_num(&str, 1, &res))
goto err; goto err;
rc= (res.type == DYN_COL_DOUBLE) && (res.x.double_value == num); rc= (res.type == DYN_COL_DOUBLE) && (res.x.double_value == num);
num= res.x.ulong_value; num= res.x.ulong_value;
err: err:
ok(rc, "%s - %lf", name, num); ok(rc, "%s - %lf", name, num);
/* cleanup */ /* cleanup */
dynamic_column_column_free(&str); mariadb_dyncol_free(&str);
} }
void test_value_single_decimal(const char *num) void test_value_single_decimal(const char *num)
...@@ -148,11 +148,11 @@ void test_value_single_decimal(const char *num) ...@@ -148,11 +148,11 @@ void test_value_single_decimal(const char *num)
mariadb_dyncol_value_init(&res); mariadb_dyncol_value_init(&res);
/* create column */ /* create column */
if (mariadb_dyncol_create_many(&str, 1, ids, &val, 1)) if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err; goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */ /* read column */
if (mariadb_dyncol_get(&str, 1, &res)) if (mariadb_dyncol_get_num(&str, 1, &res))
goto err; goto err;
rc= ((res.type == DYN_COL_DECIMAL) && rc= ((res.type == DYN_COL_DECIMAL) &&
(decimal_cmp(&res.x.decimal.value, &val.x.decimal.value) == 0)); (decimal_cmp(&res.x.decimal.value, &val.x.decimal.value) == 0));
...@@ -160,7 +160,7 @@ void test_value_single_decimal(const char *num) ...@@ -160,7 +160,7 @@ void test_value_single_decimal(const char *num)
err: err:
ok(rc, "%s - %s", num, buff); ok(rc, "%s - %s", num, buff);
/* cleanup */ /* cleanup */
dynamic_column_column_free(&str); mariadb_dyncol_free(&str);
} }
static CHARSET_INFO *charset_list[]= static CHARSET_INFO *charset_list[]=
...@@ -223,11 +223,11 @@ void test_value_single_string(const char *string, size_t len, ...@@ -223,11 +223,11 @@ void test_value_single_string(const char *string, size_t len,
mariadb_dyncol_value_init(&res); mariadb_dyncol_value_init(&res);
/* create column */ /* create column */
if (mariadb_dyncol_create_many(&str, 1, ids, &val, 1)) if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err; goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */ /* read column */
if (mariadb_dyncol_get(&str, 1, &res)) if (mariadb_dyncol_get_num(&str, 1, &res))
goto err; goto err;
rc= ((res.type == DYN_COL_STRING) && rc= ((res.type == DYN_COL_STRING) &&
(res.x.string.value.length == len) && (res.x.string.value.length == len) &&
...@@ -239,7 +239,7 @@ void test_value_single_string(const char *string, size_t len, ...@@ -239,7 +239,7 @@ void test_value_single_string(const char *string, size_t len,
(uint)res.x.string.charset->number, res.x.string.charset->name); (uint)res.x.string.charset->number, res.x.string.charset->name);
/* cleanup */ /* cleanup */
val.x.string.value.str= NULL; // we did not allocated it val.x.string.value.str= NULL; // we did not allocated it
dynamic_column_column_free(&str); mariadb_dyncol_free(&str);
} }
void test_value_single_date(uint year, uint month, uint day, const char *name) void test_value_single_date(uint year, uint month, uint day, const char *name)
...@@ -256,11 +256,11 @@ void test_value_single_date(uint year, uint month, uint day, const char *name) ...@@ -256,11 +256,11 @@ void test_value_single_date(uint year, uint month, uint day, const char *name)
val.x.time_value.day= day; val.x.time_value.day= day;
mariadb_dyncol_value_init(&res); mariadb_dyncol_value_init(&res);
/* create column */ /* create column */
if (mariadb_dyncol_create_many(&str, 1, ids, &val, 1)) if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err; goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */ /* read column */
if (mariadb_dyncol_get(&str, 1, &res)) if (mariadb_dyncol_get_num(&str, 1, &res))
goto err; goto err;
rc= ((res.type == DYN_COL_DATE) && rc= ((res.type == DYN_COL_DATE) &&
(res.x.time_value.time_type == MYSQL_TIMESTAMP_DATE) && (res.x.time_value.time_type == MYSQL_TIMESTAMP_DATE) &&
...@@ -270,7 +270,7 @@ void test_value_single_date(uint year, uint month, uint day, const char *name) ...@@ -270,7 +270,7 @@ void test_value_single_date(uint year, uint month, uint day, const char *name)
err: err:
ok(rc, "%s - %04u-%02u-%02u", name, year, month, day); ok(rc, "%s - %04u-%02u-%02u", name, year, month, day);
/* cleanup */ /* cleanup */
dynamic_column_column_free(&str); mariadb_dyncol_free(&str);
} }
void test_value_single_time(uint neg, uint hour, uint minute, uint second, void test_value_single_time(uint neg, uint hour, uint minute, uint second,
...@@ -290,11 +290,11 @@ void test_value_single_time(uint neg, uint hour, uint minute, uint second, ...@@ -290,11 +290,11 @@ void test_value_single_time(uint neg, uint hour, uint minute, uint second,
val.x.time_value.second_part= mic; val.x.time_value.second_part= mic;
mariadb_dyncol_value_init(&res); mariadb_dyncol_value_init(&res);
/* create column */ /* create column */
if (mariadb_dyncol_create_many(&str, 1, ids, &val, 1)) if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err; goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */ /* read column */
if (mariadb_dyncol_get(&str, 1, &res)) if (mariadb_dyncol_get_num(&str, 1, &res))
goto err; goto err;
rc= ((res.type == DYN_COL_TIME) && rc= ((res.type == DYN_COL_TIME) &&
(res.x.time_value.time_type == MYSQL_TIMESTAMP_TIME) && (res.x.time_value.time_type == MYSQL_TIMESTAMP_TIME) &&
...@@ -307,7 +307,7 @@ void test_value_single_time(uint neg, uint hour, uint minute, uint second, ...@@ -307,7 +307,7 @@ void test_value_single_time(uint neg, uint hour, uint minute, uint second,
ok(rc, "%s - %c%02u:%02u:%02u.%06u", name, (neg ? '-' : '+'), ok(rc, "%s - %c%02u:%02u:%02u.%06u", name, (neg ? '-' : '+'),
hour, minute, second, mic); hour, minute, second, mic);
/* cleanup */ /* cleanup */
dynamic_column_column_free(&str); mariadb_dyncol_free(&str);
} }
...@@ -332,11 +332,11 @@ void test_value_single_datetime(uint neg, uint year, uint month, uint day, ...@@ -332,11 +332,11 @@ void test_value_single_datetime(uint neg, uint year, uint month, uint day,
val.x.time_value.second_part= mic; val.x.time_value.second_part= mic;
mariadb_dyncol_value_init(&res); mariadb_dyncol_value_init(&res);
/* create column */ /* create column */
if (mariadb_dyncol_create_many(&str, 1, ids, &val, 1)) if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err; goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */ /* read column */
if (mariadb_dyncol_get(&str, 1, &res)) if (mariadb_dyncol_get_num(&str, 1, &res))
goto err; goto err;
rc= ((res.type == DYN_COL_DATETIME) && rc= ((res.type == DYN_COL_DATETIME) &&
(res.x.time_value.time_type == MYSQL_TIMESTAMP_DATETIME) && (res.x.time_value.time_type == MYSQL_TIMESTAMP_DATETIME) &&
...@@ -352,7 +352,7 @@ void test_value_single_datetime(uint neg, uint year, uint month, uint day, ...@@ -352,7 +352,7 @@ void test_value_single_datetime(uint neg, uint year, uint month, uint day,
ok(rc, "%s - %c %04u-%02u-%02u %02u:%02u:%02u.%06u", name, (neg ? '-' : '+'), ok(rc, "%s - %c %04u-%02u-%02u %02u:%02u:%02u.%06u", name, (neg ? '-' : '+'),
year, month, day, hour, minute, second, mic); year, month, day, hour, minute, second, mic);
/* cleanup */ /* cleanup */
dynamic_column_column_free(&str); mariadb_dyncol_free(&str);
} }
...@@ -415,12 +415,12 @@ void test_value_multi(ulonglong num0, ...@@ -415,12 +415,12 @@ void test_value_multi(ulonglong num0,
for (i= 0; i < 9; i++) for (i= 0; i < 9; i++)
mariadb_dyncol_value_init(res + i); mariadb_dyncol_value_init(res + i);
/* create column */ /* create column */
if (mariadb_dyncol_create_many(&str, 9, column_numbers, val, 1)) if (mariadb_dyncol_create_many_num(&str, 9, column_numbers, val, 1))
goto err; goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */ /* read column */
for (i= 0; i < 9; i++) for (i= 0; i < 9; i++)
if (mariadb_dyncol_get(&str, column_numbers[i], res + i)) if (mariadb_dyncol_get_num(&str, column_numbers[i], res + i))
goto err; goto err;
rc= ((res[0].type == DYN_COL_UINT) && rc= ((res[0].type == DYN_COL_UINT) &&
(res[0].x.ulong_value == num0) && (res[0].x.ulong_value == num0) &&
...@@ -461,7 +461,7 @@ void test_value_multi(ulonglong num0, ...@@ -461,7 +461,7 @@ void test_value_multi(ulonglong num0,
ok(rc, "%s", name); ok(rc, "%s", name);
/* cleanup */ /* cleanup */
val[4].x.string.value.str= NULL; // we did not allocated it val[4].x.string.value.str= NULL; // we did not allocated it
dynamic_column_column_free(&str); mariadb_dyncol_free(&str);
} }
...@@ -476,13 +476,13 @@ void test_value_multi_same_num() ...@@ -476,13 +476,13 @@ void test_value_multi_same_num()
for (i= 0; i < 5; i++) for (i= 0; i < 5; i++)
val[i].type= DYN_COL_NULL; val[i].type= DYN_COL_NULL;
/* create column */ /* create column */
if (!mariadb_dyncol_create_many(&str, 5, column_numbers, val, 1)) if (!mariadb_dyncol_create_many_num(&str, 5, column_numbers, val, 1))
goto err; goto err;
rc= TRUE; rc= TRUE;
err: err:
ok(rc, "%s", "same column numbers check"); ok(rc, "%s", "same column numbers check");
/* cleanup */ /* cleanup */
dynamic_column_column_free(&str); mariadb_dyncol_free(&str);
} }
...@@ -496,38 +496,38 @@ void test_update_multi(uint *column_numbers, uint *column_values, ...@@ -496,38 +496,38 @@ void test_update_multi(uint *column_numbers, uint *column_values,
val.type= DYN_COL_UINT; val.type= DYN_COL_UINT;
val.x.ulong_value= column_values[0]; val.x.ulong_value= column_values[0];
if (mariadb_dyncol_create_many(&str, 1, column_numbers, &val, 1)) if (mariadb_dyncol_create_many_num(&str, 1, column_numbers, &val, 1))
goto err; goto err;
for (i= 1; i < all; i++) for (i= 1; i < all; i++)
{ {
val.type= (null_values[i] ? DYN_COL_NULL : DYN_COL_UINT); val.type= (null_values[i] ? DYN_COL_NULL : DYN_COL_UINT);
val.x.ulong_value= column_values[i]; val.x.ulong_value= column_values[i];
if (mariadb_dyncol_update_many(&str, 1, column_numbers +i, &val)) if (mariadb_dyncol_update_many_num(&str, 1, column_numbers +i, &val))
goto err; goto err;
/* check value(s) */ /* check value(s) */
for (j= i; j >= (i < only_add ? 0 : i); j--) for (j= i; j >= (i < only_add ? 0 : i); j--)
{ {
if (mariadb_dyncol_get(&str, column_numbers[j], &val)) if (mariadb_dyncol_get_num(&str, column_numbers[j], &val))
goto err; goto err;
if (null_values[j]) if (null_values[j])
{ {
if (val.type != DYN_COL_NULL || if (val.type != DYN_COL_NULL ||
mariadb_dyncol_exists(&str, column_numbers[j]) == ER_DYNCOL_YES) mariadb_dyncol_exists_num(&str, column_numbers[j]) == ER_DYNCOL_YES)
goto err; goto err;
} }
else else
{ {
if (val.type != DYN_COL_UINT || if (val.type != DYN_COL_UINT ||
val.x.ulong_value != column_values[j] || val.x.ulong_value != column_values[j] ||
mariadb_dyncol_exists(&str, column_numbers[j]) == ER_DYNCOL_NO) mariadb_dyncol_exists_num(&str, column_numbers[j]) == ER_DYNCOL_NO)
goto err; goto err;
} }
} }
if (i < only_add) if (i < only_add)
{ {
uint elements, *num; uint elements, *num;
if (mariadb_dyncol_list(&str, &elements, &num)) if (mariadb_dyncol_list_num(&str, &elements, &num))
{ {
my_free(num); my_free(num);
goto err; goto err;
...@@ -566,7 +566,7 @@ void test_update_multi(uint *column_numbers, uint *column_values, ...@@ -566,7 +566,7 @@ void test_update_multi(uint *column_numbers, uint *column_values,
err: err:
ok(rc, "%s", "add/delete/update"); ok(rc, "%s", "add/delete/update");
/* cleanup */ /* cleanup */
dynamic_column_column_free(&str); mariadb_dyncol_free(&str);
} }
void test_empty_string() void test_empty_string()
...@@ -581,29 +581,29 @@ void test_empty_string() ...@@ -581,29 +581,29 @@ void test_empty_string()
/* empty string */ /* empty string */
bzero(&str, sizeof(str)); bzero(&str, sizeof(str));
rc= mariadb_dyncol_get(&str, 1, &res); rc= mariadb_dyncol_get_num(&str, 1, &res);
ok( (rc == ER_DYNCOL_OK) && (res.type == DYN_COL_NULL), "%s", "empty get"); ok( (rc == ER_DYNCOL_OK) && (res.type == DYN_COL_NULL), "%s", "empty get");
vals[0].type= DYN_COL_NULL; vals[0].type= DYN_COL_NULL;
rc= mariadb_dyncol_update_many(&str, 1, ids, vals); rc= mariadb_dyncol_update_many_num(&str, 1, ids, vals);
ok( (rc == ER_DYNCOL_OK) && (str.str == 0), "%s", "empty delete"); ok( (rc == ER_DYNCOL_OK) && (str.str == 0), "%s", "empty delete");
rc= mariadb_dyncol_exists(&str, 1); rc= mariadb_dyncol_exists_num(&str, 1);
ok( (rc == ER_DYNCOL_NO), "%s", "empty exists"); ok( (rc == ER_DYNCOL_NO), "%s", "empty exists");
rc= mariadb_dyncol_list(&str, &number_of_uint, &array_of_uint); rc= mariadb_dyncol_list_num(&str, &number_of_uint, &array_of_uint);
ok( (rc == ER_DYNCOL_OK) && (number_of_uint == 0) && (str.str == 0), ok( (rc == ER_DYNCOL_OK) && (number_of_uint == 0) && (str.str == 0),
"%s", "empty list"); "%s", "empty list");
val.type= DYN_COL_UINT; val.type= DYN_COL_UINT;
val.x.ulong_value= 1212; val.x.ulong_value= 1212;
rc= mariadb_dyncol_update_many(&str, 1, ids, &val); rc= mariadb_dyncol_update_many_num(&str, 1, ids, &val);
if (rc == ER_DYNCOL_OK) if (rc == ER_DYNCOL_OK)
rc= mariadb_dyncol_get(&str, 1, &res); rc= mariadb_dyncol_get_num(&str, 1, &res);
ok( (rc == ER_DYNCOL_OK) && (str.str != 0) && ok( (rc == ER_DYNCOL_OK) && (str.str != 0) &&
(res.type == DYN_COL_UINT) && (res.x.ulong_value == val.x.ulong_value), (res.type == DYN_COL_UINT) && (res.x.ulong_value == val.x.ulong_value),
"%s", "empty update"); "%s", "empty update");
dynamic_column_column_free(&str); mariadb_dyncol_free(&str);
} }
static void test_mdev_4994() static void test_mdev_4994()
...@@ -615,10 +615,10 @@ static void test_mdev_4994() ...@@ -615,10 +615,10 @@ static void test_mdev_4994()
val.type= DYN_COL_NULL; val.type= DYN_COL_NULL;
dynamic_column_initialize(&dyncol); mariadb_dyncol_init(&dyncol);
rc= mariadb_dyncol_create_many_named(&dyncol, 1, &key, &val, 0); /* crash */ rc= mariadb_dyncol_create_many_named(&dyncol, 1, &key, &val, 0); /* crash */
ok( (rc == ER_DYNCOL_OK), "%s", "test_mdev_4994"); ok( (rc == ER_DYNCOL_OK), "%s", "test_mdev_4994");
dynamic_column_column_free(&dyncol); mariadb_dyncol_free(&dyncol);
} }
static void test_mdev_4995() static void test_mdev_4995()
...@@ -627,7 +627,7 @@ static void test_mdev_4995() ...@@ -627,7 +627,7 @@ static void test_mdev_4995()
uint column_count= 5; uint column_count= 5;
int rc; int rc;
dynamic_column_initialize(&dyncol); mariadb_dyncol_init(&dyncol);
rc= mariadb_dyncol_column_count(&dyncol,&column_count); rc= mariadb_dyncol_column_count(&dyncol,&column_count);
ok( (rc == ER_DYNCOL_OK), "%s", "test_mdev_4995"); ok( (rc == ER_DYNCOL_OK), "%s", "test_mdev_4995");
...@@ -674,11 +674,11 @@ void test_update_many(uint *column_numbers, uint *column_values, ...@@ -674,11 +674,11 @@ void test_update_many(uint *column_numbers, uint *column_values,
res[i].type= DYN_COL_UINT; res[i].type= DYN_COL_UINT;
res[i].x.ulong_value= result_values[i]; res[i].x.ulong_value= result_values[i];
} }
if (mariadb_dyncol_create_many(&str1, column_count, column_numbers, val, 1)) if (mariadb_dyncol_create_many_num(&str1, column_count, column_numbers, val, 1))
goto err; goto err;
if (mariadb_dyncol_update_many(&str1, update_count, update_numbers, upd)) if (mariadb_dyncol_update_many_num(&str1, update_count, update_numbers, upd))
goto err; goto err;
if (mariadb_dyncol_create_many(&str2, result_count, result_numbers, res, 1)) if (mariadb_dyncol_create_many_num(&str2, result_count, result_numbers, res, 1))
goto err; goto err;
if (str1.length == str2.length && if (str1.length == str2.length &&
memcmp(str1.str, str2.str, str1.length) ==0) memcmp(str1.str, str2.str, str1.length) ==0)
...@@ -687,8 +687,8 @@ void test_update_many(uint *column_numbers, uint *column_values, ...@@ -687,8 +687,8 @@ void test_update_many(uint *column_numbers, uint *column_values,
err: err:
ok(rc, "%s", "update_many"); ok(rc, "%s", "update_many");
/* cleanup */ /* cleanup */
dynamic_column_column_free(&str1); mariadb_dyncol_free(&str1);
dynamic_column_column_free(&str2); mariadb_dyncol_free(&str2);
} }
int main(int argc __attribute__((unused)), char **argv) int main(int argc __attribute__((unused)), char **argv)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment