1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-07 02:42:49 +03:00

C preprocessor defines fix

This commit is contained in:
Oleksandr Byelkin
2020-06-04 16:49:21 +02:00
parent ce011210d1
commit 895dcb61e3
24 changed files with 179 additions and 150 deletions

View File

@@ -109,8 +109,8 @@ struct st_mariadb_extension {
};
#define OPT_EXT_VAL(a,key) \
((a)->options.extension && (a)->options.extension->key) ?\
(a)->options.extension->key : 0
(((a)->options.extension && (a)->options.extension->key) ?\
(a)->options.extension->key : 0)
#endif

View File

@@ -250,7 +250,7 @@ double my_ulonglong2double(unsigned long long A);
#if defined(_lint) || defined(FORCE_INIT_OF_VARS)
#define LINT_INIT(var) var=0 /* No uninitialize-warning */
#define LINT_INIT(var) do{var=0;}while(0) /* No uninitialize-warning */
#define LINT_INIT_STRUCT(var) memset(&var, 0, sizeof(var)) /* No uninitialize-warning */
#else
#define LINT_INIT(var)
@@ -272,10 +272,10 @@ typedef unsigned short ushort;
#endif
#define sgn(a) (((a) < 0) ? -1 : ((a) > 0) ? 1 : 0)
#define swap(t,a,b) { register t dummy; dummy = a; a = b; b = dummy; }
#define swap(t,a,b) do{register t dummy; dummy = a; a = b; b = dummy;}while(0)
#define test(a) ((a) ? 1 : 0)
#define set_if_bigger(a,b) { if ((a) < (b)) (a)=(b); }
#define set_if_smaller(a,b) { if ((a) > (b)) (a)=(b); }
#define set_if_bigger(a,b) do{ if ((a) < (b)) (a)=(b); }while(0)
#define set_if_smaller(a,b) do{ if ((a) > (b)) (a)=(b); }while(0)
#define test_all_bits(a,b) (((a) & (b)) == (b))
#define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1))
#define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0])))
@@ -440,11 +440,11 @@ typedef SOCKET_SIZE_TYPE size_socket;
*/
#define MALLOC_OVERHEAD 8
/* get memory in huncs */
#define ONCE_ALLOC_INIT (uint) (4096-MALLOC_OVERHEAD)
#define ONCE_ALLOC_INIT ((uint) (4096-MALLOC_OVERHEAD))
/* Typical record cash */
#define RECORD_CACHE_SIZE (uint) (64*1024-MALLOC_OVERHEAD)
#define RECORD_CACHE_SIZE ((uint) (64*1024-MALLOC_OVERHEAD))
/* Typical key cash */
#define KEY_CACHE_SIZE (uint) (8*1024*1024-MALLOC_OVERHEAD)
#define KEY_CACHE_SIZE ((uint) (8*1024*1024-MALLOC_OVERHEAD))
/* Some things that this system doesn't have */
@@ -815,7 +815,7 @@ typedef char bool; /* Ordinary boolean values 0 1 */
*((T)+3)=(uchar) (((A) >> 24)); \
*((T)+4)=(uchar) (((A) >> 32)); \
*((T)+5)=(uchar) (((A) >> 40)); } while(0)
#define int8store(T,A) *((ulonglong *) (T))= (ulonglong) (A)
#define int8store(T,A) do {*((ulonglong *) (T))= (ulonglong) (A);} while(0)
typedef union {
double v;
@@ -1046,11 +1046,11 @@ do { doubleget_union _tmp; \
#endif /* WORDS_BIGENDIAN */
#ifndef THREAD
#define thread_safe_increment(V,L) (V)++
#define thread_safe_add(V,C,L) (V)+=(C)
#define thread_safe_sub(V,C,L) (V)-=(C)
#define statistic_increment(V,L) (V)++
#define statistic_add(V,C,L) (V)+=(C)
#define thread_safe_increment(V,L) ((V)++)
#define thread_safe_add(V,C,L) ((V)+=(C))
#define thread_safe_sub(V,C,L) ((V)-=(C))
#define statistic_increment(V,L) ((V)++)
#define statistic_add(V,C,L) ((V)+=(C))
#endif
#ifdef _WIN32
@@ -1069,9 +1069,9 @@ do { doubleget_union _tmp; \
#ifdef HAVE_DLOPEN
#ifdef _WIN32
#define dlsym(lib, name) GetProcAddress((HMODULE)lib, name)
#define dlsym(lib, name) GetProcAddress((HMODULE)(lib), name)
#define dlopen(libname, unused) LoadLibraryEx(libname, NULL, 0)
#define dlclose(lib) FreeLibrary((HMODULE)lib)
#define dlclose(lib) FreeLibrary((HMODULE)(lib))
#elif defined(HAVE_DLFCN_H)
#include <dlfcn.h>
#endif

View File

@@ -39,7 +39,7 @@ extern int list_walk(LIST *list,list_walk_action action,char * argument);
#define list_rest(a) ((a)->next)
#define list_push(a,b) (a)=list_cons((b),(a))
#define list_pop(A) {LIST *old=(A); (A)=list_delete(old,old) ; ma_free((char *) old,MYF(MY_FAE)); }
#define list_pop(A) do {LIST *old=(A); (A)=list_delete(old,old) ; ma_free((char *) old,MYF(MY_FAE)); } while(0)
#ifdef __cplusplus
}

View File

@@ -35,9 +35,21 @@ typedef struct my_aio_result {
#include <stdarg.h>
#define MYSYS_PROGRAM_USES_CURSES() { ma_error_handler_hook = ma_message_curses; mysys_uses_curses=1; }
#define MYSYS_PROGRAM_DONT_USE_CURSES() { ma_error_handler_hook = ma_message_no_curses; mysys_uses_curses=0;}
#define MY_INIT(name); { ma_progname= name; ma_init(); }
#define MYSYS_PROGRAM_USES_CURSES() \
do {\
ma_error_handler_hook = ma_message_curses;\
mysys_uses_curses=1;\
} while(0)
#define MYSYS_PROGRAM_DONT_USE_CURSES() \
do {\
ma_error_handler_hook = ma_message_no_curses; \
mysys_uses_curses=0; \
} while(0)
#define MY_INIT(name) \
do {\
ma_progname= name;\
ma_init();\
} while(0)
#define MAXMAPS (4) /* Number of error message maps */
#define ERRMOD (1000) /* Max number of errors in a map */
@@ -285,15 +297,15 @@ typedef int (*qsort2_cmp)(const void *, const void *, const void *);
/* defines for mf_iocache */
/* Test if buffer is inited */
#define my_b_clear(info) (info)->buffer=0
#define my_b_inited(info) (info)->buffer
#define my_b_clear(info) do{(info)->buffer= 0;} while (0)
#define my_b_inited(info) ((info)->buffer)
#define my_b_EOF INT_MIN
#define my_b_read(info,Buffer,Count) \
((info)->rc_pos + (Count) <= (info)->rc_end ?\
(memcpy(Buffer,(info)->rc_pos,(size_t) (Count)), \
(memcpy((Buffer),(info)->rc_pos,(size_t) (Count)), \
((info)->rc_pos+=(Count)),0) :\
(*(info)->read_function)((info),Buffer,Count))
(*(info)->read_function)((info),(Buffer),(Count)))
#define my_b_get(info) \
((info)->rc_pos != (info)->rc_end ?\
@@ -302,18 +314,18 @@ typedef int (*qsort2_cmp)(const void *, const void *, const void *);
#define my_b_write(info,Buffer,Count) \
((info)->rc_pos + (Count) <= (info)->rc_end ?\
(memcpy((info)->rc_pos,Buffer,(size_t) (Count)), \
(memcpy((info)->rc_pos,(Buffer),(size_t) (Count)), \
((info)->rc_pos+=(Count)),0) :\
_my_b_write(info,Buffer,Count))
_my_b_write((info),(Buffer),(Count)))
/* my_b_write_byte doesn't have any err-check */
#define my_b_write_byte(info,chr) \
(((info)->rc_pos < (info)->rc_end) ?\
((*(info)->rc_pos++)=(chr)) :\
(_my_b_write(info,0,0) , ((*(info)->rc_pos++)=(chr))))
(_my_b_write((info),0,0) , ((*(info)->rc_pos++)=(chr))))
#define my_b_fill_cache(info) \
(((info)->rc_end=(info)->rc_pos),(*(info)->read_function)(info,0,0))
(((info)->rc_end=(info)->rc_pos),(*(info)->read_function)((info),0,0))
#define my_b_tell(info) ((info)->pos_in_file + \
((info)->rc_pos - (info)->rc_request_pos))
@@ -401,7 +413,7 @@ extern void casedn_str(my_string str);
extern void case_sort(my_string str,uint length);
extern uint ma_dirname_part(my_string to,const char *name);
extern uint ma_dirname_length(const char *name);
#define base_name(A) (A+dirname_length(A))
#define base_name(A) ((A)+dirname_length(A))
extern int test_if_hard_path(const char *dir_name);
extern char *ma_convert_dirname(my_string name);
extern void to_unix_path(my_string name);

View File

@@ -34,7 +34,7 @@
#define HOSTNAME_LENGTH 60
#define SYSTEM_MB_MAX_CHAR_LENGTH 4
#define USERNAME_CHAR_LENGTH 128
#define USERNAME_LENGTH USERNAME_CHAR_LENGTH * SYSTEM_MB_MAX_CHAR_LENGTH
#define USERNAME_LENGTH (USERNAME_CHAR_LENGTH * SYSTEM_MB_MAX_CHAR_LENGTH)
#define SERVER_VERSION_LENGTH 60
#define SQLSTATE_LENGTH 5
#define SCRAMBLE_LENGTH 20
@@ -174,7 +174,7 @@ enum enum_server_command
#define MARIADB_CLIENT_EXTENDED_METADATA (1ULL << 35)
#define IS_MARIADB_EXTENDED_SERVER(mysql)\
!(mysql->server_capabilities & CLIENT_MYSQL)
(!(mysql->server_capabilities & CLIENT_MYSQL))
#define MARIADB_CLIENT_SUPPORTED_FLAGS (MARIADB_CLIENT_PROGRESS |\
MARIADB_CLIENT_COM_MULTI |\
@@ -239,7 +239,7 @@ enum enum_server_command
#define MYSQL_ERRMSG_SIZE 512
#define NET_READ_TIMEOUT 30 /* Timeout on read */
#define NET_WRITE_TIMEOUT 60 /* Timeout on write */
#define NET_WAIT_TIMEOUT 8*60*60 /* Wait for new query */
#define NET_WAIT_TIMEOUT (8*60*60) /* Wait for new query */
/* for server integration (mysqlbinlog) */
#define LIST_PROCESS_HOST_LEN 64
@@ -316,7 +316,7 @@ enum enum_session_state_type
#define SESSION_TRACK_BEGIN 0
#define SESSION_TRACK_END SESSION_TRACK_TRANSACTION_TYPE
#define SESSION_TRACK_TYPES SESSION_TRACK_END + 1
#define SESSION_TRACK_TYPES (SESSION_TRACK_END + 1)
enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY,
MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,

View File

@@ -242,7 +242,10 @@ int mariadb_dyncol_column_cmp_named(const MYSQL_LEX_STRING *s1,
enum enum_dyncol_func_result
mariadb_dyncol_column_count(DYNAMIC_COLUMN *str, uint *column_count);
#define mariadb_dyncol_value_init(V) (V)->type= DYN_COL_NULL
#define mariadb_dyncol_value_init(V) \
do {\
(V)->type= DYN_COL_NULL;\
} while(0)
/*
Prepare value for using as decimal

View File

@@ -35,20 +35,20 @@
(MARIADB_CLIENT_STMT_BULK_OPERATIONS >> 32))))
#define SET_CLIENT_STMT_ERROR(a, b, c, d) \
{ \
do { \
(a)->last_errno= (b);\
strncpy((a)->sqlstate, (c), SQLSTATE_LENGTH);\
(a)->sqlstate[SQLSTATE_LENGTH]= 0;\
strncpy((a)->last_error, (d) ? (d) : ER((b)), MYSQL_ERRMSG_SIZE);\
(a)->last_error[MYSQL_ERRMSG_SIZE - 1]= 0;\
}
} while (0)
#define CLEAR_CLIENT_STMT_ERROR(a) \
{ \
do { \
(a)->last_errno= 0;\
strcpy((a)->sqlstate, "00000");\
(a)->last_error[0]= 0;\
}
} while (0)
#define MYSQL_PS_SKIP_RESULT_W_LEN -1
#define MYSQL_PS_SKIP_RESULT_STR -2

View File

@@ -130,13 +130,13 @@ extern unsigned int mariadb_deinitialize_ssl;
typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */
#define SET_CLIENT_ERROR(a, b, c, d) \
{ \
do { \
(a)->net.last_errno= (b);\
strncpy((a)->net.sqlstate, (c), SQLSTATE_LENGTH);\
(a)->net.sqlstate[SQLSTATE_LENGTH]= 0;\
strncpy((a)->net.last_error, (d) ? (d) : ER((b)), MYSQL_ERRMSG_SIZE - 1);\
(a)->net.last_error[MYSQL_ERRMSG_SIZE - 1]= 0;\
}
} while(0)
/* For mysql_async.c */
#define set_mariadb_error(A,B,C) SET_CLIENT_ERROR((A),(B),(C),0)
@@ -144,12 +144,12 @@ extern const char *SQLSTATE_UNKNOWN;
#define unknown_sqlstate SQLSTATE_UNKNOWN
#define CLEAR_CLIENT_ERROR(a) \
{ \
do { \
(a)->net.last_errno= 0;\
strcpy((a)->net.sqlstate, "00000");\
(a)->net.last_error[0]= '\0';\
(a)->net.extension->extended_errno= 0;\
}
} while (0)
#define MYSQL_COUNT_ERROR (~(unsigned long long) 0)

View File

@@ -514,14 +514,14 @@ typedef union { double d; ULong L[2]; } U;
#if defined(HAVE_BIGENDIAN) || defined(WORDS_BIGENDIAN) || \
(defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN))
#define word0(x) (x)->L[0]
#define word1(x) (x)->L[1]
#define word0(x) ((x)->L[0])
#define word1(x) ((x)->L[1])
#else
#define word0(x) (x)->L[1]
#define word1(x) (x)->L[0]
#define word0(x) ((x)->L[1])
#define word1(x) ((x)->L[0])
#endif
#define dval(x) (x)->d
#define dval(x) ((x)->d)
/* #define P DBL_MANT_DIG */
/* Ten_pmax= floor(P*log(2)/log(5)) */
@@ -568,8 +568,8 @@ typedef union { double d; ULong L[2]; } U;
#define Rounding Flt_Rounds
#endif
#define rounded_product(a,b) a*= b
#define rounded_quotient(a,b) a/= b
#define rounded_product(a,b) ((a)*= (b))
#define rounded_quotient(a,b) ((a)/= (b))
#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))
#define Big1 0xffffffff
@@ -579,8 +579,8 @@ typedef union { double d; ULong L[2]; } U;
#define Kmax 15
#define Bcopy(x,y) memcpy((char *)&x->sign, (char *)&y->sign, \
2*sizeof(int) + y->wds*sizeof(ULong))
#define Bcopy(x,y) memcpy((char *)&(x)->sign, (char *)&(y)->sign, \
2*sizeof(int) + (y)->wds*sizeof(ULong))
/* Arbitrary-length integer */

