Support script execution (no error messages currently)

This commit is contained in:
Alexey Romanov
2011-01-24 14:01:35 +03:00
parent 9d138346cd
commit 9f57f6ae39
4 changed files with 75 additions and 2 deletions

View File

@@ -162,6 +162,9 @@ static int control(
case CMD_PREPARED_COLUMNS:
prepared_columns(driver_data, buf, len);
break;
case CMD_SQL_EXEC_SCRIPT:
sql_exec_script(driver_data, buf, len);
break;
default:
unknown(driver_data, buf, len);
}
@@ -193,7 +196,7 @@ static inline int output_error(
int term_count;
return_error(drv, error_code, error, &dataset, &term_count);
driver_output_term(drv->port, dataset, term_count);
return 0;
return 1;
}
static inline int output_db_error(sqlite3_drv_t *drv) {
@@ -259,6 +262,32 @@ static int sql_exec(sqlite3_drv_t *drv, char *command, int command_size) {
return sql_exec_statement(drv, statement);
}
static int sql_exec_script(sqlite3_drv_t *drv, char *command, int command_size) {
int result;
const char *rest = command;
const char *end = command + command_size;
sqlite3_stmt *statement;
// printf("SQL: %.*s\n", command_size, command);
while (rest < end) {
result = sqlite3_prepare_v2(drv->db, command, end - command, &statement, &rest);
command = (char *) rest; // won't actually mutate!
if (result != SQLITE_OK) {
return output_db_error(drv);
} else if (statement == NULL) {
return output_error(drv, SQLITE_MISUSE, "empty statement");
}
result = sql_exec_statement(drv, statement);
if (result) {
// there was an error, bail out
return result;
}
}
return result;
}
static inline int decode_and_bind_param(
sqlite3_drv_t *drv, char *buffer, int *p_index,
sqlite3_stmt *statement, int param_index, int *p_type, int *p_size) {

View File

@@ -34,6 +34,7 @@
#define CMD_PREPARED_CLEAR_BINDINGS 9
#define CMD_PREPARED_FINALIZE 10
#define CMD_PREPARED_COLUMNS 11
#define CMD_SQL_EXEC_SCRIPT 12
// Number of bytes for each key
// (160 bits for SHA1 hash)
@@ -84,6 +85,7 @@ static int control(ErlDrvData drv_data, unsigned int command, char *buf,
int len, char **rbuf, int rlen);
static int sql_exec(sqlite3_drv_t *drv, char *buf, int len);
static int sql_bind_and_exec(sqlite3_drv_t *drv, char *buf, int len);
static int sql_exec_script(sqlite3_drv_t *drv, char *buf, int len);
static int prepare(sqlite3_drv_t *drv, char *buf, int len);
static int prepared_bind(sqlite3_drv_t *drv, char *buf, int len);
static int prepared_step(sqlite3_drv_t *drv, char *buf, int len);