Skip to content

Commit

Permalink
Added support for STMT_INDICATE_IGNORE indicator - please note that t…
Browse files Browse the repository at this point in the history
…he counter part for indicator type ignore is not pushed in server repo yet.
  • Loading branch information
9EOR9 committed Nov 26, 2016
1 parent aabaac0 commit 8695a17
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 3 deletions.
5 changes: 2 additions & 3 deletions libmariadb/mariadb_stmt.c
Expand Up @@ -740,8 +740,7 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req
else
indicator= ma_get_indicator(stmt, i, j);
/* check if we need to send data */
if (indicator == STMT_INDICATOR_NULL ||
indicator == STMT_INDICATOR_DEFAULT)
if (indicator > 0)
has_data= FALSE;
size= 1;
}
Expand Down Expand Up @@ -801,7 +800,7 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req
p= start + offset;
}

if (indicator != STMT_INDICATOR_DEFAULT &&
if ((indicator != STMT_INDICATOR_DEFAULT && indicator != STMT_INDICATOR_IGNORE) &&
((stmt->params[i].is_null && *stmt->params[i].is_null) ||
stmt->params[i].buffer_type == MYSQL_TYPE_NULL ||
!stmt->params[i].buffer))
Expand Down
115 changes: 115 additions & 0 deletions unittest/libmariadb/bulk1.c
Expand Up @@ -335,11 +335,126 @@ static int bulk_null(MYSQL *mysql)

mysql_stmt_close(stmt);
return OK;
}

static int bulk5(MYSQL *mysql)
{
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
MYSQL_BIND bind[3];
MYSQL_RES *res;
unsigned long rows;
unsigned int array_size= 5;
int rc;
int intval[]= {12,13,14,15,16};
int id[]= {1,2,3,4,5};

rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk5");
check_mysql_rc(rc, mysql);

rc= mysql_query(mysql, "CREATE TABLE bulk5 (a int, b int)");
check_mysql_rc(rc, mysql);

rc= mysql_query(mysql, "INSERT INTO bulk5 VALUES (1,1), (2,2), (3,3), (4,4), (5,5)");
check_mysql_rc(rc, mysql);


memset(bind, 0, sizeof(MYSQL_BIND) * 3);

rc= mysql_stmt_prepare(stmt, "UPDATE bulk5 SET a=? WHERE a=?", -1);
check_stmt_rc(rc, stmt);

bind[0].buffer_type= MYSQL_TYPE_LONG;
bind[0].buffer= &intval;
bind[1].buffer_type= MYSQL_TYPE_LONG;
bind[1].buffer= &id;

rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, &array_size);
check_stmt_rc(rc, stmt);

rc= mysql_stmt_bind_param(stmt, bind);
check_stmt_rc(rc, stmt);

rc= mysql_stmt_execute(stmt);
check_stmt_rc(rc, stmt);

mysql_stmt_close(stmt);

rc= mysql_query(mysql, "SELECT * FROM bulk5 WHERE a=b+11");
check_mysql_rc(rc, mysql);

res= mysql_store_result(mysql);
rows= mysql_num_rows(res);
mysql_free_result(res);

FAIL_IF(rows != 5, "expected 5 rows");

return OK;
}

static int bulk6(MYSQL *mysql)
{
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
MYSQL_BIND bind[3];
MYSQL_RES *res;
unsigned long rows;
unsigned int array_size= 5;
int rc;
int intval[]= {12,13,14,15,16};
int id[]= {1,2,3,4,5};
char indicator[5];

memset(indicator, STMT_INDICATOR_IGNORE, 5);

rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk5");
check_mysql_rc(rc, mysql);

rc= mysql_query(mysql, "CREATE TABLE bulk5 (a int, b int default 4)");
check_mysql_rc(rc, mysql);

rc= mysql_query(mysql, "INSERT INTO bulk5 VALUES (1,1), (2,2), (3,3), (4,4), (5,5)");
check_mysql_rc(rc, mysql);


memset(bind, 0, sizeof(MYSQL_BIND) * 3);

rc= mysql_stmt_prepare(stmt, "UPDATE bulk5 SET a=?, b=? WHERE a=?", -1);
check_stmt_rc(rc, stmt);

bind[0].buffer_type= MYSQL_TYPE_LONG;
bind[0].buffer= &intval;
bind[1].buffer_type= MYSQL_TYPE_LONG;
bind[1].buffer= &intval;
bind[1].u.indicator= indicator;
bind[2].buffer_type= MYSQL_TYPE_LONG;
bind[2].buffer= &id;

rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, &array_size);
check_stmt_rc(rc, stmt);

rc= mysql_stmt_bind_param(stmt, bind);
check_stmt_rc(rc, stmt);

rc= mysql_stmt_execute(stmt);
check_stmt_rc(rc, stmt);

mysql_stmt_close(stmt);

rc= mysql_query(mysql, "SELECT * FROM bulk5 WHERE a=b+11");
check_mysql_rc(rc, mysql);

res= mysql_store_result(mysql);
rows= mysql_num_rows(res);
mysql_free_result(res);

FAIL_IF(rows != 5, "expected 5 rows");

return OK;
}

struct my_tests_st my_tests[] = {
{"check_bulk", check_bulk, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"bulk5", bulk5, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"bulk6", bulk6, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"bulk1", bulk1, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"bulk2", bulk2, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"bulk3", bulk3, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
Expand Down

0 comments on commit 8695a17

Please sign in to comment.