View File

@@ -73,7 +73,7 @@
#define LONGLONG_MAX ((long long) 0x7FFFFFFFFFFFFFFFLL)
#endif
#define MAX_DBL_STR 3 + DBL_MANT_DIG - DBL_MIN_EXP
#define MAX_DBL_STR (3 + DBL_MANT_DIG - DBL_MIN_EXP)
#if defined(HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)
/* First check for ANSI C99 definition: */

View File

@@ -40,10 +40,10 @@
Windows does not support MSG_DONTWAIT for send()/recv(). So we need to ensure
that the socket is non-blocking at the start of every operation.
*/
#define WIN_SET_NONBLOCKING(mysql) { \
#define WIN_SET_NONBLOCKING(mysql) do { \
my_bool old_mode; \
if ((mysql)->net.pvio) ma_pvio_blocking((mysql)->net.pvio, FALSE, &old_mode); \
}
} while(0)
#else
#define WIN_SET_NONBLOCKING(mysql)
#endif

View File

@@ -61,7 +61,7 @@
#define UPDATE_STMT_ERROR(stmt)\
SET_CLIENT_STMT_ERROR((stmt), (stmt)->mysql->net.last_errno, (stmt)->mysql->net.sqlstate, (stmt)->mysql->net.last_error)
#define STMT_NUM_OFS(type, a,r) ((type *)(a))[r]
#define STMT_NUM_OFS(type, a, r) (((type *)(a))[r])
#define MADB_RESET_ERROR 1
#define MADB_RESET_LONGDATA 2
#define MADB_RESET_SERVER 4

