Formatting

This commit is contained in:
Alexey Romanov
2010-11-23 16:25:08 +03:00
parent 2ea2dc8fcc
commit b256eae5dd

View File

@@ -118,8 +118,9 @@ static int control(ErlDrvData drv_data, unsigned int command, char *buf,
return 0;
}
static inline int return_error(sqlite3_drv_t *drv, int error_code,
const char *error, ErlDrvTermData **spec, int *term_count) {
static inline int return_error(
sqlite3_drv_t *drv, int error_code, const char *error,
ErlDrvTermData **spec, int *term_count) {
*spec = (ErlDrvTermData *) malloc(11 * sizeof(ErlDrvTermData));
(*spec)[0] = ERL_DRV_PORT;
(*spec)[1] = driver_mk_port(drv->port);
@@ -136,7 +137,8 @@ static inline int return_error(sqlite3_drv_t *drv, int error_code,
return 0;
}
static inline int output_error(sqlite3_drv_t *drv, int error_code, const char *error) {
static inline int output_error(
sqlite3_drv_t *drv, int error_code, const char *error) {
ErlDrvTermData *dataset;
int term_count;
return_error(drv, error_code, error, &dataset, &term_count);
@@ -158,8 +160,7 @@ static inline int sql_exec_statement(sqlite3_drv_t *drv, sqlite3_stmt *statement
// fflush(drv->log);
if (sqlite3_threadsafe()) {
drv->async_handle =
driver_async(drv->port, &drv->key, sql_exec_async,
drv->async_handle = driver_async(drv->port, &drv->key, sql_exec_async,
async_command, sql_free_async);
} else {
sql_exec_async(async_command);
@@ -186,7 +187,8 @@ static int sql_exec(sqlite3_drv_t *drv, char *command, int command_size) {
}
static inline int decode_and_bind_param(
sqlite3_drv_t *drv, char *buffer, int *index, sqlite3_stmt *statement, int param_index, int *type, int *size) {
sqlite3_drv_t *drv, char *buffer, int *index,
sqlite3_stmt *statement, int param_index, int *type, int *size) {
int result;
ei_get_type(buffer, index, type, size);
long long_val;
@@ -194,10 +196,10 @@ static inline int decode_and_bind_param(
double double_val;
char* char_buf_val;
switch (*type) {
// case ERL_SMALL_INTEGER_EXT:
// ei_decode_long(buffer, index, &long_val);
// result = sqlite3_bind_int(statement, param_index, long_val);
// break;
// case ERL_SMALL_INTEGER_EXT:
// ei_decode_long(buffer, index, &long_val);
// result = sqlite3_bind_int(statement, param_index, long_val);
// break;
case ERL_SMALL_INTEGER_EXT:
case ERL_INTEGER_EXT:
case ERL_SMALL_BIG_EXT:
@@ -211,6 +213,7 @@ static inline int decode_and_bind_param(
result = sqlite3_bind_double(statement, param_index, double_val);
break;
case ERL_ATOM_EXT:
// include space for null separator
char_buf_val = malloc((*size + 1) * sizeof(char));
ei_decode_atom(buffer, index, char_buf_val);
if (strncmp(char_buf_val, "null", 5) == 0) {
@@ -222,7 +225,8 @@ static inline int decode_and_bind_param(
}
break;
case ERL_STRING_EXT:
char_buf_val = malloc((*size + 1) * sizeof(char)); // space for null separator
// include space for null separator
char_buf_val = malloc((*size + 1) * sizeof(char));
ei_decode_string(buffer, index, char_buf_val);
result = sqlite3_bind_text(statement, param_index, char_buf_val, *size, &free);
break;
@@ -292,7 +296,6 @@ static int sql_bind_and_exec(sqlite3_drv_t *drv, char *buffer, int buffer_size)
char param_name[MAXATOMLEN + 1]; // parameter names shouldn't be longer than 256!
while (index < buffer_size) {
ei_decode_list_header(buffer, &index, &cur_list_size);
// note the finish condition; the last element is the tail and we shouldn't decode it!
for (i = 0; i < cur_list_size; i++) {
ei_get_type(buffer, &index, &type, &size);
if (type == ERL_SMALL_TUPLE_EXT) {
@@ -333,9 +336,12 @@ static int sql_bind_and_exec(sqlite3_drv_t *drv, char *buffer, int buffer_size)
param_index = sqlite3_bind_parameter_index(statement, param_name);
break;
default:
return output_error(drv, SQLITE_MISMATCH, "parameter index must be given as integer, atom, or string");
return output_error(
drv, SQLITE_MISMATCH,
"parameter index must be given as integer, atom, or string");
}
result = decode_and_bind_param(drv, buffer, &index, statement, param_index, &type, &size);
result = decode_and_bind_param(
drv, buffer, &index, statement, param_index, &type, &size);
if (result != SQLITE_OK) {
return result; // error has already been output
}
@@ -343,11 +349,13 @@ static int sql_bind_and_exec(sqlite3_drv_t *drv, char *buffer, int buffer_size)
else {
IMPLICIT_INDEX:
if (param_indices_are_explicit) {
return output_error(drv, SQLITE_MISUSE,
return output_error(
drv, SQLITE_MISUSE,
"parameters without indices shouldn't follow indexed or named parameters");
}
result = decode_and_bind_param(drv, buffer, &index, statement, param_index, &type, &size);
result = decode_and_bind_param(
drv, buffer, &index, statement, param_index, &type, &size);
if (result != SQLITE_OK) {
return result; // error has already been output
}
@@ -553,13 +561,13 @@ static void sql_exec_async(void *_async_command) {
async_command->binaries = binaries;
if (next_row == SQLITE_BUSY) {
return_error(drv, SQLITE_BUSY, "SQLite3 database is busy", &async_command->dataset,
&async_command->term_count);
return_error(drv, SQLITE_BUSY, "SQLite3 database is busy",
&async_command->dataset, &async_command->term_count);
return;
}
if (next_row != SQLITE_DONE) {
return_error(drv, next_row, sqlite3_errmsg(drv->db), &async_command->dataset,
&async_command->term_count);
return_error(drv, next_row, sqlite3_errmsg(drv->db),
&async_command->dataset, &async_command->term_count);
return;
}