Index: otp/lib/odbc/c_src/odbcserver.c =================================================================== --- otp.orig/lib/odbc/c_src/odbcserver.c 2015-04-28 01:58:07.000000000 +0300 +++ otp/lib/odbc/c_src/odbcserver.c 2015-04-28 02:03:32.132350400 +0300 @@ -138,18 +138,18 @@ #else void database_handler(const char *port); #endif -static db_result_msg handle_db_request(byte *reqstring, db_state *state); +static db_result_msg handle_db_request(Byte *reqstring, db_state *state); static void supervise(const char *port); /* ----------------- ODBC functions --------------------------------------*/ -static db_result_msg db_connect(byte *connStrIn, db_state *state); +static db_result_msg db_connect(Byte *connStrIn, db_state *state); static db_result_msg db_close_connection(db_state *state); -static db_result_msg db_end_tran(byte compleationtype, db_state *state); -static db_result_msg db_query(byte *sql, db_state *state); -static db_result_msg db_select_count(byte *sql,db_state *state); -static db_result_msg db_select(byte *args, db_state *state); -static db_result_msg db_param_query(byte *buffer, db_state *state); -static db_result_msg db_describe_table(byte *sql, db_state *state); +static db_result_msg db_end_tran(Byte compleationtype, db_state *state); +static db_result_msg db_query(Byte *sql, db_state *state); +static db_result_msg db_select_count(Byte *sql,db_state *state); +static db_result_msg db_select(Byte *args, db_state *state); +static db_result_msg db_param_query(Byte *buffer, db_state *state); +static db_result_msg db_describe_table(Byte *sql, db_state *state); /* ------------- Encode/decode functions -------- ------------------------*/ @@ -177,31 +177,31 @@ db_state *state); static void encode_data_type(SQLSMALLINT sql_type, SQLINTEGER size, SQLSMALLINT decimal_digits, db_state *state); -static Boolean decode_params(db_state *state, byte *buffer, int *index, param_array **params, +static Boolean decode_params(db_state *state, Byte *buffer, int *index, param_array **params, int i, int j, int num_param_values); /*------------- Erlang port communication functions ----------------------*/ -static int read_exact(byte *buf, int len); -static byte * receive_erlang_port_msg(void); +static int read_exact(Byte *buf, int len); +static Byte * receive_erlang_port_msg(void); /* ------------- Socket communication functions --------------------------*/ #ifdef WIN32 static SOCKET connect_to_erlang(const char *port); static void send_msg(db_result_msg *msg, SOCKET socket); -static byte *receive_msg(SOCKET socket); +static Byte *receive_msg(SOCKET socket); static Boolean receive_msg_part(SOCKET socket, - byte * buffer, size_t msg_len); -static Boolean send_msg_part(SOCKET socket, byte * buffer, size_t msg_len); + Byte * buffer, size_t msg_len); +static Boolean send_msg_part(SOCKET socket, Byte * buffer, size_t msg_len); static void close_socket(SOCKET socket); static void init_winsock(void); #elif defined(UNIX) static int connect_to_erlang(const char *port); static void send_msg(db_result_msg *msg, int socket); -static byte *receive_msg(int socket); -static Boolean receive_msg_part(int socket, byte * buffer, size_t msg_len); -static Boolean send_msg_part(int socket, byte * buffer, size_t msg_len); +static Byte *receive_msg(int socket); +static Boolean receive_msg_part(int socket, Byte * buffer, size_t msg_len); +static Boolean send_msg_part(int socket, Byte * buffer, size_t msg_len); static void close_socket(int socket); static void tcp_nodelay(int sock); #endif @@ -221,7 +221,7 @@ static void init_driver(int erl_auto_commit_mode, int erl_trace_driver, db_state *state); -static void init_param_column(param_array *params, byte *buffer, int *index, +static void init_param_column(param_array *params, Byte *buffer, int *index, int num_param_values, db_state* state); static void init_param_statement(int cols, @@ -234,7 +234,7 @@ static db_result_msg map_sql_2_c_column(db_column* column, db_state *state); -static param_array * bind_parameter_arrays(byte *buffer, int *index, +static param_array * bind_parameter_arrays(Byte *buffer, int *index, int cols, int num_param_values, db_state *state); @@ -268,7 +268,7 @@ int main(void) { - byte *msg = NULL; + Byte *msg = NULL; char *temp = NULL, *supervisor_port = NULL, *odbc_port = NULL; size_t length; #ifdef WIN32 @@ -320,7 +320,7 @@ #endif void supervise(const char *port) { - byte *msg = NULL; + Byte *msg = NULL; int reason; #ifdef WIN32 SOCKET socket; @@ -345,17 +345,17 @@ } #ifdef WIN32 -DWORD WINAPI database_handler(const char *port) +void WINAPI database_handler(const char *port) #else - void database_handler(const char *port) +void database_handler(const char *port) #endif { db_result_msg msg; - byte *request_buffer = NULL; + Byte *request_buffer = NULL; db_state state = {NULL, NULL, NULL, NULL, 0, {NULL, 0, 0}, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE}; - byte request_id; + Byte request_id; #ifdef WIN32 SOCKET socket; init_winsock(); @@ -397,15 +397,15 @@ /* Description: Calls the appropriate function to handle the database request recived from the erlang-process. Returns a message to send back to erlang. */ -static db_result_msg handle_db_request(byte *reqstring, db_state *state) +static db_result_msg handle_db_request(Byte *reqstring, db_state *state) { - byte *args; - byte request_id; + Byte *args; + Byte request_id; - /* First byte is an index that identifies the requested command the + /* First Byte is an index that identifies the requested command the rest is the argument string. */ request_id = reqstring[0]; - args = reqstring + sizeof(byte); + args = reqstring + sizeof(Byte); switch(request_id) { case OPEN_CONNECTION: @@ -414,9 +414,9 @@ return db_close_connection(state); case COMMIT_TRANSACTION: if(args[0] == COMMIT) { - return db_end_tran((byte)SQL_COMMIT, state); + return db_end_tran((Byte)SQL_COMMIT, state); } else { /* args[0] == ROLLBACK */ - return db_end_tran((byte)SQL_ROLLBACK, state); + return db_end_tran((Byte)SQL_ROLLBACK, state); } case QUERY: return db_query(args, state); @@ -437,7 +437,7 @@ /* Description: Tries to open a connection to the database using , returns a message indicating the outcome. */ -static db_result_msg db_connect(byte *args, db_state *state) +static db_result_msg db_connect(Byte *args, db_state *state) { /* * Danil Onishchenko aka RubberCthulhu, alevandal@gmail.com. 2013.01.09. @@ -458,7 +458,7 @@ SQLSMALLINT stringlength2ptr = 0, connlen; db_result_msg msg; diagnos diagnos; - byte *connStrIn; + Byte *connStrIn; int erl_auto_commit_mode, erl_trace_driver, use_srollable_cursors, tuple_row_state, binary_strings, extended_errors; @@ -469,7 +469,7 @@ tuple_row_state = args[3]; binary_strings = args[4]; extended_errors = args[5]; - connStrIn = args + 6 * sizeof(byte); + connStrIn = args + 6 * sizeof(Byte); if(tuple_row_state == ON) { tuple_row(state) = TRUE; @@ -592,7 +592,7 @@ /* Description: Requests a commit or rollback operation for all active operations on all statements associated with the connection handle . Returns an ok or error message. */ -static db_result_msg db_end_tran(byte compleationtype, db_state *state) +static db_result_msg db_end_tran(Byte compleationtype, db_state *state) { SQLRETURN result; diagnos diagnos; @@ -610,12 +610,12 @@ /* Description: Executes an sql query and encodes the result set as an erlang term into the message buffer of the returned message-struct. */ -static db_result_msg db_query(byte *sql, db_state *state) +static db_result_msg db_query(Byte *sql, db_state *state) { SQLRETURN result; db_result_msg msg; diagnos diagnos; - byte is_error[6]; + Byte is_error[6]; if (associated_result_set(state)) { clean_state(state); @@ -694,7 +694,7 @@ /* Description: Executes an sql query. Returns number of rows in the result set. */ -static db_result_msg db_select_count(byte *sql, db_state *state) +static db_result_msg db_select_count(Byte *sql, db_state *state) { SQLSMALLINT num_of_columns; SQLLEN num_of_rows; @@ -740,12 +740,12 @@ /* Description: Fetches rows from the result set associated with the connection by db_select_count. The method of seletion will be according too */ -static db_result_msg db_select(byte *args, db_state *state) +static db_result_msg db_select(Byte *args, db_state *state) { db_result_msg msg; SQLSMALLINT num_of_columns; int offset, n, orientation; - byte erlOrientation; + Byte erlOrientation; erlOrientation = args[0]; @@ -772,17 +772,17 @@ break; case SELECT_ABSOLUTE: orientation = SQL_FETCH_ABSOLUTE; - offset = atoi(strtok((char *)(args + sizeof(byte)), ";")); + offset = atoi(strtok((char *)(args + sizeof(Byte)), ";")); n = atoi(strtok(NULL, ";")); break; case SELECT_RELATIVE: orientation = SQL_FETCH_RELATIVE; - offset = atoi(strtok((char *)(args + sizeof(byte)), ";")); + offset = atoi(strtok((char *)(args + sizeof(Byte)), ";")); n = atoi(strtok(NULL, ";")); break; case SELECT_N_NEXT: orientation = SQL_FETCH_NEXT; - offset = atoi(strtok((char *)(args + sizeof(byte)), ";")); + offset = atoi(strtok((char *)(args + sizeof(Byte)), ";")); n = atoi(strtok(NULL, ";")); break; default: @@ -818,9 +818,9 @@ /* Description: Handles parameterized queries ex: INSERT INTO FOO VALUES(?, ?) */ -static db_result_msg db_param_query(byte *buffer, db_state *state) +static db_result_msg db_param_query(Byte *buffer, db_state *state) { - byte *sql; + Byte *sql; db_result_msg msg; SQLLEN num_param_values; int i, ver = 0, @@ -846,7 +846,7 @@ ei_get_type(buffer, &index, &erl_type, &size); - sql = (byte*)safe_malloc((sizeof(byte) * (size + 1))); + sql = (Byte*)safe_malloc((sizeof(Byte) * (size + 1))); ei_decode_string(buffer, &index, sql); ei_decode_long(buffer, &index, &long_num_param_values); @@ -931,7 +931,7 @@ } -static db_result_msg db_describe_table(byte *sql, db_state *state) +static db_result_msg db_describe_table(Byte *sql, db_state *state) { db_result_msg msg; SQLSMALLINT num_of_columns; @@ -1030,7 +1030,7 @@ ei_encode_string(NULL, &index, reason); msg.length = index; - msg.buffer = (byte *)safe_malloc(index); + msg.buffer = (Byte *)safe_malloc(index); msg.dyn_alloc = FALSE; index = 0; @@ -1059,7 +1059,7 @@ ei_encode_atom(NULL, &index, atom); msg.length = index; - msg.buffer = (byte *)safe_malloc(index); + msg.buffer = (Byte *)safe_malloc(index); msg.dyn_alloc = FALSE; index = 0; @@ -1233,7 +1233,7 @@ break; case SQL_C_BIT: ei_x_encode_atom(&dynamic_buffer(state), - ((byte*)values)[j]==TRUE?"true":"false"); + ((Byte*)values)[j]==TRUE?"true":"false"); break; default: ei_x_encode_atom(&dynamic_buffer(state), "error"); @@ -1454,7 +1454,7 @@ ei_encode_long(NULL, &index, num_of_rows); } msg.length = index; - msg.buffer = (byte *)safe_malloc(index); + msg.buffer = (Byte *)safe_malloc(index); msg.dyn_alloc = FALSE; index = 0; @@ -1651,7 +1651,7 @@ } } -static Boolean decode_params(db_state *state, byte *buffer, int *index, param_array **params, +static Boolean decode_params(db_state *state, Byte *buffer, int *index, param_array **params, int i, int j, int num_param_values) { int erl_type, size; @@ -1724,8 +1724,8 @@ return FALSE; } - /* For 64-bit platforms we downcast 8-byte long - * to 4-byte SQLINTEGER, checking for overflow */ + /* For 64-bit platforms we downcast 8-Byte long + * to 4-Byte SQLINTEGER, checking for overflow */ if(l64>INT_MAX || l64length; @@ -1999,9 +1999,9 @@ } #ifdef WIN32 -static Boolean send_msg_part(SOCKET socket, byte * buffer, size_t msg_len) +static Boolean send_msg_part(SOCKET socket, Byte * buffer, size_t msg_len) #elif defined(UNIX) -static Boolean send_msg_part(int socket, byte * buffer, size_t msg_len) +static Boolean send_msg_part(int socket, Byte * buffer, size_t msg_len) #endif { int nr_bytes_sent = 0; @@ -2196,7 +2196,7 @@ DO_EXIT(EXIT_CONNECTION); } -static void init_param_column(param_array *params, byte *buffer, int *index, +static void init_param_column(param_array *params, Byte *buffer, int *index, int num_param_values, db_state* state) { long user_type, precision, scale, length; @@ -2253,8 +2253,8 @@ params->type.strlen_or_indptr_array = alloc_strlen_indptr(num_param_values, SQL_NTS); params->values.string = - (byte *)safe_malloc(num_param_values * - sizeof(byte)* params->type.len); + (Byte *)safe_malloc(num_param_values * + sizeof(Byte)* params->type.len); } break; case USER_CHAR: @@ -2272,8 +2272,8 @@ params->type.strlen_or_indptr_array = alloc_strlen_indptr(num_param_values, SQL_NTS); params->values.string = - (byte *)safe_malloc(num_param_values * - sizeof(byte)* params->type.len); + (Byte *)safe_malloc(num_param_values * + sizeof(Byte)* params->type.len); break; case USER_WCHAR: @@ -2295,7 +2295,7 @@ params->type.strlen_or_indptr_array = alloc_strlen_indptr(num_param_values, SQL_NTS); params->values.string = - (byte *)safe_malloc(num_param_values * sizeof(byte) * params->type.len); + (Byte *)safe_malloc(num_param_values * sizeof(Byte) * params->type.len); break; case USER_TIMESTAMP: @@ -2304,7 +2304,7 @@ params->type.c = SQL_C_TYPE_TIMESTAMP; params->type.col_size = (SQLUINTEGER)COL_SQL_TIMESTAMP; params->values.string = - (byte *)safe_malloc(num_param_values * params->type.len); + (Byte *)safe_malloc(num_param_values * params->type.len); break; case USER_FLOAT: params->type.sql = SQL_FLOAT; @@ -2334,10 +2334,10 @@ case USER_BOOLEAN: params->type.sql = SQL_BIT; params->type.c = SQL_C_BIT; - params->type.len = sizeof(byte); + params->type.len = sizeof(Byte); params->type.col_size = params->type.len; params->values.bool = - (byte *)safe_malloc(num_param_values * params->type.len); + (Byte *)safe_malloc(num_param_values * params->type.len); break; } params->offset = 0; @@ -2445,7 +2445,7 @@ case SQL_LONGVARBINARY: column -> type.len = (column -> type.col_size) + /* Make place for NULL termination */ - sizeof(byte); + sizeof(Byte); column -> type.c = SQL_C_CHAR; column -> type.strlen_or_indptr = SQL_NTS; break; @@ -2479,7 +2479,7 @@ case SQL_TYPE_DATE: case SQL_TYPE_TIME: column -> type.len = (column -> type.col_size) + - sizeof(byte); + sizeof(Byte); column -> type.c = SQL_C_CHAR; column -> type.strlen_or_indptr = SQL_NTS; break; @@ -2494,7 +2494,7 @@ column -> type.strlen_or_indptr = (SQLLEN)NULL; break; case SQL_BIT: - column -> type.len = sizeof(byte); + column -> type.len = sizeof(Byte); column -> type.c = SQL_C_BIT; column -> type.strlen_or_indptr = (SQLLEN)NULL; break; @@ -2508,7 +2508,7 @@ return msg; } -static param_array * bind_parameter_arrays(byte *buffer, int *index, +static param_array * bind_parameter_arrays(Byte *buffer, int *index, int cols, int num_param_values, db_state *state) { @@ -2722,13 +2722,13 @@ SQLINTEGER nativeError; SQLSMALLINT errmsg_buffer_size, record_nr, errmsg_size; int acc_errmsg_size; - byte *current_errmsg_pos; + Byte *current_errmsg_pos; SQLCHAR current_sql_state[SQL_STATE_SIZE]; SQLRETURN result; diagnos.error_msg[0] = 0; - current_errmsg_pos = (byte *)diagnos.error_msg; + current_errmsg_pos = (Byte *)diagnos.error_msg; /* number bytes free in error message buffer */ errmsg_buffer_size = MAX_ERR_MSG - ERRMSG_HEADR_SIZE; Index: otp/lib/odbc/c_src/odbcserver.h =================================================================== --- otp.orig/lib/odbc/c_src/odbcserver.h 2015-04-28 01:57:03.000000000 +0300 +++ otp/lib/odbc/c_src/odbcserver.h 2015-04-28 02:03:32.179017300 +0300 @@ -119,7 +119,7 @@ /*------------------------ TYPDEFS ----------------------------------*/ -typedef char byte; +typedef char Byte; typedef int Boolean; typedef struct { @@ -139,14 +139,14 @@ typedef struct { int length; - byte *buffer; + Byte *buffer; Boolean dyn_alloc; } db_result_msg; typedef struct { SQLCHAR sqlState[SQL_STATE_SIZE]; SQLINTEGER nativeError; - byte error_msg[MAX_ERR_MSG]; + Byte error_msg[MAX_ERR_MSG]; } diagnos; typedef struct { @@ -154,10 +154,10 @@ int offset; SQLUSMALLINT input_output_type; union { - byte *string; + Byte *string; SQLINTEGER *integer; double *floating; - byte *bool; + Byte *bool; }values; } param_array;