View File

@@ -26,7 +26,7 @@
#define SC_IO_BUFFER_SIZE 0x4000
#define MAX_SSL_ERR_LEN 100
#define SCHANNEL_PAYLOAD(A) (A).cbMaximumMessage + (A).cbHeader + (A).cbTrailer
#define SCHANNEL_PAYLOAD(A) ((A).cbMaximumMessage + (A).cbHeader + (A).cbTrailer)
void ma_schannel_set_win_error(MARIADB_PVIO *pvio, DWORD ErrorNo);

View File

@@ -34,5 +34,5 @@ POSSIBILITY OF SUCH DAMAGE.
#include <stdio.h>
#define SSPI_MAX_TOKEN_SIZE 50000
#define SEC_ERROR(err) (err < 0)
#define SEC_ERROR(err) ((err) < 0)
extern void sspi_errmsg(int err, char *buf, size_t size);

View File

@@ -85,16 +85,16 @@ typedef struct st_conn_repl {
} REPL_DATA;
#define SET_SLAVE(mysql, data)\
{\
do {\
mysql->net.pvio= data->pvio[MARIADB_SLAVE]; \
data->current_type= MARIADB_SLAVE;\
}
} while(0)
#define SET_MASTER(mysql, data)\
{\
do {\
mysql->net.pvio= data->pvio[MARIADB_MASTER];\
data->current_type= MARIADB_MASTER;\
}
} while(0)
/* parse url

View File

@@ -29,7 +29,7 @@
#include <string.h>
#include <ma_string.h>
#define PVIO_SHM_BUFFER_SIZE 16000 + 4
#define PVIO_SHM_BUFFER_SIZE (16000 + 4)
my_bool pvio_shm_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout);
int pvio_shm_get_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type);

View File

@@ -52,7 +52,7 @@
#include <netinet/ip.h>
#include <netdb.h>
#include <netinet/tcp.h>
#define IS_SOCKET_EINTR(err) (err == SOCKET_EINTR)
#define IS_SOCKET_EINTR(err) ((err) == SOCKET_EINTR)
#else
#include <ws2tcpip.h>
#define O_NONBLOCK 1

View File

@@ -116,7 +116,7 @@ typedef struct {
unsigned long pkt_length;
} TRACE_INFO;
#define TRACE_STATUS(a) (!a) ? "ok" : "error"
#define TRACE_STATUS(a) ((!a) ? "ok" : "error")
TRACE_INFO *trace_info= NULL;

View File

@@ -223,11 +223,11 @@ static int test_change_user(MYSQL *mysql)
/* Prepare environment */
sprintf(buff, "drop database if exists %s", db);
rc= mysql_query(mysql, buff);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
sprintf(buff, "create database %s", db);
rc= mysql_query(mysql, buff);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
sprintf(buff,
"grant select on %s.* to %s@'%%' identified by '%s'",
@@ -235,14 +235,14 @@ static int test_change_user(MYSQL *mysql)
user_pw,
pw);
rc= mysql_query(mysql, buff);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
sprintf(buff,
"grant select on %s.* to %s@'%%'",
db,
user_no_pw);
rc= mysql_query(mysql, buff);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
/* Try some combinations */
@@ -288,13 +288,13 @@ static int test_change_user(MYSQL *mysql)
FAIL_UNLESS(rc, "Error expected");
rc= mysql_change_user(mysql, user_pw, pw, db);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_change_user(mysql, user_pw, pw, NULL);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_change_user(mysql, user_pw, pw, "");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_change_user(mysql, user_no_pw, pw, db);
FAIL_UNLESS(rc, "Error expected");
@@ -306,16 +306,16 @@ static int test_change_user(MYSQL *mysql)
FAIL_UNLESS(rc, "Error expected");
rc= mysql_change_user(mysql, user_no_pw, "", NULL);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_change_user(mysql, user_no_pw, "", "");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_change_user(mysql, user_no_pw, "", db);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_change_user(mysql, user_no_pw, NULL, db);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_change_user(mysql, "", pw, db);
FAIL_UNLESS(rc, "Error expected");
@@ -345,15 +345,15 @@ static int test_change_user(MYSQL *mysql)
sprintf(buff, "drop database %s", db);
rc= mysql_query(mysql, buff);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
sprintf(buff, "drop user %s@'%%'", user_pw);
rc= mysql_query(mysql, buff);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
sprintf(buff, "drop user %s@'%%'", user_no_pw);
rc= mysql_query(mysql, buff);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
return OK;
}
@@ -661,7 +661,7 @@ int test_connection_timeout(MYSQL *unused __attribute__((unused)))
elapsed= time(NULL) - start;
diag("elapsed: %lu", (unsigned long)elapsed);
mysql_close(mysql);
FAIL_IF((unsigned int)elapsed > 2 * timeout, "timeout ignored")
FAIL_IF((unsigned int)elapsed > 2 * timeout, "timeout ignored");
return OK;
}
@@ -681,7 +681,7 @@ int test_connection_timeout2(MYSQL *unused __attribute__((unused)))
elapsed= time(NULL) - start;
diag("elapsed: %lu", (unsigned long)elapsed);
mysql_close(mysql);
FAIL_IF((unsigned int)elapsed > 2 * timeout, "timeout ignored")
FAIL_IF((unsigned int)elapsed > 2 * timeout, "timeout ignored");
return OK;
}
@@ -706,7 +706,7 @@ int test_connection_timeout3(MYSQL *unused __attribute__((unused)))
}
elapsed= time(NULL) - start;
diag("elapsed: %lu", (unsigned long)elapsed);
FAIL_IF((unsigned int)elapsed > timeout + 1, "timeout ignored")
FAIL_IF((unsigned int)elapsed > timeout + 1, "timeout ignored");
mysql_close(mysql);
mysql= mysql_init(NULL);

View File

@@ -1123,7 +1123,7 @@ static int test_bug11909(MYSQL *mysql)
check_stmt_rc(rc, stmt2);
rc= mysql_stmt_fetch(stmt2);
FAIL_UNLESS(rc == 0, "rc != 0")
FAIL_UNLESS(rc == 0, "rc != 0");
FAIL_UNLESS(empno == 10, "empno != 10");
FAIL_UNLESS(strcmp(firstname, "CHRISTINE""") == 0, "firstname != 'Christine'");

View File

@@ -64,57 +64,71 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define MAX_TEST_QUERY_LENGTH 300 /* MAX QUERY BUFFER LENGTH */
/* prevent warnings on Win64 by using STMT_LEN instead of strlen */
#define STMT_LEN(A) (unsigned long)strlen((A))
#define STMT_LEN(A) ((unsigned long)strlen((A)))
#define SKIP_TRAVIS()\
do {\
if (getenv("TRAVIS"))\
{\
diag("Skip test on Travis CI");\
return SKIP;\
}
}\
}while(0)
#define SKIP_MYSQL(mysql)\
do {\
if (!mariadb_connection(mysql))\
{\
diag("Skip test for non MariaDB server");\
return OK;\
}
}\
} while(0)
#define check_mysql_rc(rc, mysql) \
do {\
if (rc)\
{\
diag("Error (%d): %s (%d) in %s line %d", rc, mysql_error(mysql), \
mysql_errno(mysql), __FILE__, __LINE__);\
return(FAIL);\
}
}\
} while(0)
#define check_stmt_rc(rc, stmt) \
do {\
if (rc)\
{\
diag("Error: %s (%s: %d)", mysql_stmt_error(stmt), __FILE__, __LINE__);\
return(FAIL);\
}
}\
} while(0)
#define FAIL_IF(expr, reason)\
do {\
if (expr)\
{\
diag("Error: %s (%s: %d)", (reason) ? reason : "", __FILE__, __LINE__);\
return FAIL;\
}
}\
} while(0)
#define FAIL_UNLESS(expr, reason)\
do {\
if (!(expr))\
{\
diag("Error: %s (%s: %d)", reason, __FILE__, __LINE__);\
return FAIL;\
}
}\
} while(0)
#define SKIP_CONNECTION_HANDLER \
do {\
if (hostname && strstr(hostname, "://"))\
{\
diag("Test skipped (connection handler)");\
return SKIP;\
}
}\
} while(0)
/* connection options */
#define TEST_CONNECTION_DEFAULT 1 /* default connection */

View File

@@ -678,7 +678,7 @@ static int test_prepare_ext(MYSQL *mysql)
char query[MAX_TEST_QUERY_LENGTH];
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prepare_ext");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
sql= (char *)"CREATE TABLE test_prepare_ext"
"("
@@ -716,7 +716,7 @@ static int test_prepare_ext(MYSQL *mysql)
" c32 set('monday', 'tuesday', 'wednesday'))";
rc= mysql_query(mysql, sql);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
/* insert by prepare - all integers */
strcpy(query, "INSERT INTO test_prepare_ext(c1, c2, c3, c4, c5, c6) VALUES(?, ?, ?, ?, ?, ?)");
@@ -785,7 +785,7 @@ static int test_prepare_ext(MYSQL *mysql)
mysql_stmt_close(stmt);
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prepare_ext");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
return OK;
}
@@ -1203,7 +1203,7 @@ static int test_long_data(MYSQL *mysql)
stmt= mysql_stmt_init(mysql);
FAIL_IF(!stmt, mysql_error(mysql));
rc= mysql_stmt_prepare(stmt, SL(query));
check_stmt_rc(rc, stmt)
check_stmt_rc(rc, stmt);
FAIL_IF(mysql_stmt_param_count(stmt) != 3, "Paramcount != 3");
@@ -1296,7 +1296,7 @@ static int test_long_data_str(MYSQL *mysql)
stmt= mysql_stmt_init(mysql);
FAIL_IF(!stmt, mysql_error(mysql));
rc= mysql_stmt_prepare(stmt, SL(query));
check_stmt_rc(rc, stmt)
check_stmt_rc(rc, stmt);
FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Paramcount != 2");
@@ -1395,7 +1395,7 @@ static int test_long_data_str1(MYSQL *mysql)
stmt= mysql_stmt_init(mysql);
FAIL_IF(!stmt, mysql_error(mysql));
rc= mysql_stmt_prepare(stmt, SL(query));
check_stmt_rc(rc, stmt)
check_stmt_rc(rc, stmt);
FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Paramcount != 2");
@@ -1465,7 +1465,7 @@ static int test_long_data_str1(MYSQL *mysql)
stmt= mysql_stmt_init(mysql);
FAIL_IF(!stmt, mysql_error(mysql));
rc= mysql_stmt_prepare(stmt, SL(query));
check_stmt_rc(rc, stmt)
check_stmt_rc(rc, stmt);
FAIL_IF(mysql_stmt_param_count(stmt) != 0, "Paramcount != 0");
@@ -1560,7 +1560,7 @@ static int test_long_data_bin(MYSQL *mysql)
stmt= mysql_stmt_init(mysql);
FAIL_IF(!stmt, mysql_error(mysql));
rc= mysql_stmt_prepare(stmt, SL(query));
check_stmt_rc(rc, stmt)
check_stmt_rc(rc, stmt);
FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Paramcount != 2");
@@ -1653,7 +1653,7 @@ static int test_simple_delete(MYSQL *mysql)
stmt= mysql_stmt_init(mysql);
FAIL_IF(!stmt, mysql_error(mysql));
rc= mysql_stmt_prepare(stmt, SL(query));
check_stmt_rc(rc, stmt)
check_stmt_rc(rc, stmt);
FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Paramcount != 2");

View File

@@ -1064,10 +1064,10 @@ static int test_bug1946(MYSQL *mysql)
rc= mysql_query(mysql, "DROP TABLE IF EXISTS prepare_command");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "CREATE TABLE prepare_command(ID INT)");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
stmt= mysql_stmt_init(mysql);
FAIL_IF(!stmt, mysql_error(mysql));
@@ -1106,9 +1106,9 @@ static int test_bug20152(MYSQL *mysql)
tm.second = 42;
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "CREATE TABLE t1 (f1 DATE)");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
stmt= mysql_stmt_init(mysql);
rc= mysql_stmt_prepare(stmt, SL(query));
@@ -1120,7 +1120,7 @@ static int test_bug20152(MYSQL *mysql)
rc= mysql_stmt_close(stmt);
check_stmt_rc(rc, stmt);
rc= mysql_query(mysql, "DROP TABLE t1");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
FAIL_UNLESS(tm.hour == 14 && tm.minute == 9 && tm.second == 42, "time != 14:09:42");
return OK;
}
@@ -1142,10 +1142,10 @@ static int test_bug2247(MYSQL *mysql)
/* create table and insert few rows */
rc= mysql_query(mysql, drop);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, create);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
stmt= mysql_stmt_init(mysql);
FAIL_IF(!stmt, mysql_error(mysql));
@@ -1160,7 +1160,7 @@ static int test_bug2247(MYSQL *mysql)
FAIL_UNLESS(exp_count == 1, "exp_count != 1");
rc= mysql_query(mysql, SELECT);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
/*
mysql_store_result overwrites mysql->affected_rows. Check that
mysql_stmt_affected_rows() returns the same value, whereas
@@ -1173,7 +1173,7 @@ static int test_bug2247(MYSQL *mysql)
FAIL_UNLESS(exp_count == mysql_stmt_affected_rows(stmt), "affected_rows != exp_count");
rc= mysql_query(mysql, update);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
FAIL_UNLESS(mysql_affected_rows(mysql) == NUM_ROWS, "affected_rows != NUM_ROWS");
FAIL_UNLESS(exp_count == mysql_stmt_affected_rows(stmt), "affected_rows != exp_count");
@@ -1192,13 +1192,13 @@ static int test_bug2247(MYSQL *mysql)
FAIL_UNLESS(exp_count == NUM_ROWS, "exp_count != NUM_ROWS");
rc= mysql_query(mysql, insert);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
FAIL_UNLESS(mysql_affected_rows(mysql) == 1, "affected_rows != 1");
FAIL_UNLESS(exp_count == mysql_stmt_affected_rows(stmt), "affected_rows != exp_count");
mysql_stmt_close(stmt);
rc= mysql_query(mysql, drop);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
return OK;
}
@@ -1215,10 +1215,10 @@ static int test_bug2248(MYSQL *mysql)
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bug2248");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "CREATE TABLE test_bug2248 (id int)");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
stmt= mysql_stmt_init(mysql);
FAIL_IF(!stmt, mysql_error(mysql));
@@ -1256,7 +1256,7 @@ static int test_bug2248(MYSQL *mysql)
mysql_stmt_close(stmt);
rc= mysql_query(mysql, "DROP TABLE test_bug2248");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
return OK;
}
@@ -2658,7 +2658,7 @@ static int test_bug5194(MYSQL *mysql)
MAX_PARAM_COUNT * CHARS_PER_PARAM + 1);
param_str= (char*) malloc(COLUMN_COUNT * CHARS_PER_PARAM);
FAIL_IF(my_bind == 0 || query == 0 || param_str == 0, "Not enough memory")
FAIL_IF(my_bind == 0 || query == 0 || param_str == 0, "Not enough memory");
stmt= mysql_stmt_init(mysql);

View File

@@ -541,16 +541,16 @@ static int test_bug19671(MYSQL *mysql)
mysql_query(mysql, "set sql_mode=''");
rc= mysql_query(mysql, "drop table if exists t1");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "drop view if exists v1");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "create table t1(f1 int)");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "create view v1 as select va.* from t1 va");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
result= mysql_list_fields(mysql, "v1", NULL);
FAIL_IF(!result, "Invalid result set");
@@ -568,8 +568,8 @@ static int test_bug19671(MYSQL *mysql)
}
mysql_free_result(result);
check_mysql_rc(mysql_query(mysql, "drop view v1"), mysql)
check_mysql_rc(mysql_query(mysql, "drop table t1"), mysql)
check_mysql_rc(mysql_query(mysql, "drop view v1"), mysql);
check_mysql_rc(mysql_query(mysql, "drop table t1"), mysql);
return OK;
}
@@ -604,17 +604,17 @@ static int test_bug21726(MYSQL *mysql)
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, update_query);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
insert_id= mysql_insert_id(mysql);
FAIL_UNLESS(insert_id == 2, "insert_id != 2");
rc= mysql_query(mysql, update_query);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
insert_id= mysql_insert_id(mysql);
FAIL_UNLESS(insert_id == 3, "insert_id != 3");
rc= mysql_query(mysql, select_query);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
insert_id= mysql_insert_id(mysql);
FAIL_UNLESS(insert_id == 3, "insert_id != 3");
result= mysql_store_result(mysql);