From f0d35340b47a3dc710157e2625eb17e32b161457 Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Wed, 8 May 2024 15:59:52 -0400 Subject: [PATCH] K&R no more --- README | 2 +- dist/Makefile.in | 8 +- dist/srcfiles.in | 1 + src/api.c | 199 ++--- src/api_table.c | 9 +- src/cg_attach.c | 17 +- src/cg_auth.c | 12 +- src/cg_build.c | 168 +---- src/cg_date.c | 27 +- src/cg_delete.c | 9 +- src/cg_expr.c | 88 +-- src/cg_pragma.c | 12 +- src/cg_select.c | 104 +-- src/cg_trigger.c | 52 +- src/cg_vacuum.c | 12 +- src/cg_where.c | 23 +- src/clib/random.c | 3 +- src/clib/xvprintf.c | 9 +- src/common/dbsql_alloc.c | 28 +- src/common/dbsql_err.c | 10 +- src/common/hash.c | 12 +- src/common/str.c | 49 +- src/dbsql.in | 8 +- src/dbsql/dbsql.c | 26 +- src/dbsql_tclsh.c | 4 +- src/inc/db_int.h | 1 - src/inc/os_ext.h | 1 + src/os/os_jtime.c | 3 +- src/os/os_sleep.c | 59 ++ src/py/src/cache.c | 397 ---------- src/py/src/connection.c | 1325 --------------------------------- src/py/src/cursor.c | 1091 --------------------------- src/py/src/module.c | 422 ----------- src/py/src/prepare_protocol.c | 106 --- src/py/src/row.c | 255 ------- src/py/src/statement.c | 457 ------------ src/safety.c | 9 +- src/sm.c | 114 +-- src/sql_fns.c | 18 +- src/vdbe.c | 46 +- src/vdbe_method.c | 121 +-- test/scr050/crashtest1.c | 4 +- test/scr050/dbsql_tclsh.c | 220 ++---- test/scr050/tcl_dbsql.c | 43 +- test/scr050/tcl_internal.c | 20 +- test/scr050/tcl_md5.c | 9 +- test/scr050/tcl_printf.c | 113 +-- test/scr050/tcl_sql_funcs.c | 3 +- test/scr050/tcl_threads.c | 2 +- 49 files changed, 459 insertions(+), 5272 deletions(-) create mode 100644 src/os/os_sleep.c diff --git a/README b/README index 1cd033b..4f31350 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -DBSQL 0.4.0: (March 8, 2024) +DBSQL 0.4.0: (May 8, 2024) This is version 0.4.0 of DBSQL. diff --git a/dist/Makefile.in b/dist/Makefile.in index 0228192..0853a31 100644 --- a/dist/Makefile.in +++ b/dist/Makefile.in @@ -121,8 +121,8 @@ C_FILES=\ $(srcdir)/lemon/lempar.c $(srcdir)/os/os.c $(srcdir)/clib/random.c \ $(srcdir)/sql_fns.c $(srcdir)/sql_tokenize.c \ $(srcdir)/cg_vacuum.c $(srcdir)/vdbe.c $(srcdir)/vdbe_method.c \ - $(srcdir)/common/dbsql_err.c $(srcdir)/clib/snprintf.c \ - $(srcdir)/os/os_jtime.c $(srcdir)/clib/memcmp.c \ + $(srcdir)/common/dbsql_err.c (srcdir)/clib/snprintf.c \ + $(srcdir)/os/os_jtime.c $(srcdir)/os/os_sleep.c $(srcdir)/clib/memcmp.c \ $(srcdir)/clib/strcasecmp.c $(srcdir)/os/dbsql_alloc.c \ $(srcdir)/common/str.c $(srcdir)/common/dbsql_atoi.c \ $(srcdir)/common/dbsql_atof.c $(srcdir)/common/dbsql_fop.c \ @@ -138,7 +138,7 @@ C_OBJS= cg_attach@o@ cg_insert@o@ sql_tokenize@o@ cg_auth@o@ \ sql_fns@o@ random@o@ cg_update@o@ cg_delete@o@ hash@o@ \ cg_expr@o@ opcodes@o@ sql_parser@o@ cg_vacuum@o@ \ vdbe@o@ vdbe_method@o@ sm@o@ snprintf@o@ dbsql_err@o@ \ - dbsql_fop@o@ cg_select@o@ os_jtime@o@ memcmp@o@ \ + dbsql_fop@o@ cg_select@o@ os_sleep@o@ os_jtime@o@ memcmp@o@ \ dbsql_atof@o@ safety@o@ dbsql_atoi@o@ strcasecmp@o@ \ strdup@o@ dbsql_alloc@o@ str@o@ @@ -410,6 +410,8 @@ dbsql_alloc@o@: $(srcdir)/common/dbsql_alloc.c $(CC) $(CFLAGS) $? os_jtime@o@: $(srcdir)/os/os_jtime.c $(CC) $(CFLAGS) $? +os_sleep@o@: $(srcdir)/os/os_sleep.c + $(CC) $(CFLAGS) $? lemon@o@: $(srcdir)/lemon/lemon.c $(CC) $(CFLAGS) $? memcmp@o@: $(srcdir)/clib/memcmp.c diff --git a/dist/srcfiles.in b/dist/srcfiles.in index 20cd759..8155e3a 100644 --- a/dist/srcfiles.in +++ b/dist/srcfiles.in @@ -74,6 +74,7 @@ src/dbsql_tclsh.c app=dbsql_tclsh src/lemon/lemon.c app=lemon src/lemon/lempar.c app=lemon src/os/os_jtime.c dynamic static +src/os/os_sleep.c dynamic static src/safety.c dynamic static src/sm.c dynamic static src/sql_fns.c dynamic static diff --git a/src/api.c b/src/api.c index 84cc6e8..53c6d04 100644 --- a/src/api.c +++ b/src/api.c @@ -48,8 +48,7 @@ typedef struct { * * STATIC: static void __corrupt_schema __P((init_data_t *)); */ -static void __corrupt_schema(data) - init_data_t *data; +static void __corrupt_schema(init_data_t *data) { __str_append(data->err_msgs, "malformed database schema", (char*)0); @@ -72,11 +71,7 @@ static void __corrupt_schema(data) * STATIC: static int __init_callback __P((void *, int, char **, char **)); */ static int -__init_callback(init, argc, argv, col_name) - void *init; - int argc; - char **argv; - char **col_name; +__init_callback(void* init, int argc, char **argv, char **col_name) { init_data_t *data = (init_data_t*)init; parser_t parser; @@ -168,10 +163,7 @@ __init_callback(init, argc, argv, col_name) * STATIC: static int __init_db_file __P((DBSQL *, int, char **)); */ static int -__init_db_file(dbp, dbi, err_msgs) - DBSQL *dbp; - int dbi; - char **err_msgs; +__init_db_file(DBSQL* dbp, int dbi, char **err_msgs) { table_t *table; char *args[6]; @@ -306,9 +298,7 @@ __init_db_file(dbp, dbi, err_msgs) * PUBLIC: int __init_databases __P((DBSQL *, char**)); */ int -__init_databases(dbp, err_msgs) - DBSQL *dbp; - char **err_msgs; +__init_databases(DBSQL* dbp, char **err_msgs) { int i = 0; int rc = DBSQL_SUCCESS; @@ -464,8 +454,7 @@ __api_open(dbp, filename, mode, err_msgs) * STATIC: static int __api_last_inserted_rowid __P((DBSQL *)); */ int -__api_last_inserted_rowid(dbp) - DBSQL *dbp; +__api_last_inserted_rowid(DBSQL* dbp) { return dbp->lastRowid; } @@ -477,8 +466,7 @@ __api_last_inserted_rowid(dbp) * STATIC: static int __api_last_change_count __P((DBSQL *)); */ int -__api_last_change_count(dbp) - DBSQL *dbp; +__api_last_change_count(DBSQL* dbp) { return dbp->_num_last_changes; } @@ -491,8 +479,7 @@ __api_last_change_count(dbp) * STATIC: static int __api_total_change_count __P((DBSQL *)); */ int -__api_total_change_count(dbp) - DBSQL *dbp; +__api_total_change_count(DBSQL* dbp) { return dbp->_num_total_changes; } @@ -504,8 +491,7 @@ __api_total_change_count(dbp) * STATIC: static int __api_close __P((DBSQL *)); */ int -__api_close(dbp) - DBSQL *dbp; +__api_close(DBSQL* dbp) { hash_ele_t *i; int j; @@ -563,14 +549,7 @@ __api_close(dbp) * err_msgs OUT: Write error messages here */ static int -__process_sql(dbp, sql, callback, arg, tail, vm, err_msgs) - DBSQL *dbp; - const char *sql; - dbsql_callback callback; - void *arg; - const char **tail; - dbsql_stmt_t **vm; - char **err_msgs; +__process_sql(DBSQL *dbp, const char *sql, dbsql_callback callback, void *arg, const char **tail, dbsql_stmt_t **vm, char **err_msgs) { parser_t parser; @@ -672,12 +651,7 @@ __process_sql(dbp, sql, callback, arg, tail, vm, err_msgs) * arg First argument to callback() * err_msgs Write error messages here */ -int __api_exec(dbp, sql, callback, arg, err_msgs) - DBSQL *dbp; - const char *sql; - dbsql_callback callback; - void *arg; - char **err_msgs; +int __api_exec(DBSQL *dbp, const char *sql, dbsql_callback callback, void *arg, char **err_msgs) { return __process_sql(dbp, sql, callback, arg, 0, 0, err_msgs); } @@ -697,12 +671,7 @@ int __api_exec(dbp, sql, callback, arg, err_msgs) * err_msgs OUT: Write error messages here */ int -__api_prepare(dbp, sql, tail, stmt, err_msgs) - DBSQL *dbp; - const char *sql; - const char **tail; - dbsql_stmt_t **stmt; - char **err_msgs; +__api_prepare(DBSQL *dbp, const char *sql, const char **tail, dbsql_stmt_t **stmt, char **err_msgs) { return __process_sql(dbp, sql, 0, 0, tail, stmt, err_msgs); } @@ -728,9 +697,7 @@ __api_prepare(dbp, sql, tail, stmt, err_msgs) * with it. */ int -__api_finalize(stmt, err_msgs) - dbsql_stmt_t *stmt; - char **err_msgs; +__api_finalize(dbsql_stmt_t* stmt, char **err_msgs) { int rc = __vdbe_finalize((vdbe_t*)stmt, err_msgs); __str_urealloc(err_msgs); @@ -753,9 +720,7 @@ __api_finalize(stmt, err_msgs) * is returned. */ int -__api_reset(stmt, err_msgs) - dbsql_stmt_t *stmt; - char **err_msgs; +__api_reset(dbsql_stmt_t* stmt, char **err_msgs) { int rc = __vdbe_reset((vdbe_t*)stmt, err_msgs); __vdbe_make_ready((vdbe_t*)stmt, -1, 0, 0, 0); @@ -778,11 +743,7 @@ __api_reset(stmt, err_msgs) * count Number of times table has been busy */ static int -__default_busy_callback(dbp, arg, not_used, count) - DBSQL *dbp; - void *arg; - const char *not_used; - int count; +__default_busy_callback(DBSQL *dbp, void *arg, const char *not_used, int count) { #if defined(__LP64) || defined(__LP64__) u_int64_t timeout = (u_int64_t)arg; @@ -809,13 +770,13 @@ __default_busy_callback(dbp, arg, not_used, count) if (delay <= 0) return 0; } -/* __os_sleep(dbp, 0, delay); FIXME */ + __os_sleep(0, delay); return 1; #else if ((count + 1) * 1000 > timeout) { return 0; } -/* __os_sleep(dbp, 1, 0); FIXME */ + __os_sleep(1, 0); return 1; #endif } @@ -829,10 +790,7 @@ __default_busy_callback(dbp, arg, not_used, count) * STATIC: int (*)(DBSQL *, void*, const char*, int), void *)); */ void -__api_set_busy_callback(dbp, busy, arg) - DBSQL *dbp; - int (*busy)(DBSQL *, void *, const char*, int); - void *arg; +__api_set_busy_callback(DBSQL *dbp, int (*busy)(DBSQL *, void *, const char*, int), void *arg) { dbp->xBusyCallback = busy; dbp->pBusyArg = arg; @@ -849,11 +807,7 @@ __api_set_busy_callback(dbp, busy, arg) * STATIC: int (*)(void*), void *)); */ void -__api_set_progress_callback(dbp, num_ops, progress, arg) - DBSQL *dbp; - int num_ops; - int (*progress)(void*); - void *arg; +__api_set_progress_callback(DBSQL* dbp, int num_ops, int (*progress)(void*), void* arg) { if (num_ops > 0) { dbp->xProgress = progress; @@ -876,9 +830,7 @@ __api_set_progress_callback(dbp, num_ops, progress, arg) * STATIC: static void __api_set_busy_timeout __P((DBSQL *, int)); */ void -__api_set_busy_timeout(dbp, ms) - DBSQL *dbp; - int ms; +__api_set_busy_timeout(DBSQL* dbp, int ms) { #if defined(__LP64) || defined(__LP64__) u_int64_t delay = ms; @@ -899,8 +851,7 @@ __api_set_busy_timeout(dbp, ms) * PUBLIC: void __api_interrupt __P((DBSQL *)); */ void -__api_interrupt(dbp) - DBSQL *dbp; +__api_interrupt(DBSQL* dbp) { dbp->flags |= DBSQL_Interrupt; } @@ -912,10 +863,7 @@ __api_interrupt(dbp) * EXTERN: const char *dbsql_version __P((int *, int *, int *)); */ const char * -dbsql_version(major, minor, patch) - int *major; - int *minor; - int *patch; +dbsql_version(int* major, int* minor, int* patch) { *major = DBSQL_VERSION_MAJOR; *minor = DBSQL_VERSION_MINOR; @@ -950,7 +898,7 @@ __api_get_encoding() * of arguments, including 0. * * STATIC: static int __api_create_function __P((DBSQL *, const char *, int, - * STATIC: void *, int, + * STATIC: int, void *, * STATIC: void (*)(dbsql_func_t *, int, const char**), * STATIC: void (*)(dbsql_func_t *, int, const char**), * STATIC: void (*)(dbsql_func_t *))); @@ -959,22 +907,13 @@ __api_get_encoding() * name Name of the function to add * num_arg Number of arguments * encoding The encoding expected by the functions - * user_data User data + * user_data User data * func The function's implementation * step Step is used by aggregate functions - * finalize When finished with + * finalize When finished with an aggregate function */ int -__api_create_function(dbp, name, num_arg, user_data, encoding, func, - step, finalize) - DBSQL *dbp; - const char *name; - int num_arg; - void *user_data; - int encoding;/*TODO: not yet used*/ - void (*func)(dbsql_func_t*, int, const char**); - void (*step)(dbsql_func_t*, int, const char**); - void (*finalize)(dbsql_func_t*); +__api_create_function(DBSQL *dbp, const char *name, int encoding, int num_arg, void *user_data, /*TODO: not yet used*/ void (*func)(dbsql_func_t*, int, const char**), void (*step)(dbsql_func_t*, int, const char**), void (*finalize)(dbsql_func_t*)) { func_def_t *p; int name_len; @@ -1023,13 +962,8 @@ static int __api_exec_printf(DBSQL *dbp, const char *fmt, dbsql_callback callback, void *arg, char **err_msgs, ...) #else -__api_exec_printf(dbp, fmt, callback, arg, err_msgs, ...) - DBSQL *dbp; - const char *fmt; - dbsql_callback callback; - void *arg; - char **err_msgs; - va_dcl +__api_exec_printf(DBSQL *dbp, const char *fmt, dbsql_callback callback, + void *arg, char **err_msgs, va_dcl) #endif { va_list ap; @@ -1055,13 +989,7 @@ __api_exec_printf(dbp, fmt, callback, arg, err_msgs, ...) * va_list Args list */ static int -__api_exec_vprintf(dbp, fmt, callback, arg, err_msgs, ap) - DBSQL *dbp; - const char *fmt; - dbsql_callback callback; - void *arg; - char **err_msgs; - va_list ap; +__api_exec_vprintf(DBSQL *dbp, const char *fmt, dbsql_callback callback, void *arg, char **err_msgs, va_list ap) { char *sql; int rc; @@ -1092,14 +1020,7 @@ static int __api_exec_table_printf(DBSQL *dbp, const char *fmt, char ***results, int *num_rows, int *num_cols, char **err_msgs, ...) #else -__api_exec_printf(dbp, fmt, results, num_rows, num_cols, err_msgs, ...) - DBSQL *dbp; - const char *fmt; - char ***results; - int *num_rows; - int *num_cols; - char **err_msgs; - va_dcl +__api_exec_printf(DBSQL *dbp, const char *fmt, char ***results, int *num_rows, int *num_cols, char **err_msgs, va_dcl) #endif { va_list ap; @@ -1127,14 +1048,7 @@ __api_exec_printf(dbp, fmt, results, num_rows, num_cols, err_msgs, ...) * ap Arguments to the format string */ static int -__api_exec_table_vprintf(dbp, fmt, results, num_rows, num_cols, err_msgs, ap) - DBSQL *dbp; - const char *fmt; - char ***results; - int *num_rows; - int *num_cols; - char **err_msgs; - va_list ap; +__api_exec_table_vprintf(DBSQL *dbp, const char *fmt, char ***results, int *num_rows, int *num_cols, char **err_msgs, va_list ap) { char *sql; int rc; @@ -1154,10 +1068,7 @@ __api_exec_table_vprintf(dbp, fmt, results, num_rows, num_cols, err_msgs, ap) * STATIC: static int __api_func_return_type __P((DBSQL *, const char *, int)); */ int -__api_func_return_type(dbp, name, data_type) - DBSQL *dbp; - const char *name; - int data_type; +__api_func_return_type(DBSQL *dbp, const char *name, int data_type) { func_def_t *p = (func_def_t*)__hash_find((hash_t*)dbp->fns, name, strlen(name)); @@ -1180,10 +1091,7 @@ __api_func_return_type(dbp, name, data_type) * STATIC: void (*trace)(void*, const char *), void *)); */ void * -__api_set_trace_callback(dbp, trace, arg) - DBSQL *dbp; - void (*trace)(void*,const char*); - void *arg; +__api_set_trace_callback(DBSQL *dbp, void (*trace)(void*,const char*), void *arg) { void *old = dbp->pTraceArg; dbp->xTrace = trace; @@ -1205,10 +1113,7 @@ __api_set_trace_callback(dbp, trace, arg) * arg Argument to the function */ void * -__api_set_commit_callback(dbp, callback, arg) - DBSQL *dbp; - int (*callback)(void*); - void *arg; +__api_set_commit_callback(DBSQL* dbp, int (*callback)(void*), void* arg) { void *old = dbp->pCommitArg; dbp->xCommitCallback = callback; @@ -1222,8 +1127,7 @@ __api_set_commit_callback(dbp, callback, arg) * STATIC: static DB_ENV *__api_get_dbenv __P((DBSQL *)); */ static DB_ENV * -__api_get_dbenv(dbp) - DBSQL *dbp; +__api_get_dbenv(DBSQL* dbp) { return dbp->dbenv; } @@ -1239,9 +1143,7 @@ __api_get_dbenv(dbp) * callback Function to invoke on each commit */ void -__api_set_errcall(dbp, callback) - DBSQL *dbp; - void (*callback)(const char *, char *); +__api_set_errcall(DBSQL *dbp, void (*callback)(const char *, char *)) { dbp->dbsql_errcall = callback; } @@ -1256,9 +1158,7 @@ __api_set_errcall(dbp, callback) * file Open file stream for suitable for writing */ void -__api_set_errfile(dbp, file) - DBSQL *dbp; - FILE *file; +__api_set_errfile(DBSQL* dbp, FILE* file) { dbp->dbsql_errfile = file; } @@ -1273,16 +1173,14 @@ __api_set_errfile(dbp, file) * file OUT: The file used for error messages */ void -__api_get_errfile(dbp, file) - DBSQL *dbp; - FILE **file; +__api_get_errfile(DBSQL* dbp, FILE **file) { *file = dbp->dbsql_errfile; } /* * __api_set_errpfx -- - * Set a prefix for use when writting error messages. + * Set a prefix for use when writing error messages. * * STATIC: static void __api_set_errpfx __P((DBSQL *, const char *)); * @@ -1290,9 +1188,7 @@ __api_get_errfile(dbp, file) * prefix A prefix string */ void -__api_set_errpfx(dbp, prefix) - DBSQL *dbp; - const char *prefix; +__api_set_errpfx(DBSQL *dbp, const char *prefix) { __dbsql_strdup(dbp, prefix, &dbp->dbsql_errpfx); } @@ -1307,9 +1203,7 @@ __api_set_errpfx(dbp, prefix) * prefix OUT: The prefix string */ void -__api_get_errpfx(dbp, prefix) - DBSQL *dbp; - const char **prefix; +__api_get_errpfx(DBSQL *dbp, const char **prefix) { *prefix = dbp->dbsql_errpfx; } @@ -1322,12 +1216,7 @@ __api_get_errpfx(dbp, prefix) * EXTERN: const char *, int, u_int32_t flags)); */ int -dbsql_create_env(dbpp, dir, crypt, mode, flags) - DBSQL **dbpp; - const char *dir; - const char *crypt; - int mode; - u_int32_t flags; +dbsql_create_env(DBSQL **dbpp, const char *dir, const char *crypt, int mode, u_int32_t flags) { int rc; DB_ENV *dbenv; @@ -1422,10 +1311,7 @@ dbsql_create_env(dbpp, dir, crypt, mode, flags) * EXTERN: int dbsql_create __P((DBSQL **, DB_ENV *, u_int32_t)); */ int -dbsql_create(dbpp, dbenv, flags) - DBSQL **dbpp; - DB_ENV *dbenv; - u_int32_t flags; +dbsql_create(DBSQL **dbpp, DB_ENV* dbenv, u_int32_t flags) { DBSQL *dbp; DBSQL_ASSERT(dbpp != 0); @@ -1435,7 +1321,6 @@ dbsql_create(dbpp, dbenv, flags) /* * Does the library expect data to be encoded as UTF-8 - * or iso8859? The following global constant always * lets us know. * TODO: Make this configurable as a flag and part of the meta * database. diff --git a/src/api_table.c b/src/api_table.c index bd789f3..8e0b24c 100644 --- a/src/api_table.c +++ b/src/api_table.c @@ -59,11 +59,7 @@ typedef struct table_result { * STATIC: static int __get_table_cb __P((void *, int, char **, char **)); */ static int -__get_table_cb(arg, ncol, argv, colv) - void *arg; - int ncol; - char **argv; - char **colv; +__get_table_cb(void* arg, int ncol, char* *argv, char* *colv) { int rc; table_result_t *p = (table_result_t*)arg; @@ -248,8 +244,7 @@ __api_get_table(dbp, sql, results, nrows, ncols, err_msgs) * result Result returned from from __api_get_table() */ void -__api_free_table(results) - char **results; +__api_free_table(char* *results) { char *last_result; diff --git a/src/cg_attach.c b/src/cg_attach.c index 3db449f..7d51d9c 100644 --- a/src/cg_attach.c +++ b/src/cg_attach.c @@ -38,10 +38,7 @@ * PUBLIC: void __attach __P((parser_t *, token_t *, token_t *)); */ void -__attach(parser, file, db) - parser_t *parser; - token_t *file; - token_t *db; +__attach(parser_t* parser, token_t* file, token_t* db) { int rc, i; dbsql_db_t *new; @@ -136,9 +133,7 @@ __attach(parser, file, db) * PUBLIC: void __detach __P((parser_t *, token_t *)); */ void -__detach(parser, db) - parser_t *parser; - token_t *db; +__detach(parser_t* parser, token_t* db) { int i; DBSQL *dbp; @@ -285,9 +280,7 @@ int __ref_normalize_src_list(normctx, src_list) * database */ int -__ref_normalize_select(normctx, select) - ref_normalizer_ctx_t *normctx; - select_t *select; +__ref_normalize_select(ref_normalizer_ctx_t* normctx, select_t* select) { while (select) { if (__ref_normalize_expr_list(normctx, select->pEList)) { @@ -346,9 +339,7 @@ int __ref_normalize_expr(normctx, expr) * expr The expression to be fixed to one database */ int -__ref_normalize_expr_list(normctx, list) - ref_normalizer_ctx_t *normctx; - expr_list_t *list; +__ref_normalize_expr_list(ref_normalizer_ctx_t* normctx, expr_list_t* list) { int i; if (list == 0) diff --git a/src/cg_auth.c b/src/cg_auth.c index 0dd9069..ed26daf 100644 --- a/src/cg_auth.c +++ b/src/cg_auth.c @@ -97,9 +97,7 @@ int __api_set_authorizer(dbp, auth, arg) * STATIC: static void __auth_bad_return_code __P((parser_t *, int)); */ static void -__auth_bad_return_code(parser, rc) - parser_t *parser; - int rc; +__auth_bad_return_code(parser_t* parser, int rc) { char buf[20]; sprintf(buf, "(%d)", rc); @@ -128,10 +126,7 @@ __auth_bad_return_code(parser, rc) * tab_list All table that expr might refer to */ void -__auth_read(parser, expr, tab_list) - parser_t *parser; - expr_t *expr; - src_list_t *tab_list; +__auth_read(parser_t* parser, expr_t* expr, src_list_t* tab_list) { int rc; DBSQL *dbp = parser->db; @@ -262,8 +257,7 @@ void __auth_context_push(parser, authctx, context) * PUBLIC: void __auth_context_pop __P((auth_context_t *)); */ void -__auth_context_pop(authctx) - auth_context_t *authctx; +__auth_context_pop(auth_context_t* authctx) { if (authctx->pParse) { authctx->pParse->zAuthContext = authctx->zAuthContext; diff --git a/src/cg_build.c b/src/cg_build.c index 69bbacb..1d7bb7f 100644 --- a/src/cg_build.c +++ b/src/cg_build.c @@ -54,9 +54,7 @@ * PUBLIC: void __parse_begin __P((parser_t *, int)); */ void -__parse_begin(parser, explain_flag) - parser_t *parser; - int explain_flag; +__parse_begin(parser_t* parser, int explain_flag) { DBSQL *dbp = parser->db; int i; @@ -88,11 +86,7 @@ __parse_begin(parser, explain_flag) * STATIC: static int __null_callback __P((void *, int , char **, char **)); */ static int -__null_callback(not_used, n, a, b) - void *not_used; - int n; - char **a; - char **b; +__null_callback(void* not_used, int n, char* *a, char* *b) { return 0; } @@ -110,8 +104,7 @@ __null_callback(not_used, n, a, b) * PUBLIC: void __parse_exec __P((parser_t *)); */ void -__parse_exec(parser) - parser_t *parser; +__parse_exec(parser_t* parser) { int rc = DBSQL_SUCCESS; DBSQL *dbp = parser->db; @@ -280,9 +273,7 @@ __find_index(dbp, name, database) * STATIC: static void __delete_index __P((DBSQL *, index_t *)); */ static void -__delete_index(dbp, index) - DBSQL *dbp; - index_t *index; +__delete_index(DBSQL* dbp, index_t* index) { index_t *old; @@ -305,9 +296,7 @@ __delete_index(dbp, index) * PUBLIC: void __unlink_and_delete_index __P((DBSQL *, index_t *)); */ void -__unlink_and_delete_index(dbp, index) - DBSQL *dbp; - index_t *index; +__unlink_and_delete_index(DBSQL* dbp, index_t* index) { if (index->pTable->pIndex == index) { index->pTable->pIndex = index->pNext; @@ -336,9 +325,7 @@ __unlink_and_delete_index(dbp, index) * PUBLIC: void __reset_internal_schema __P((DBSQL *, int)); */ void -__reset_internal_schema(dbp, idb) - DBSQL *dbp; - int idb; +__reset_internal_schema(DBSQL* dbp, int idb) { hash_ele_t *ele; hash_t temp1; @@ -404,8 +391,7 @@ __reset_internal_schema(dbp, idb) * PUBLIC: void __rollback_internal_changes __P((DBSQL *)); */ void -__rollback_internal_changes(dbp) - DBSQL *dbp; +__rollback_internal_changes(DBSQL* dbp) { if (dbp->flags & DBSQL_InternChanges) { __reset_internal_schema(dbp, 0); @@ -419,8 +405,7 @@ __rollback_internal_changes(dbp) * PUBLIC: void __commit_internal_changes __P((DBSQL *)); */ void -__commit_internal_changes(dbp) - DBSQL *dbp; +__commit_internal_changes(DBSQL* dbp) { dbp->aDb[0].schema_sig = dbp->next_sig; dbp->flags &= ~DBSQL_InternChanges; @@ -443,9 +428,7 @@ __commit_internal_changes(dbp) * PUBLIC: void __vdbe_delete_table __P((DBSQL *, table_t *)); */ void -__vdbe_delete_table(dbp, table) - DBSQL *dbp; - table_t *table; +__vdbe_delete_table(DBSQL* dbp, table_t* table) { int i; index_t *index, *next; @@ -498,9 +481,7 @@ __vdbe_delete_table(dbp, table) * STATIC: static void __unlink_and_delete_table __P((DBSQL, table_t *)); */ static void -__unlink_and_delete_table(dbp, table) - DBSQL *dbp; - table_t *table; +__unlink_and_delete_table(DBSQL* dbp, table_t* table) { table_t *old; foreign_key_t *f1, *f2; @@ -536,8 +517,7 @@ __unlink_and_delete_table(dbp, table) * PUBLIC: char *__table_name_from_token __P((token_t *)); */ char * -__table_name_from_token(name) - token_t *name; +__table_name_from_token(token_t* name) { char *n; __dbsql_strndup(NULL, name->z, &n, name->n); @@ -742,9 +722,7 @@ void __start_table(parser, start, name, temp, view) * PUBLIC: void __add_column __P((parser_t *, token_t *)); */ void -__add_column(parser, name) - parser_t *parser; - token_t *name; +__add_column(parser_t* parser, token_t* name) { table_t *table; int i; @@ -789,9 +767,7 @@ __add_column(parser, name) * PUBLIC: void __add_not_null __P((parser_t *, int)); */ void -__add_not_null(parser, on_error) - parser_t *parser; - int on_error; +__add_not_null(parser_t* parser, int on_error) { table_t *table; int i; @@ -815,10 +791,7 @@ __add_not_null(parser, on_error) * PUBLIC: void __add_column_type __P((parser_t *, token_t *, token_t *)); */ void -__add_column_type(parser, first, last) - parser_t *parser; - token_t *first; - token_t *last; +__add_column_type(parser_t* parser, token_t* first, token_t* last) { table_t *table; int i, j; @@ -859,10 +832,7 @@ __add_column_type(parser, first, last) * PUBLIC: void __add_default_value __P((parser_t *, token_t *, int)); */ void -__add_default_value(parser, val, minus) - parser_t *parser; - token_t *val; - int minus; +__add_default_value(parser_t* parser, token_t* val, int minus) { table_t *table; int i; @@ -904,10 +874,7 @@ __add_default_value(parser, val, minus) * PUBLIC: void __add_primary_key __P((parser_t *, id_list_t *, int)); */ void -__add_primary_key(parser, list, on_error) - parser_t *parser; - id_list_t *list; - int on_error; +__add_primary_key(parser_t* parser, id_list_t* list, int on_error) { table_t *table = parser->pNewTable; char *type = 0; @@ -1013,9 +980,7 @@ __collate_type(type, ntype) * PUBLIC: void __add_collate_type __P((parser_t *, int)); */ void -__add_collate_type(parser, type) - parser_t *parser; - int type; +__add_collate_type(parser_t* parser, int type) { table_t *table; int i; @@ -1046,9 +1011,7 @@ __add_collate_type(parser, type) * PUBLIC: void __change_schema_signature __P((DBSQL *, vdbe_t *)); */ void -__change_schema_signature(dbp, v) - DBSQL *dbp; - vdbe_t *v; +__change_schema_signature(DBSQL* dbp, vdbe_t* v) { static struct drand48_data rand; static int first_time = 1; @@ -1097,10 +1060,7 @@ __ident_length(z) * STATIC: static void __ident_put __P((char *, int *, char *)); */ static void -__ident_put(z, idx, ident) - char *z; - int *idx; - char *ident; +__ident_put(char* z, int* idx, char* ident) { int i, j, need_quote; i = *idx; @@ -1133,8 +1093,7 @@ __ident_put(z, idx, ident) * STATIC: static char *__gen_create_table_stmt __P((table_t *)); */ static char * -__gen_create_table_stmt(table) - table_t *table; +__gen_create_table_stmt(table_t* table) { int i, k, n; char *stmt; @@ -1193,10 +1152,7 @@ __gen_create_table_stmt(table) * PUBLIC: select_t *)); */ void -__ending_create_table_paren(parser, end, select) - parser_t *parser; - token_t *end; - select_t *select; +__ending_create_table_paren(parser_t* parser, token_t* end, select_t* select) { table_t *table; DBSQL *dbp = parser->db; @@ -1412,9 +1368,7 @@ void __create_view(parser, begin, name, select, temp) * PUBLIC: int __view_get_column_names __P((parser_t *, table_t *)); */ int -__view_get_column_names(parser, table) - parser_t *parser; - table_t *table; +__view_get_column_names(parser_t* parser, table_t* table) { expr_list_t *elist; select_t *sel; @@ -1499,8 +1453,7 @@ __view_get_column_names(parser, table) * STATIC: static void __view_reset_column_names __P((table_t *)); */ static void -__view_reset_column_names(table) - table_t *table; +__view_reset_column_names(table_t* table) { int i; if (table == 0 || table->pSelect==0 ) return; @@ -1523,9 +1476,7 @@ __view_reset_column_names(table) * STATIC: static void __view_reset_all __P((DBSQL *, int)); */ static void -__view_reset_all(dbp, idx) - DBSQL *dbp; - int idx; +__view_reset_all(DBSQL* dbp, int idx) { hash_ele_t *i; if (!DB_PROPERTY_HAS_VALUE(dbp, idx, DBSQL_UNRESET_VIEWS)) @@ -1548,9 +1499,7 @@ __view_reset_all(dbp, idx) * PUBLIC: table_t *__table_from_token __P((parser_t *, token_t *)); */ table_t * -__table_from_token(parser, token) - parser_t *parser; - token_t *token; +__table_from_token(parser_t* parser, token_t* token) { char *name; table_t *table; @@ -1577,10 +1526,7 @@ __table_from_token(parser, token) * PUBLIC: void __drop_table __P((parser_t *, token_t *name, int)); */ void -__drop_table(parser, name, view) - parser_t *parser; - token_t *name; - int view; +__drop_table(parser_t* parser, token_t* name, int view) { table_t *table; vdbe_t *v; @@ -1742,9 +1688,7 @@ __drop_table(parser, name, view) * PUBLIC: void __add_idx_key_type __P((vdbe_t *, index_t *)); */ void -__add_idx_key_type(v, idx) - vdbe_t *v; - index_t *idx; +__add_idx_key_type(vdbe_t* v, index_t* idx) { char *type; table_t *table; @@ -1918,9 +1862,7 @@ void __create_foreign_key(parser, from_col, to, to_col, flags) * PUBLIC: void __defer_foreign_key __P((parser_t *, int)); */ void -__defer_foreign_key(parser, deferred) - parser_t *parser; - int deferred; +__defer_foreign_key(parser_t* parser, int deferred) { table_t *table; foreign_key_t *fkey; @@ -1956,14 +1898,7 @@ __defer_foreign_key(parser, deferred) * end The ")" that closes the CREATE INDEX statement. */ void -__create_index(parser, token, sltable, list, on_error, start, end) - parser_t *parser; - token_t *token; - src_list_t *sltable; - id_list_t *list; - int on_error; - token_t *start; - token_t *end; +__create_index(parser_t* parser, token_t* token, src_list_t* sltable, id_list_t* list, int on_error, token_t* start, token_t* end) { table_t *table; /* Table to be indexed */ index_t *index; /* The index to be created */ @@ -2286,9 +2221,7 @@ exit_create_index: * PUBLIC: void __drop_index __P((parser_t *, src_list_t *)); */ void -__drop_index(parser, name) - parser_t *parser; - src_list_t *name; +__drop_index(parser_t* parser, src_list_t* name) { index_t *index; vdbe_t *v; @@ -2383,9 +2316,7 @@ __drop_index(parser, name) * PUBLIC: id_list_t *__id_list_append __P((id_list_t *, token_t *)); */ id_list_t * -__id_list_append(list, token) - id_list_t *list; - token_t *token; +__id_list_append(id_list_t* list, token_t* token) { if (list == 0) { if (__dbsql_calloc(NULL, 1, sizeof(id_list_t), &list) ==ENOMEM) @@ -2440,10 +2371,7 @@ __id_list_append(list, token) * PUBLIC: token_t *)); */ src_list_t * -__src_list_append(list, table, database) - src_list_t *list; - token_t *table; - token_t *database; +__src_list_append(src_list_t* list, token_t* table, token_t* database) { if (list == 0) { if (__dbsql_calloc(NULL, 1, sizeof(src_list_t), &list)==ENOMEM) @@ -2499,9 +2427,7 @@ __src_list_append(list, table, database) * PUBLIC: void __src_list_assign_cursors __P((parser_t *, src_list_t *)); */ void -__src_list_assign_cursors(parser, list) - parser_t *parser; - src_list_t *list; +__src_list_assign_cursors(parser_t* parser, src_list_t* list) { int i; for (i = 0; i < list->nSrc; i++) { @@ -2518,9 +2444,7 @@ __src_list_assign_cursors(parser, list) * PUBLIC: void __src_list_add_alias __P((src_list_t *, token_t *)); */ void -__src_list_add_alias(list, token) - src_list_t *list; - token_t *token; +__src_list_add_alias(src_list_t* list, token_t* token) { if (list && list->nSrc > 0) { int i = list->nSrc - 1; @@ -2537,8 +2461,7 @@ __src_list_add_alias(list, token) * PUBLIC: void __id_list_delete __P((id_list_t *)); */ void -__id_list_delete(list) - id_list_t *list; +__id_list_delete(id_list_t* list) { int i; if (list == 0) @@ -2579,8 +2502,7 @@ __id_list_index(list, name) * PUBLIC: void __src_list_delete __P((src_list_t *)); */ void -__src_list_delete(list) - src_list_t *list; +__src_list_delete(src_list_t* list) { int i; if (list == 0) @@ -2606,9 +2528,7 @@ __src_list_delete(list) * PUBLIC: void __dbsql_txn_begin __P((parser_t *, int)); */ void -__dbsql_txn_begin(parser, on_error) - parser_t *parser; - int on_error; +__dbsql_txn_begin(parser_t* parser, int on_error) { DBSQL *dbp; @@ -2638,8 +2558,7 @@ __dbsql_txn_begin(parser, on_error) * PUBLIC: void __dbsql_txn_commit __P((parser_t *)); */ void -__dbsql_txn_commit(parser) - parser_t *parser; +__dbsql_txn_commit(parser_t* parser) { DBSQL *dbp; @@ -2669,8 +2588,7 @@ __dbsql_txn_commit(parser) * PUBLIC: void __dbsql_txn_abort __P((parser_t *)); */ void -__dbsql_txn_abort(parser) - parser_t *parser; +__dbsql_txn_abort(parser_t* parser) { DBSQL *dbp; vdbe_t *v; @@ -2742,10 +2660,7 @@ void __code_verify_schema(parser, idb) * PUBLIC: void __vdbe_prepare_write __P((parser_t*, int, int)); */ void -__vdbe_prepare_write(parser, checkpoint, idb) - parser_t *parser; - int checkpoint; - int idb; +__vdbe_prepare_write(parser_t* parser, int checkpoint, int idb) { vdbe_t *v; DBSQL *dbp = parser->db; @@ -2780,8 +2695,7 @@ __vdbe_prepare_write(parser, checkpoint, idb) * PUBLIC: void __vdbe_conclude_write __P((parser_t *)); */ void -__vdbe_conclude_write(parser) - parser_t *parser; +__vdbe_conclude_write(parser_t* parser) { vdbe_t *v; DBSQL *dbp = parser->db; diff --git a/src/cg_date.c b/src/cg_date.c index 2b0623f..6d1c2c9 100644 --- a/src/cg_date.c +++ b/src/cg_date.c @@ -270,8 +270,7 @@ __parse_hh_mm_ss(date, dt) * STATIC: static void compute_jd __P((datetime_t *)); */ static void -__compute_jd(dt) - datetime_t *dt; +__compute_jd(datetime_t* dt) { int Y, M, D, A, B, X1, X2; @@ -371,7 +370,7 @@ __parse_yyyy_mm_dd(date, dt) * The following are acceptable forms for the input string: * * YYYY-MM-DD HH:MM:SS.FFF +/-HH:MM - * DDDD.DD + * DDDD.DD * now * * In the first form, the +/-HH:MM is always optional. The fractional @@ -420,8 +419,7 @@ __parse_date_or_time(date, dt) * STATIC: static void __compute_ymd __P((datetime_t *)); */ static void -__compute_ymd(dt) - datetime_t *dt; +__compute_ymd(datetime_t* dt) { int Z, A, B, C, D, E, X1; if (dt->validYMD) @@ -447,8 +445,7 @@ __compute_ymd(dt) * STATIC: static void __compute_hms __P((datetime_t *)); */ static void -__compute_hms(dt) - datetime_t *dt; +__compute_hms(datetime_t* dt) { int Z, s; if (dt->validHMS) @@ -472,8 +469,7 @@ __compute_hms(dt) * STATIC: static void __compute_ymd_hms __P((datetime_t *)); */ static void -__compute_ymd_hms(dt) - datetime_t *dt; +__compute_ymd_hms(datetime_t* dt) { __compute_ymd(dt); __compute_hms(dt); @@ -486,8 +482,7 @@ __compute_ymd_hms(dt) * STATIC: static void __clear_ymd_hms_tz __P((datetime_t *)); */ static void -__clear_ymd_hms_tz(dt) - datetime_t *dt; +__clear_ymd_hms_tz(datetime_t* dt) { dt->validYMD = 0; dt->validHMS = 0; @@ -502,8 +497,7 @@ __clear_ymd_hms_tz(dt) * STATIC: static double __localtime_offset __P((datetime_t *)); */ static double -__localtime_offset(dt) - datetime_t *dt; +__localtime_offset(datetime_t* dt) { datetime_t x, y; time_t t; @@ -1020,8 +1014,7 @@ __strftime_sql_func(context, argc, argv) * PUBLIC: void __register_datetime_funcs __P((DBSQL *)); */ void -__register_datetime_funcs(dbp) - DBSQL *dbp; +__register_datetime_funcs(DBSQL* dbp) { static struct { char *name; @@ -1040,8 +1033,8 @@ __register_datetime_funcs(dbp) int i; for (i = 0; i < sizeof(funcs) / sizeof(funcs[0]); i++) { - dbp->create_function(dbp, funcs[i].name, funcs[i].args, - DBSQL_UTF8_ENCODED, NULL, funcs[i].func, + dbp->create_function(dbp, funcs[i].name, DBSQL_UTF8_ENCODED, + funcs[i].args, NULL, funcs[i].func, NULL, NULL); if (funcs[i].func) { dbp->func_return_type(dbp, funcs[i].name, diff --git a/src/cg_delete.c b/src/cg_delete.c index 35a99e6..149a321 100644 --- a/src/cg_delete.c +++ b/src/cg_delete.c @@ -36,9 +36,7 @@ * PUBLIC: table_t *__src_list_lookup __P((parser_t *, src_list_t *)); */ table_t * -__src_list_lookup(parser, src) - parser_t *parser; - src_list_t *src; +__src_list_lookup(parser_t* parser, src_list_t* src) { table_t *table = 0; int i; @@ -60,10 +58,7 @@ __src_list_lookup(parser, src) * PUBLIC: int __is_table_read_only __P((parser_t *, table_t *, int)); */ int -__is_table_read_only(parser, table, views_ok) - parser_t *parser; - table_t *table; - int views_ok; +__is_table_read_only(parser_t* parser, table_t* table, int views_ok) { if (table->readOnly) { __error_msg(parser, "table %s may not be modified", diff --git a/src/cg_expr.c b/src/cg_expr.c index ba4da2f..9fb5a2c 100644 --- a/src/cg_expr.c +++ b/src/cg_expr.c @@ -40,11 +40,7 @@ * PUBLIC: expr_t *__expr __P((int, expr_t *, expr_t *, token_t *)); */ expr_t * -__expr(op, left, right, token) - int op; - expr_t *left; - expr_t *right; - token_t *token; +__expr(int op, expr_t* left, expr_t* right, token_t* token) { expr_t *new; if (__dbsql_calloc(NULL, 1, sizeof(expr_t), &new) == ENOMEM) { @@ -79,10 +75,7 @@ __expr(op, left, right, token) * PUBLIC: void __expr_span __P((expr_t *, token_t *, token_t *)); */ void -__expr_span(expr, left, right) - expr_t *expr; - token_t *left; - token_t *right; +__expr_span(expr_t* expr, token_t* left, token_t* right) { DBSQL_ASSERT(right != 0); DBSQL_ASSERT(left != 0); @@ -108,9 +101,7 @@ __expr_span(expr, left, right) * PUBLIC: expr_t *__expr_function __P((expr_list_t *, token_t *)); */ expr_t * -__expr_function(list, token) - expr_list_t *list; - token_t *token; +__expr_function(expr_list_t* list, token_t* token) { expr_t *new; if (__dbsql_calloc(NULL, 1, sizeof(expr_t), &new) == ENOMEM) { @@ -138,8 +129,7 @@ __expr_function(list, token) * PUBLIC: void __expr_delete __P((expr_t *)); */ void -__expr_delete(p) - expr_t *p; +__expr_delete(expr_t* p) { if (p == 0) return; @@ -169,8 +159,7 @@ __expr_delete(p) * PUBLIC: expr_t *__expr_dup __P((expr_t *)); */ expr_t * -__expr_dup(p) - expr_t *p; +__expr_dup(expr_t* p) { expr_t *new; if (p == 0) @@ -199,9 +188,7 @@ __expr_dup(p) * PUBLIC: void __token_copy __P((token_t *, token_t *)); */ void -__token_copy(to, from) - token_t *to; - token_t *from; +__token_copy(token_t* to, token_t* from) { if (to->dyn) __dbsql_free(NULL, (char*)to->z); @@ -221,8 +208,7 @@ __token_copy(to, from) * PUBLIC: expr_list_t *__expr_list_dup __P((expr_list_t *)); */ expr_list_t * -__expr_list_dup(p) - expr_list_t *p; +__expr_list_dup(expr_list_t* p) { expr_list_t *new; int i; @@ -266,8 +252,7 @@ __expr_list_dup(p) * PUBLIC: src_list_t *__src_list_dup __P((src_list_t *)); */ src_list_t * -__src_list_dup(p) - src_list_t *p; +__src_list_dup(src_list_t* p) { src_list_t *new; int i; @@ -302,8 +287,7 @@ __src_list_dup(p) * PUBLIC: id_list_t *__id_list_dup __P((id_list_t *)); */ id_list_t * -__id_list_dup(p) - id_list_t *p; +__id_list_dup(id_list_t* p) { id_list_t *new; int i; @@ -330,8 +314,7 @@ __id_list_dup(p) * PUBLIC: select_t *__select_dup __P((select_t *)); */ select_t * -__select_dup(p) - select_t *p; +__select_dup(select_t* p) { select_t *new; if (p == 0) @@ -365,10 +348,7 @@ __select_dup(p) * PUBLIC: token_t *)); */ expr_list_t * -__expr_list_append(list, expr, name) - expr_list_t *list; - expr_t *expr; - token_t *name; +__expr_list_append(expr_list_t* list, expr_t* expr, token_t* name) { if (list == 0) { if (__dbsql_calloc(NULL, 1, sizeof(expr_list_t), @@ -409,8 +389,7 @@ __expr_list_append(list, expr, name) * PUBLIC: void __expr_list_delete __P((expr_list_t *)); */ void -__expr_list_delete(list) - expr_list_t *list; +__expr_list_delete(expr_list_t* list) { int i; if (list == 0) @@ -434,8 +413,7 @@ __expr_list_delete(list) * PUBLIC: int __expr_is_constant __P((expr_t *)); */ int -__expr_is_constant(p) - expr_t *p; +__expr_is_constant(expr_t* p) { int rc = 0; @@ -494,9 +472,7 @@ __expr_is_constant(p) * PUBLIC: int __expr_is_integer __P((expr_t *, int *)); */ int -__expr_is_integer(p, value) - expr_t *p; - int *value; +__expr_is_integer(expr_t* p, int* value) { const char *z; int v, n; @@ -1072,11 +1048,7 @@ __get_function_name(expr, name, len) * PUBLIC: int __expr_check __P((parser_t *, expr_t *, int, int *)); */ int -__expr_check(parser, expr, agg_allowed, agg) - parser_t *parser; - expr_t *expr; - int agg_allowed; - int *agg; +__expr_check(parser_t* parser, expr_t* expr, int agg_allowed, int* agg) { int nerr, i, n, no_such_func, is_type_of, wrong_num_args, is_agg, nid; const char *id; @@ -1210,8 +1182,7 @@ __expr_check(parser, expr, agg_allowed, agg) * PUBLIC: int __expr_type __P((expr_t *)); */ int -__expr_type(p) - expr_t *p; +__expr_type(expr_t* p) { int i; expr_list_t *list; @@ -1304,9 +1275,7 @@ __expr_type(p) * PUBLIC: void __expr_code __P((parser_t *, expr_t *)); */ void -__expr_code(parser, expr) - parser_t *parser; - expr_t *expr; +__expr_code(parser_t* parser, expr_t* expr) { vdbe_t *v = parser->pVdbe; int i, op, dest, nexpr, nid, addr, expr_end_lable, jump_inst; @@ -1562,11 +1531,7 @@ __expr_code(parser, expr) * PUBILC: void __expr_if_true __P((parser_t *, expr_t *, int, int)); */ void -__expr_if_true(parser, expr, dest, jump_if_null) - parser_t *parser; - expr_t *expr; - int dest; - int jump_if_null; +__expr_if_true(parser_t* parser, expr_t* expr, int dest, int jump_if_null) { vdbe_t *v = parser->pVdbe; int d2, addr, op = 0; @@ -1657,11 +1622,7 @@ __expr_if_true(parser, expr, dest, jump_if_null) * PUBLIC: void __expr_if_false __P((parser_t *, expr_t *, int, int)); */ void -__expr_if_false(parser, expr, dest, jump_if_null) - parser_t *parser; - expr_t *expr; - int dest; - int jump_if_null; +__expr_if_false(parser_t* parser, expr_t* expr, int dest, int jump_if_null) { vdbe_t *v = parser->pVdbe; int addr, d2, op = 0; @@ -1759,9 +1720,7 @@ __expr_if_false(parser, expr, dest, jump_if_null) * PUBLIC: int __expr_compare __P((expr_t *, expr_t *)); */ int -__expr_compare(a, b) - expr_t *a; - expr_t *b; +__expr_compare(expr_t* a, expr_t* b) { int i; if (a == 0) { @@ -1813,8 +1772,7 @@ __expr_compare(a, b) * STATIC: static int __append_agg_info __P((parser_t *)); */ static int -__append_agg_info(parser) - parser_t *parser; +__append_agg_info(parser_t* parser) { agg_expr_t *agg; if ((parser->nAgg & 0x7) == 0) { @@ -1839,9 +1797,7 @@ __append_agg_info(parser) * PUBLIC: int __expr_analyze_aggregates __P((parser_t *, expr_t *)); */ int -__expr_analyze_aggregates(parser, expr) - parser_t *parser; - expr_t *expr; +__expr_analyze_aggregates(parser_t* parser, expr_t* expr) { int i, n, nexpr, nerr = 0; agg_expr_t *agg; diff --git a/src/cg_pragma.c b/src/cg_pragma.c index eecdc70..84fdf80 100644 --- a/src/cg_pragma.c +++ b/src/cg_pragma.c @@ -37,8 +37,7 @@ * STATIC: static int __get_boolean __P((char *)); */ static int -__get_boolean(z) - char *z; +__get_boolean(char* z) { static char *true[] = { "yes", "on", "true" }; int i; @@ -68,8 +67,7 @@ __get_boolean(z) * STATIC: static int __get_safety_level __P((char *)); */ static int -__get_safety_level(z) - char *z; +__get_safety_level(char* z) { static const struct { const char *word; @@ -111,11 +109,7 @@ __get_safety_level(z) * PUBLIC: void __pragma __P((parser_t *, token_t *, token_t *, int)); */ void -__pragma(parser, left, right, minus_p) - parser_t *parser; - token_t *left; - token_t *right; - int minus_p; +__pragma(parser_t* parser, token_t* left, token_t* right, int minus_p) { char *left_name = 0; char *right_name = 0; diff --git a/src/cg_select.c b/src/cg_select.c index fba0c78..3152fb6 100644 --- a/src/cg_select.c +++ b/src/cg_select.c @@ -106,11 +106,7 @@ __select_new(result_cols, from_clause, where_clause, groupby_clause, * PUBLIC: int __join_type __P((parser_t *, token_t *, token_t *, token_t *)); */ int -__join_type(parser, a, b, c) - parser_t *parser; - token_t *a; - token_t *b; - token_t *c; +__join_type(parser_t* parser, token_t* a, token_t* b, token_t* c) { int jointype = 0; token_t *ap_all[3]; @@ -256,8 +252,7 @@ __add_where_term(col, table1, table2, expr) * STATIC: static void __set_join_expr __P((expr_t *)); */ static void -__set_join_expr(p) - expr_t *p; +__set_join_expr(expr_t* p) { while (p) { ExprSetProperty(p, EP_FromJoin); @@ -277,9 +272,7 @@ __set_join_expr(p) * STATIC: static int __process_join __P((parser_t *, select_t *)); */ static int -__process_join(parser, select) - parser_t *parser; - select_t *select; +__process_join(parser_t* parser, select_t* select) { int i, j; src_list_t *src; @@ -380,8 +373,7 @@ __process_join(parser, select) * PUBLIC: void __select_delete __P((select_t *)); */ void -__select_delete(select) - select_t *select; +__select_delete(select_t* select) { if (select == 0) return; @@ -403,8 +395,7 @@ __select_delete(select) * STATIC: static void __aggregage_info_reset __P((parser_t *)); */ static void -__aggregate_info_reset(parser) - parser_t *parser; +__aggregate_info_reset(parser_t* parser) { __dbsql_free(parser->db, parser->aAgg); parser->aAgg = 0; @@ -421,10 +412,7 @@ __aggregate_info_reset(parser) * STATIC: expr_list_t *)); */ static void -__push_onto_sorter(parser, v, orderby_clause) - parser_t *parser; - vdbe_t *v; - expr_list_t *orderby_clause; +__push_onto_sorter(parser_t* parser, vdbe_t* v, expr_list_t* orderby_clause) { int i, order, type, c; char *sort_order; @@ -470,9 +458,7 @@ __push_onto_sorter(parser, v, orderby_clause) * PUBLIC: void __add_key_type __P((vdbe_t *, expr_list_t *)); */ void -__add_key_type(v, elist) - vdbe_t *v; - expr_list_t *elist; +__add_key_type(vdbe_t* v, expr_list_t* elist) { int i; int col = elist->nExpr; @@ -719,12 +705,7 @@ __select_inner_loop(parser, select, elist, src_table, num_cols, orderby_clause, * param Optional parameter associated with dest */ static void -__generate_sort_tail(select, v, num_cols, dest, param) - select_t *select; - vdbe_t *v; - int num_cols; - int dest; - int param; +__generate_sort_tail(select_t* select, vdbe_t* v, int num_cols, int dest, int param) { int i, addr; int end = __vdbe_make_label(v); @@ -803,10 +784,7 @@ __generate_sort_tail(select, v, num_cols, dest, param) * elist Expressions defining the result set */ static void -__generate_column_types(parser, tables, elist) - parser_t *parser; - src_list_t *tables; - expr_list_t *elist; +__generate_column_types(parser_t* parser, src_list_t* tables, expr_list_t* elist) { int i, j, col; expr_t *p; @@ -865,10 +843,7 @@ __generate_column_types(parser, tables, elist) * elist Expressions defining the result set */ static void -__generate_column_names(parser, tables, elist) - parser_t *parser; - src_list_t *tables; - expr_list_t *elist; +__generate_column_names(parser_t* parser, src_list_t* tables, expr_list_t* elist) { int i, j, show_full_names, icol, addr; char *type, *name, *col, *tab; @@ -948,8 +923,7 @@ __generate_column_names(parser, tables, elist) * STATIC: static const char *__select_op_name __P((int)); */ static const char * -__select_op_name(id) - int id; +__select_op_name(int id) { char *z; switch(id) { @@ -987,9 +961,7 @@ __select_op_name(id) * STATIC: static int __file_in_column_list __P((parser_t *, select_t *)); */ static int -__fill_in_column_list(parser, select) - parser_t *parser; - select_t *select; +__fill_in_column_list(parser_t* parser, select_t* select) { int i, j, k, rc; src_list_t *tables; @@ -1245,8 +1217,7 @@ __fill_in_column_list(parser, select) * PUBLIC: void __select_unbind __P((select_t *)); */ void -__select_unbind(select) - select_t *select; +__select_unbind(select_t* select) { int i; table_t *table; @@ -1388,8 +1359,7 @@ __match_orderby_to_column(parser, select, orderby_clause, table_idx, * PUBLIC: vdbe_t *__parser_get_vdbe __P((parser_t *)); */ vdbe_t * -__parser_get_vdbe(parser) - parser_t *parser; +__parser_get_vdbe(parser_t* parser) { vdbe_t *v = parser->pVdbe; if (v == 0) { @@ -1431,9 +1401,7 @@ __parser_get_vdbe(parser) * STATIC: expr_list_t *)); */ static void -__multi_select_sort_order(select, orderby_clause) - select_t *select; - expr_list_t *orderby_clause; +__multi_select_sort_order(select_t* select, expr_list_t* orderby_clause) { int i; expr_list_t *elist; @@ -1482,9 +1450,7 @@ __multi_select_sort_order(select, orderby_clause) * STATIC: static void __compute_limit_registers __P((parser_t *, select_t *)); */ static void -__compute_limit_registers(parser, select) - parser_t *parser; - select_t *select; +__compute_limit_registers(parser_t* parser, select_t* select) { int mem; vdbe_t *v; @@ -1553,11 +1519,7 @@ __compute_limit_registers(parser, select) * */ static int -__multi_select(parser, select, dest, param) - parser_t *parser; - select_t *select; - int dest; - int param; +__multi_select(parser_t* parser, select_t* select, int dest, int param) { int tab1, tab2; int cont, brk, start; @@ -1667,7 +1629,6 @@ __multi_select(parser, select, dest, param) rc = __select(parser, prior, prior_op, union_tab, 0, 0, 0); if (rc) return rc; - /* * Code the current SELECT statement. */ @@ -1690,7 +1651,6 @@ __multi_select(parser, select, dest, param) select->nOffset = offset; if (rc) return rc; - /* * Convert the data in the temporary table into whatever form * it is that we currently need. @@ -1751,7 +1711,6 @@ __multi_select(parser, select, dest, param) rc = __select(parser, prior, SRT_Union, tab1, 0, 0, 0); if (rc) return rc; - /* * Code the current SELECT into temporary table "tab2". */ @@ -1768,7 +1727,6 @@ __multi_select(parser, select, dest, param) select->nOffset = offset; if (rc) return rc; - /* * Generate code to take the intersection of the two temporary * tables. @@ -1841,10 +1799,7 @@ static void __subst_expr_list(expr_list_t*,int,expr_list_t*); * STATIC: static void __subst_expr __P((expr_t *, int, expr_list_t *)); */ static void -__subst_expr(expr, table, elist) - expr_t *expr; - int table; - expr_list_t *elist; +__subst_expr(expr_t* expr, int table, expr_list_t* elist) { expr_t *new; @@ -1886,10 +1841,7 @@ __subst_expr(expr, table, elist) * STATIC: expr_list_t *)); */ static void -__subst_expr_list(list, table, elist) - expr_list_t *list; - int table; - expr_list_t *elist; +__subst_expr_list(expr_list_t* list, int table, expr_list_t* elist) { int i; if (list == 0) @@ -1980,12 +1932,7 @@ __subst_expr_list(list, table, elist) * subquery_agg_p True if the subquery uses aggregate functions */ static int -__flatten_subquery(parser, select, from, agg_p, subquery_agg_p) - parser_t *parser; - select_t *select; - int from; - int agg_p; - int subquery_agg_p; +__flatten_subquery(parser_t* parser, select_t* select, int from, int agg_p, int subquery_agg_p) { select_t *sub_select; /* The inner query or "subquery" */ src_list_t *outer_from_clause; /* The FROM clause of the outer query */ @@ -2228,11 +2175,7 @@ __flatten_subquery(parser, select, from, agg_p, subquery_agg_p) * STATIC: static int __min_max_query __P((parser_t *, select_t *, int, int)); */ static int -__min_max_query(parser, select, dest, param) - parser_t *parser; - select_t *select; - int dest; - int param; +__min_max_query(parser_t* parser, select_t* select, int dest, int param) { expr_t *expr; int col; @@ -2907,10 +2850,7 @@ int __select(parser, select, dest, param, parent, parent_tab, parent_agg_p) * PUBLIC: table_t *__select_result_set __P((parser_t *, char *, select_t *)); */ table_t * -__select_result_set(parser, tab_name, select) - parser_t *parser; - char *tab_name; - select_t *select; +__select_result_set(parser_t* parser, char* tab_name, select_t* select) { int i, j, n, cnt; table_t *table; diff --git a/src/cg_trigger.c b/src/cg_trigger.c index b29cf28..f8fb159 100644 --- a/src/cg_trigger.c +++ b/src/cg_trigger.c @@ -28,8 +28,7 @@ * PUBLIC: void __vdbe_delete_trigger_step __P((trigger_step_t *)); */ void -__vdbe_delete_trigger_step(ts) - trigger_step_t *ts; +__vdbe_delete_trigger_step(trigger_step_t* ts) { while(ts) { trigger_step_t * tmp = ts; @@ -221,10 +220,7 @@ __begin_trigger(parser, trigger, tr_tm, op, columns, tab_name, foreach, * CREATE TRIGGER */ void -__finish_trigger(parser, steplist, all) - parser_t *parser; - trigger_step_t *steplist; - token_t *all; +__finish_trigger(parser_t* parser, trigger_step_t* steplist, token_t* all) { ref_normalizer_ctx_t normctx; trigger_t *nt = 0; /* The trigger whose construction is finishing up */ @@ -316,8 +312,7 @@ __finish_trigger(parser, steplist, all) * STATIC: static void __persist_trigger_step __P((trigger_step_t *)); */ static void -__persist_trigger_step(ts) - trigger_step_t *ts; +__persist_trigger_step(trigger_step_t* ts) { if (ts->target.z) { __dbsql_strndup(NULL, ts->target.z, &ts->target.z, ts->target.n); @@ -356,8 +351,7 @@ __persist_trigger_step(ts) * PUBLIC: trigger_step_t * __trigger_select_step __P((select_t *)); */ trigger_step_t * -__trigger_select_step(select) - select_t *select; +__trigger_select_step(select_t* select) { trigger_step_t *ts; @@ -392,12 +386,7 @@ __trigger_select_step(select) * etc.) */ trigger_step_t * -__trigger_insert_step(tab_name, column, elist, select, orconf) - token_t *tab_name; - id_list_t *column; - expr_list_t *elist; - select_t *select; - int orconf; +__trigger_insert_step(token_t* tab_name, id_list_t* column, expr_list_t* elist, select_t* select, int orconf) { trigger_step_t *ts; @@ -434,11 +423,7 @@ __trigger_insert_step(tab_name, column, elist, select, orconf) * etc) */ trigger_step_t * -__trigger_update_step(tab_name, elist, where_clause, orconf) - token_t *tab_name; - expr_list_t *elist; - expr_t *where_clause; - int orconf; +__trigger_update_step(token_t* tab_name, expr_list_t* elist, expr_t* where_clause, int orconf) { trigger_step_t *ts; @@ -464,9 +449,7 @@ __trigger_update_step(tab_name, elist, where_clause, orconf) * PUBLIC: trigger_step_t *__trigger_delete_step __P((token_t *, expr_t *)); */ trigger_step_t * -__trigger_delete_step(tab_name, where_clause) - token_t *tab_name; - expr_t *where_clause; +__trigger_delete_step(token_t* tab_name, expr_t* where_clause) { trigger_step_t *ts; @@ -489,8 +472,7 @@ __trigger_delete_step(tab_name, where_clause) * PUBLIC: void __vdbe_delete_trigger __P((trigger_t *)); */ void -__vdbe_delete_trigger(trigger) - trigger_t *trigger; +__vdbe_delete_trigger(trigger_t* trigger) { if (trigger == 0) return; @@ -521,9 +503,7 @@ __vdbe_delete_trigger(trigger) * PUBLIC: void __drop_trigger __P((parser_t *, src_list_t *)); */ void -__drop_trigger(parser, trig_list) - parser_t *parser; - src_list_t *trig_list; +__drop_trigger(parser_t* parser, src_list_t* trig_list) { int i; trigger_t *trigger; @@ -567,10 +547,7 @@ __drop_trigger(parser, trig_list) * PUBLIC: void __drop_trigger_ptr __P((parser_t *, trigger_t *, int)); */ void -__drop_trigger_ptr(parser, trigger, nested) - parser_t *parser; - trigger_t *trigger; - int nested; +__drop_trigger_ptr(parser_t* parser, trigger_t* trigger, int nested) { table_t *table; vdbe_t *v; @@ -669,9 +646,7 @@ __drop_trigger_ptr(parser, trigger, nested) * STATIC: static int __check_column_overlap __P((id_list_t *, expr_list_t *)); */ static int -__check_column_overlap(id_list, elist) - id_list_t *id_list; - expr_list_t *elist; +__check_column_overlap(id_list_t* id_list, expr_list_t* elist) { int e; if (!id_list || !elist) @@ -792,10 +767,7 @@ static src_list_t *targetSrcList(parser, step) * orconfin Conflict algorithm. (OE_Abort, etc) */ static int -__code_trigger_program(parser, steplist, orconfin) - parser_t *parser; - trigger_step_t *steplist; - int orconfin; +__code_trigger_program(parser_t* parser, trigger_step_t* steplist, int orconfin) { int orconf; trigger_step_t * ts = steplist; diff --git a/src/cg_vacuum.c b/src/cg_vacuum.c index beb1b6c..f5239b4 100644 --- a/src/cg_vacuum.c +++ b/src/cg_vacuum.c @@ -36,9 +36,7 @@ * PUBLIC: void __vacuum __P((parser_t *, token_t *)); */ void -__vacuum(parser, tab_name) - parser_t *parser; - token_t *tab_name; +__vacuum(parser_t* parser, token_t* tab_name) { vdbe_t *v = __parser_get_vdbe(parser); __vdbe_add_op(v, OP_Vacuum, 0, 0); @@ -53,9 +51,7 @@ __vacuum(parser, tab_name) * PUBLIC: int __execute_vacuum __P((char **, DBSQL *)); */ int -__execute_vacuum(err_msgs, dbp) - char **err_msgs; - DBSQL *dbp; +__execute_vacuum(char* *err_msgs, DBSQL* dbp) { return DBSQL_SUCCESS; /* NOTE: When DB implements compaction (someday) then this will be the place to invoke the @@ -72,9 +68,7 @@ __execute_vacuum(err_msgs, dbp) * PUBLIC: int __execute_vacuum __P((char **, DBSQL *)); */ int -__execute_vacuum(err_msgs, dbp) - char **err_msgs; - DBSQL *dbp; +__execute_vacuum(char* *err_msgs, DBSQL* dbp) { return DBSQL_SUCCESS; } diff --git a/src/cg_where.c b/src/cg_where.c index 48ae8f9..3b6b83f 100644 --- a/src/cg_where.c +++ b/src/cg_where.c @@ -71,10 +71,7 @@ typedef struct expr_mask_set { * STATIC: static int __expr_split __P((int, expr_info_t *, expr_t *)); */ static int -__expr_split(num_slot, slot, expr) - int num_slot; - expr_info_t *slot; - expr_t *expr; +__expr_split(int num_slot, expr_info_t* slot, expr_t* expr) { int cnt = 0; if (expr == 0 || num_slot < 1) @@ -101,9 +98,7 @@ __expr_split(num_slot, slot, expr) * STATIC: static int __get_cursor_bitmask __P((expr_mask_set_t *, int)); */ static int -__get_cursor_bitmask(mask_set, cursor) - expr_mask_set_t *mask_set; - int cursor; +__get_cursor_bitmask(expr_mask_set_t* mask_set, int cursor) { int i; for (i = 0; i < mask_set->n; i++) { @@ -140,9 +135,7 @@ __get_cursor_bitmask(mask_set, cursor) * STATIC: static int __expr_table_usage __P((expr_mask_set_t *, expr_t *)); */ static int -__expr_table_usage(mask_set, p) - expr_mask_set_t *mask_set; - expr_t *p; +__expr_table_usage(expr_mask_set_t* mask_set, expr_t* p) { int i; unsigned int mask = 0; @@ -175,8 +168,7 @@ __expr_table_usage(mask_set, p) * STATIC: static int __allowed_op __P((int)); */ static int -__allowed_op(op) - int op; +__allowed_op(int op) { switch(op) { case TK_LT: /* FALLTHROUGH */ @@ -201,9 +193,7 @@ __allowed_op(op) * STATIC: static void expr_analyze __P((expr_mask_set_t *, expr_info_t *)); */ static void -__expr_analyze(mask_set, info) - expr_mask_set_t *mask_set; - expr_info_t *info; +__expr_analyze(expr_mask_set_t* mask_set, expr_info_t* info) { expr_t *expr = info->p; info->prereqLeft = __expr_table_usage(mask_set, expr->pLeft); @@ -1391,8 +1381,7 @@ where_info_t *__where_begin(parser, tab_list, where_clause, push_key_p, * PUBLIC: void __where_end __P((where_info_t *)); */ void -__where_end(winfo) - where_info_t *winfo; +__where_end(where_info_t* winfo) { int i, addr; where_level_t *level; diff --git a/src/clib/random.c b/src/clib/random.c index cb3aea1..9cf65f5 100644 --- a/src/clib/random.c +++ b/src/clib/random.c @@ -116,8 +116,7 @@ */ #ifndef HAVE_SRAND48_R void -__rng_seed(buf) - char *buf; +__rng_seed(char* buf) { u_int32_t pid; double jt; diff --git a/src/clib/xvprintf.c b/src/clib/xvprintf.c index 44c6d95..947ed74 100644 --- a/src/clib/xvprintf.c +++ b/src/clib/xvprintf.c @@ -126,9 +126,7 @@ static et_info_t fmtinfo[] = { * always returned. */ static int -et_getdigit(val, cnt) - long_double_t *val; - int *cnt; +et_getdigit(long_double_t* val, int* cnt) { int digit; long_double_t d; @@ -757,10 +755,7 @@ __et_printf(dbp, func, arg, fmt, ap) * STATIC: static void mout __P((void *, char *, int)); */ static void -__mout(arg, zNewText, nNewChar) - void *arg; - char *zNewText; - int nNewChar; +__mout(void* arg, char* zNewText, int nNewChar) { xvprintf_t *pM = (xvprintf_t*)arg; if (pM->len + nNewChar + 1 > pM->amt) { diff --git a/src/common/dbsql_alloc.c b/src/common/dbsql_alloc.c index 1f36145..29adafb 100644 --- a/src/common/dbsql_alloc.c +++ b/src/common/dbsql_alloc.c @@ -33,10 +33,7 @@ * PUBLIC: int __dbsql_umalloc __P((DBSQL *, size_t, void *)); */ int -__dbsql_umalloc(dbp, size, storep) - DBSQL *dbp; - size_t size; - void *storep; +__dbsql_umalloc(DBSQL* dbp, size_t size, void* storep) { return (__os_umalloc((dbp ? dbp->dbenv : NULL), size, storep)); } @@ -48,10 +45,7 @@ __dbsql_umalloc(dbp, size, storep) * PUBLIC: int __dbsql_urealloc __P((DBSQL *, size_t, void *)); */ int -__dbsql_urealloc(dbp, size, storep) - DBSQL *dbp; - size_t size; - void *storep; +__dbsql_urealloc(DBSQL* dbp, size_t size, void* storep) { return (__os_urealloc((dbp ? dbp->dbenv : NULL), size, storep)); } @@ -63,9 +57,7 @@ __dbsql_urealloc(dbp, size, storep) * PUBLIC: void __dbsql_ufree __P((DBSQL *, void *)); */ void -__dbsql_ufree(dbp, ptr) - DBSQL *dbp; - void *ptr; +__dbsql_ufree(DBSQL* dbp, void* ptr) { __os_ufree((dbp ? dbp->dbenv : NULL), ptr); } @@ -141,10 +133,7 @@ __dbsql_calloc(dbp, num, size, storep) * PUBLIC: int __dbsql_malloc __P((DBSQL *, size_t, void *)); */ int -__dbsql_malloc(dbp, size, storep) - DBSQL *dbp; - size_t size; - void *storep; +__dbsql_malloc(DBSQL* dbp, size_t size, void* storep) { return (__os_malloc((dbp ? dbp->dbenv : NULL), size, storep)); } @@ -156,10 +145,7 @@ __dbsql_malloc(dbp, size, storep) * PUBLIC: int __dbsql_realloc __P((DBSQL *, size_t, void *)); */ int -__dbsql_realloc(dbp, size, storep) - DBSQL *dbp; - size_t size; - void *storep; +__dbsql_realloc(DBSQL* dbp, size_t size, void* storep) { return (__os_realloc((dbp ? dbp->dbenv : NULL), size, storep)); } @@ -171,9 +157,7 @@ __dbsql_realloc(dbp, size, storep) * PUBLIC: void __dbsql_free __P((DBSQL *, void *)); */ void -__dbsql_free(dbp, ptr) - DBSQL *dbp; - void *ptr; +__dbsql_free(DBSQL* dbp, void* ptr) { __os_free((dbp ? dbp->dbenv : NULL), ptr); } diff --git a/src/common/dbsql_err.c b/src/common/dbsql_err.c index b684a13..1af8d20 100644 --- a/src/common/dbsql_err.c +++ b/src/common/dbsql_err.c @@ -63,8 +63,7 @@ __dbsql_assert(failedexpr, file, line) * PUBLIC: int __dbsql_panic_msg __P((DBSQL *)); */ int -__dbsql_panic_msg(dbp) - DBSQL *dbp; +__dbsql_panic_msg(DBSQL* dbp) { __dbsql_err(dbp, "PANIC: fatal database error detected; run recovery"); @@ -81,9 +80,7 @@ __dbsql_panic_msg(dbp) * PUBLIC: int __dbsql_panic __P((DBSQL *, int)); */ int -__dbsql_panic(dbp, errval) - DBSQL *dbp; - int errval; +__dbsql_panic(DBSQL* dbp, int errval) { if (dbp != NULL) { PANIC_SET(dbp, 1); @@ -120,8 +117,7 @@ __dbsql_panic(dbp, errval) * EXTERN: char *dbsql_strerror __P((int)); */ char * -dbsql_strerror(error) - int error; +dbsql_strerror(int error) { char *p; diff --git a/src/common/hash.c b/src/common/hash.c index b6317d7..3cf9cfd 100644 --- a/src/common/hash.c +++ b/src/common/hash.c @@ -116,10 +116,7 @@ * PUBLIC: void __hash_init __P((hash_t *, int, int)); */ void -__hash_init(this, class, copy_key_p) - hash_t *this; - int class; - int copy_key_p; +__hash_init(hash_t* this, int class, int copy_key_p) { DBSQL_ASSERT(this != 0); DBSQL_ASSERT(class >= DBSQL_HASH_INT && class <= DBSQL_HASH_BINARY); @@ -141,8 +138,7 @@ __hash_init(this, class, copy_key_p) * PUBLIC: void __hash_clear __P((hash_t *)); */ void -__hash_clear(this) - hash_t *this; +__hash_clear(hash_t* this) { hash_ele_t *elem; DBSQL_ASSERT(this != 0); @@ -321,9 +317,7 @@ static int * STATIC: static void __rehash __P((hash_t *, int)); */ static void -__rehash(this, new_size) - hash_t *this; - int new_size; +__rehash(hash_t* this, int new_size) { struct _ht *new_ht; /* The new hash table */ hash_ele_t *elem, *next_elem; /* For looping over existing elements */ diff --git a/src/common/str.c b/src/common/str.c index 9ad7740..a6a9149 100644 --- a/src/common/str.c +++ b/src/common/str.c @@ -187,7 +187,7 @@ __str_nappend(result, va_alist) size_t len; const char *tmp; char *r; - int n; + unsigned long n; if (result == 0) return; @@ -222,16 +222,15 @@ __str_nappend(result, va_alist) * the quote characters. The conversion is done in-place. If the * input does not begin with a quote character, then this routine * is a no-op. Quotes can be of the form "'a-b-c'" or the MS-Access style - * brackets around identifers such as: "[a-b-c]". In both cases the + * brackets around identifiers such as: "[a-b-c]". In both cases the * result is "a-b-c". * * PUBLIC: void __str_unquote __P((char *)); */ void -__str_unquote(z) - char *z; +__str_unquote(char* z) { - int quote; + char quote; int i, j; if (z == NULL) @@ -262,15 +261,14 @@ __str_unquote(z) * __str_urealloc -- * Make a duplicate of a string into memory obtained from * __dbsql_umalloc() Free the original string using __dbsql_free(). - * This routine is called on all strings that are passed outside of + * This routine is called on all strings that are passed outside * the library. That way clients can free the string using * __dbsql_ufree() rather than having to call __dbsql_free(). * * PUBLIC: int __str_urealloc __P((char **)); */ int -__str_urealloc(pz) - char **pz; +__str_urealloc(char* *pz) { int rc = DBSQL_SUCCESS; char *new; @@ -298,8 +296,7 @@ __str_urealloc(pz) * PUBLIC: int __str_is_numeric __P((const char *)); */ int -__str_is_numeric(z) - const char *z; +__str_is_numeric(const char *z) { if (*z == '-' || *z == '+') z++; @@ -417,14 +414,11 @@ static int __utf8_to_int(const unsigned char *z) { * PUBLIC: const unsigned char *)); */ int -__str_glob_cmp(pattern, string) - const unsigned char *pattern; - const unsigned char *string; +__str_glob_cmp(const unsigned char *pattern, const unsigned char *string) { - char c; + unsigned char c, c2; int invert; int seen; - char c2; while((c = *pattern) != 0) { switch(c) { @@ -530,9 +524,7 @@ __str_glob_cmp(pattern, string) * PUBLIC: const unsigned char *)); */ int -__str_like_cmp(pattern, string) - const unsigned char *pattern; - const unsigned char *string; +__str_like_cmp(const unsigned char *pattern, const unsigned char *string) { register int c; int c2; @@ -600,9 +592,7 @@ __str_like_cmp(pattern, string) * PUBLIC: int __str_numeric_cmp __P((const char *, const char *)); */ int -__str_numeric_cmp(left, right) - const char *left; - const char *right; +__str_numeric_cmp(const char *left, const char *right) { int result; int left_is_num, right_is_num; @@ -652,10 +642,10 @@ __str_numeric_cmp(left, right) * PUBLIC: int __str_int_in32b __P((const char *)); */ int -__str_int_in32b(num) - const char *num; +__str_int_in32b(const char *num) { - int c, i = 0; + int i = 0; + char c; if (*num == '-' || *num == '+') num++; while ((c = num[i]) >= '0' && c <= '9') { @@ -694,9 +684,7 @@ __str_int_in32b(num) * PUBLIC: void __str_real_as_sortable __P((double, char *)); */ void -__str_real_as_sortable(r, z) - double r; - char *z; +__str_real_as_sortable(double r, char* z) { int neg; int exp; @@ -825,13 +813,10 @@ __str_real_as_sortable(r, z) * PUBLIC: int __str_cmp __P((const char *, const char *)); */ int -__str_cmp(a, b) - const char *a; - const char *b; +__str_cmp(const char *a, const char *b) { - int res = 0; + unsigned char dir = 0, res = 0; int a_numeric_p, b_numeric_p; - int dir = 0; while(res == 0 && *a && *b) { if (a[0] == 'N' || b[0] == 'N') { diff --git a/src/dbsql.in b/src/dbsql.in index 9eea3b7..d197935 100644 --- a/src/dbsql.in +++ b/src/dbsql.in @@ -99,7 +99,7 @@ typedef int (*dbsql_callback)(void *, int, char **, char **); /* * If the following macro is set to 1, then NULL values are considered * distinct for the SELECT DISTINCT statement and for UNION or EXCEPT - * compound queries. No other SQL database engine (among those tested) + * compound queries. No other SQL database engine (among those tested) * works this way except for OCELOT. But the SQL92 spec implies that * this is how things should work. * @@ -181,7 +181,7 @@ extern const char dbsql_encoding[]; #define DBSQL_CANTOPEN (-50988)/* Unable to open the database file */ #define DBSQL_PROTOCOL (-50987)/* Database lock protocol error */ #define DBSQL_SCHEMA (-50986)/* The database schema changed */ -#define DBSQL_CONSTRAINT (-50985)/* Abort due to contraint violation */ +#define DBSQL_CONSTRAINT (-50985)/* Abort due to constraint violation */ #define DBSQL_MISMATCH (-50984)/* Data type mismatch */ #define DBSQL_MISUSE (-50983)/* Library used incorrectly */ #define DBSQL_AUTH (-50982)/* Authorization denied */ @@ -225,7 +225,7 @@ struct __dbsql { void (*set_progresscall) __P((DBSQL *, int, int(*)(void*), void*)); #endif void *(*set_commitcall) __P((DBSQL *, int(*)(void*), void*)); - void (*set_busycall) __P((DBSQL *, int(*)(int, const char *, int),\ + void (*set_busycall) __P((DBSQL *, int(*)(DBSQL *, void *, const char *, int),\ void *)); void (*set_timeout) __P((DBSQL *, int ms)); @@ -275,7 +275,7 @@ struct __dbsql { * codes is used as the second parameter. The 5th parameter is the name * of the database ("main", "temp", etc.) if applicable. The 6th parameter * is the name of the inner-most trigger or view that is responsible for - * the access attempt or NULL if this access attempt is directly from + * the access attempt or NULL if this access attempt is directly from * input SQL code. * Arg-3 Arg-4 */ diff --git a/src/dbsql/dbsql.c b/src/dbsql/dbsql.c index bc75a96..8663d09 100644 --- a/src/dbsql/dbsql.c +++ b/src/dbsql/dbsql.c @@ -92,9 +92,7 @@ extern int isatty(); * is done. */ static char * -local_getline(prompt, in) - char *prompt; - FILE *in; +local_getline(char* prompt, FILE* in) { char *line; int len; @@ -288,8 +286,7 @@ output_html_string(out, z) ** This routine runs when the user presses Ctrl-C */ static void -interrupt_handler(NOT_USED) - int NOT_USED; +interrupt_handler(int NOT_USED) { g.interrupted_p = 1; if (g.dbp) @@ -301,11 +298,7 @@ interrupt_handler(NOT_USED) * for each row of a query result. */ static int -callback(arg, num_args, args, cols) - void *arg; - int num_args; - char **args; - char **cols; +callback(void* arg, int num_args, char* *args, char* *cols) { int i; struct callback_data *p = (struct callback_data*)arg; @@ -510,11 +503,7 @@ set_table_name(p, name) * This routine should print text sufficient to recreate the table. */ static int -dump_callback(arg, num_args, args, cols) - void *arg; - int num_args; - char **args; - char **cols; +dump_callback(void* arg, int num_args, char* *args, char* *cols) { struct callback_data *p = (struct callback_data *)arg; if (num_args != 3) @@ -1289,8 +1278,7 @@ static const char options[] = * */ static void -usage(show_detail) - int show_detail; +usage(int show_detail) { fprintf(stderr, "Usage: dbsql [OPTIONS] FILENAME [SQL]\n"); if (show_detail) { @@ -1318,9 +1306,7 @@ main_init(data) } int -main(argc, argv) - int argc; - char **argv; +main(int argc, char* *argv) { char *err_msgs = 0; struct callback_data data; diff --git a/src/dbsql_tclsh.c b/src/dbsql_tclsh.c index d48a6c4..15feb80 100644 --- a/src/dbsql_tclsh.c +++ b/src/dbsql_tclsh.c @@ -56,9 +56,7 @@ static char main_loop[] = * main -- */ int -main(argc, argv) - int argc; - char **argv; +main(int argc, char* *argv) { int i; const char *info; diff --git a/src/inc/db_int.h b/src/inc/db_int.h index 5c6f13d..aa6ce46 100644 --- a/src/inc/db_int.h +++ b/src/inc/db_int.h @@ -46,7 +46,6 @@ extern int __os_urealloc__DB_UNIQUE_NAME__ __P((DB_ENV *, size_t, void *)); extern void *__ua_memcpy__DB_UNIQUE_NAME__ __P((void *, const void *, size_t)); extern void __os_free__DB_UNIQUE_NAME__ __P((DB_ENV *, void *)); extern void __os_set_errno__DB_UNIQUE_NAME__ __P((int)); -extern void __os_sleep__DB_UNIQUE_NAME__ __P((DB_ENV *, u_long, u_long)); extern void __os_ufree__DB_UNIQUE_NAME__ __P((DB_ENV *, void *)); #if defined(__cplusplus) diff --git a/src/inc/os_ext.h b/src/inc/os_ext.h index ac888cf..08705e1 100644 --- a/src/inc/os_ext.h +++ b/src/inc/os_ext.h @@ -7,6 +7,7 @@ extern "C" { #endif int __os_jtime __P((double *)); +void __os_sleep __P((u_long secs, u_long usecs)); #if defined(__cplusplus) } diff --git a/src/os/os_jtime.c b/src/os/os_jtime.c index 6c53bfa..aa0b1b5 100644 --- a/src/os/os_jtime.c +++ b/src/os/os_jtime.c @@ -47,8 +47,7 @@ int _fake_current_time = 0; * PUBLIC: int __os_jtime __P((double *)); */ int -__os_jtime(result) - double *result; +__os_jtime(double* result) { #ifndef DB_WIN32 time_t t; diff --git a/src/os/os_sleep.c b/src/os/os_sleep.c new file mode 100644 index 0000000..7d0bd6a --- /dev/null +++ b/src/os/os_sleep.c @@ -0,0 +1,59 @@ +/*- + * DBSQL - A SQL database engine. + * + * Copyright (C) 2007-2008 The DBSQL Group, Inc. - All rights reserved. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * There are special exceptions to the terms and conditions of the GPL as it + * is applied to this software. View the full text of the exception in file + * LICENSE_EXCEPTIONS in the directory of this software distribution. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#include "dbsql_config.h" + +#ifndef NO_SYSTEM_INCLUDES +#include + +#include +#include +#include +#endif + +#include "dbsql_int.h" + +/* + * __os_sleep -- + * Pause the thread of control. + * + * PUBLIC: void __os_sleep __P((u_long secs, u_long usecs)); + */ +void +__os_sleep(u_long secs, u_long usecs) +{ + /* Calculate the total time in microseconds */ + u_long total_usecs = secs * 1000000 + usecs; + + /* Convert microseconds to seconds and microseconds */ + u_long sleep_secs = total_usecs / 1000000; + u_long sleep_usecs = total_usecs % 1000000; + + // Sleep using the standard POSIX sleep function + struct timespec req; + struct timespec rem = { 0 }; + req.tv_sec = sleep_secs; + req.tv_nsec = sleep_usecs * 1000; + + /* Handle potential interruption by signals */ + while (nanosleep(&req, &rem) != 0 && errno == EINTR) { + req = rem; + } +} diff --git a/src/py/src/cache.c b/src/py/src/cache.c index 4f0620f..e69de29 100644 --- a/src/py/src/cache.c +++ b/src/py/src/cache.c @@ -1,397 +0,0 @@ -/*- - * DBSQL - A SQL database engine. - * - * Copyright (C) 2007 DBSQL Group, Inc - All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * There are special exceptions to the terms and conditions of the GPL as it - * is applied to this software. View the full text of the exception in file - * LICENSE_EXCEPTIONS in the directory of this software distribution. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * http://creativecommons.org/licenses/GPL/2.0/ - * - * $Id: api.c 7 2007-02-03 13:34:17Z gburd $ - */ - -/* cache .c - a LRU cache - * - * Copyright (C) 2004-2006 Gerhard Häring - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -#include "cache.h" -#include - -/* only used internally */ -pydbsql_Node* pydbsql_new_node(PyObject* key, PyObject* data) -{ - pydbsql_Node* node; - - node = (pydbsql_Node*) (pydbsql_NodeType.tp_alloc(&pydbsql_NodeType, 0)); - if (!node) { - return NULL; - } - - Py_INCREF(key); - node->key = key; - - Py_INCREF(data); - node->data = data; - - node->prev = NULL; - node->next = NULL; - - return node; -} - -void pydbsql_node_dealloc(pydbsql_Node* self) -{ - Py_DECREF(self->key); - Py_DECREF(self->data); - - self->ob_type->tp_free((PyObject*)self); -} - -int pydbsql_cache_init(pydbsql_Cache* self, PyObject* args, PyObject* kwargs) -{ - PyObject* factory; - int size = 10; - - self->factory = NULL; - - if (!PyArg_ParseTuple(args, "O|i", &factory, &size)) { - return -1; - } - - /* minimum cache size is 5 entries */ - if (size < 5) { - size = 5; - } - self->size = size; - self->first = NULL; - self->last = NULL; - - self->mapping = PyDict_New(); - if (!self->mapping) { - return -1; - } - - Py_INCREF(factory); - self->factory = factory; - - self->decref_factory = 1; - - return 0; -} - -void pydbsql_cache_dealloc(pydbsql_Cache* self) -{ - pydbsql_Node* node; - pydbsql_Node* delete_node; - - if (!self->factory) { - /* constructor failed, just get out of here */ - return; - } - - /* iterate over all nodes and deallocate them */ - node = self->first; - while (node) { - delete_node = node; - node = node->next; - Py_DECREF(delete_node); - } - - if (self->decref_factory) { - Py_DECREF(self->factory); - } - Py_DECREF(self->mapping); - - self->ob_type->tp_free((PyObject*)self); -} - -PyObject* pydbsql_cache_get(pydbsql_Cache* self, PyObject* args) -{ - PyObject* key = args; - pydbsql_Node* node; - pydbsql_Node* ptr; - PyObject* data; - - node = (pydbsql_Node*)PyDict_GetItem(self->mapping, key); - if (node) { - /* an entry for this key already exists in the cache */ - - /* increase usage counter of the node found */ - if (node->count < LONG_MAX) { - node->count++; - } - - /* if necessary, reorder entries in the cache by swapping positions */ - if (node->prev && node->count > node->prev->count) { - ptr = node->prev; - - while (ptr->prev && node->count > ptr->prev->count) { - ptr = ptr->prev; - } - - if (node->next) { - node->next->prev = node->prev; - } else { - self->last = node->prev; - } - if (node->prev) { - node->prev->next = node->next; - } - if (ptr->prev) { - ptr->prev->next = node; - } else { - self->first = node; - } - - node->next = ptr; - node->prev = ptr->prev; - if (!node->prev) { - self->first = node; - } - ptr->prev = node; - } - } else { - /* There is no entry for this key in the cache, yet. We'll insert a new - * entry in the cache, and make space if necessary by throwing the - * least used item out of the cache. */ - - if (PyDict_Size(self->mapping) == self->size) { - if (self->last) { - node = self->last; - - if (PyDict_DelItem(self->mapping, self->last->key) != 0) { - return NULL; - } - - if (node->prev) { - node->prev->next = NULL; - } - self->last = node->prev; - node->prev = NULL; - - Py_DECREF(node); - } - } - - data = PyObject_CallFunction(self->factory, "O", key); - - if (!data) { - return NULL; - } - - node = pydbsql_new_node(key, data); - if (!node) { - return NULL; - } - node->prev = self->last; - - Py_DECREF(data); - - if (PyDict_SetItem(self->mapping, key, (PyObject*)node) != 0) { - Py_DECREF(node); - return NULL; - } - - if (self->last) { - self->last->next = node; - } else { - self->first = node; - } - self->last = node; - } - - Py_INCREF(node->data); - return node->data; -} - -PyObject* pydbsql_cache_display(pydbsql_Cache* self, PyObject* args) -{ - pydbsql_Node* ptr; - PyObject* prevkey; - PyObject* nextkey; - PyObject* fmt_args; - PyObject* template; - PyObject* display_str; - - ptr = self->first; - - while (ptr) { - if (ptr->prev) { - prevkey = ptr->prev->key; - } else { - prevkey = Py_None; - } - Py_INCREF(prevkey); - - if (ptr->next) { - nextkey = ptr->next->key; - } else { - nextkey = Py_None; - } - Py_INCREF(nextkey); - - fmt_args = Py_BuildValue("OOO", prevkey, ptr->key, nextkey); - if (!fmt_args) { - return NULL; - } - template = PyString_FromString("%s <- %s ->%s\n"); - if (!template) { - return NULL; - } - display_str = PyString_Format(template, fmt_args); - Py_DECREF(template); - Py_DECREF(fmt_args); - if (!display_str) { - return NULL; - } - PyObject_Print(display_str, stdout, Py_PRINT_RAW); - Py_DECREF(display_str); - - Py_DECREF(prevkey); - Py_DECREF(nextkey); - - ptr = ptr->next; - } - - Py_INCREF(Py_None); - return Py_None; -} - -static PyMethodDef cache_methods[] = { - {"get", (PyCFunction)pydbsql_cache_get, METH_O, - PyDoc_STR("Gets an entry from the cache or calls the factory function to produce one.")}, - {"display", (PyCFunction)pydbsql_cache_display, METH_NOARGS, - PyDoc_STR("For debugging only.")}, - {NULL, NULL} -}; - -PyTypeObject pydbsql_NodeType = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - MODULE_NAME "Node", /* tp_name */ - sizeof(pydbsql_Node), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)pydbsql_node_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */ - 0, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)0, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0 /* tp_free */ -}; - -PyTypeObject pydbsql_CacheType = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - MODULE_NAME ".Cache", /* tp_name */ - sizeof(pydbsql_Cache), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)pydbsql_cache_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */ - 0, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - cache_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)pydbsql_cache_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0 /* tp_free */ -}; - -extern int pydbsql_cache_setup_types(void) -{ - int rc; - - pydbsql_NodeType.tp_new = PyType_GenericNew; - pydbsql_CacheType.tp_new = PyType_GenericNew; - - rc = PyType_Ready(&pydbsql_NodeType); - if (rc < 0) { - return rc; - } - - rc = PyType_Ready(&pydbsql_CacheType); - return rc; -} diff --git a/src/py/src/connection.c b/src/py/src/connection.c index be23708..e69de29 100644 --- a/src/py/src/connection.c +++ b/src/py/src/connection.c @@ -1,1325 +0,0 @@ -/*- - * DBSQL - A SQL database engine. - * - * Copyright (C) 2007 DBSQL Group, Inc - All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * There are special exceptions to the terms and conditions of the GPL as it - * is applied to this software. View the full text of the exception in file - * LICENSE_EXCEPTIONS in the directory of this software distribution. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * http://creativecommons.org/licenses/GPL/2.0/ - * - * $Id: api.c 7 2007-02-03 13:34:17Z gburd $ - */ - -/* connection.c - the connection type - * - * Copyright (C) 2004-2006 Gerhard Häring - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -#include "cache.h" -#include "module.h" -#include "connection.h" -#include "statement.h" -#include "cursor.h" -#include "prepare_protocol.h" -#include "util.h" -#include "dbsqlcompat.h" - -#include "pythread.h" - -static int pydbsql_connection_set_isolation_level(pydbsql_Connection* self, PyObject* isolation_level); - - -void _dbsql_result_error(dbsql_func_t* ctx, const char* errmsg, int len) -{ - dbsql_set_result_error(ctx, errmsg, len); -} - -int pydbsql_connection_init(pydbsql_Connection* self, PyObject* args, PyObject* kwargs) -{ - static char *kwlist[] = {"database", "timeout", "detect_types", "isolation_level", "check_same_thread", "factory", "cached_statements", NULL, NULL}; - - char* database; - char* errors; - int detect_types = 0; - PyObject* isolation_level = NULL; - PyObject* factory = NULL; - int check_same_thread = 1; - int cached_statements = 100; - double timeout = 5.0; - int rc; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|diOiOi", kwlist, - &database, &timeout, &detect_types, - &isolation_level, &check_same_thread, - &factory, &cached_statements)) - { - return -1; - } - - self->begin_statement = NULL; - - self->statement_cache = NULL; - self->statements = NULL; - - Py_INCREF(Py_None); - self->row_factory = Py_None; - - Py_INCREF(&PyUnicode_Type); - self->text_factory = (PyObject*)&PyUnicode_Type; - - Py_BEGIN_ALLOW_THREADS - rc = self->db->open(self->db, database, 0, &errors); - Py_END_ALLOW_THREADS - - if (errors) { - free(errors); /*TODO*/ - errors = 0; - } - if (rc != DBSQL_SUCCESS) { - _pydbsql_seterror(rc); - return -1; - } - - if (!isolation_level) { - isolation_level = PyString_FromString(""); - if (!isolation_level) { - return -1; - } - } else { - Py_INCREF(isolation_level); - } - self->isolation_level = NULL; - pydbsql_connection_set_isolation_level(self, isolation_level); - Py_DECREF(isolation_level); - - self->statement_cache = (pydbsql_Cache*)PyObject_CallFunction((PyObject*)&pydbsql_CacheType, "Oi", self, cached_statements); - if (PyErr_Occurred()) { - return -1; - } - - self->statements = PyList_New(0); - if (!self->statements) { - return -1; - } - self->created_statements = 0; - - /* By default, the Cache class INCREFs the factory in its initializer, and - * decrefs it in its deallocator method. Since this would create a circular - * reference here, we're breaking it by decrementing self, and telling the - * cache class to not decref the factory (self) in its deallocator. - */ - self->statement_cache->decref_factory = 0; - Py_DECREF(self); - - self->inTransaction = 0; - self->detect_types = detect_types; - self->timeout = timeout; - self->db->set_timeout(self->db, (int)(timeout*1000)); - - self->thread_ident = PyThread_get_thread_ident(); - self->check_same_thread = check_same_thread; - - self->function_pinboard = PyDict_New(); - if (!self->function_pinboard) { - return -1; - } - - self->collations = PyDict_New(); - if (!self->collations) { - return -1; - } - - self->Warning = pydbsql_Warning; - self->Error = pydbsql_Error; - self->InterfaceError = pydbsql_InterfaceError; - self->DatabaseError = pydbsql_DatabaseError; - self->DataError = pydbsql_DataError; - self->OperationalError = pydbsql_OperationalError; - self->IntegrityError = pydbsql_IntegrityError; - self->InternalError = pydbsql_InternalError; - self->ProgrammingError = pydbsql_ProgrammingError; - self->NotSupportedError = pydbsql_NotSupportedError; - - return 0; -} - -/* Empty the entire statement cache of this connection */ -void pydbsql_flush_statement_cache(pydbsql_Connection* self) -{ - pydbsql_Node* node; - pydbsql_Statement* statement; - - node = self->statement_cache->first; - - while (node) { - statement = (pydbsql_Statement*)(node->data); - (void)pydbsql_statement_finalize(statement); - node = node->next; - } - - Py_DECREF(self->statement_cache); - self->statement_cache = (pydbsql_Cache*)PyObject_CallFunction((PyObject*)&pydbsql_CacheType, "O", self); - Py_DECREF(self); - self->statement_cache->decref_factory = 0; -} - -void pydbsql_reset_all_statements(pydbsql_Connection* self) -{ - int i; - PyObject* weakref; - PyObject* statement; - - for (i = 0; i < PyList_Size(self->statements); i++) { - weakref = PyList_GetItem(self->statements, i); - statement = PyWeakref_GetObject(weakref); - if (statement != Py_None) { - (void)pydbsql_statement_reset((pydbsql_Statement*)statement); - } - } -} - -void pydbsql_connection_dealloc(pydbsql_Connection* self) -{ - Py_XDECREF(self->statement_cache); - - /* Clean up if user has not called .close() explicitly. */ - if (self->db) { - Py_BEGIN_ALLOW_THREADS - self->db->close(self->db); - Py_END_ALLOW_THREADS - } - - if (self->begin_statement) { - PyMem_Free(self->begin_statement); - } - Py_XDECREF(self->isolation_level); - Py_XDECREF(self->function_pinboard); - Py_XDECREF(self->row_factory); - Py_XDECREF(self->text_factory); - Py_XDECREF(self->collations); - Py_XDECREF(self->statements); - - self->ob_type->tp_free((PyObject*)self); -} - -PyObject* pydbsql_connection_cursor(pydbsql_Connection* self, PyObject* args, PyObject* kwargs) -{ - static char *kwlist[] = {"factory", NULL, NULL}; - PyObject* factory = NULL; - PyObject* cursor; - - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", kwlist, - &factory)) { - return NULL; - } - - if (!pydbsql_check_thread(self) || !pydbsql_check_connection(self)) { - return NULL; - } - - if (factory == NULL) { - factory = (PyObject*)&pydbsql_CursorType; - } - - cursor = PyObject_CallFunction(factory, "O", self); - - if (cursor && self->row_factory != Py_None) { - Py_XDECREF(((pydbsql_Cursor*)cursor)->row_factory); - Py_INCREF(self->row_factory); - ((pydbsql_Cursor*)cursor)->row_factory = self->row_factory; - } - - return cursor; -} - -PyObject* pydbsql_connection_close(pydbsql_Connection* self, PyObject* args) -{ - int rc; - - if (!pydbsql_check_thread(self)) { - return NULL; - } - - pydbsql_flush_statement_cache(self); - - if (self->db) { - Py_BEGIN_ALLOW_THREADS - rc = self->db->close(self->db); - Py_END_ALLOW_THREADS - - if (rc != DBSQL_SUCCESS) { - _pydbsql_seterror(rc); - return NULL; - } else { - self->db = NULL; - } - } - - Py_INCREF(Py_None); - return Py_None; -} - -/* - * Checks if a connection object is usable (i. e. not closed). - * - * 0 => error; 1 => ok - */ -int pydbsql_check_connection(pydbsql_Connection* con) -{ - if (!con->db) { - PyErr_SetString(pydbsql_ProgrammingError, "Cannot operate on a closed database."); - return 0; - } else { - return 1; - } -} - -PyObject* _pydbsql_connection_begin(pydbsql_Connection* self) -{ - int rc; - const char* tail; - dbsql_stmt_t* statement; - char *errors; - - Py_BEGIN_ALLOW_THREADS - rc = self->db->prepare(self->db, self->begin_statement, &tail, &statement, - &errors); - Py_END_ALLOW_THREADS - - if (errors) { - free(errors); /*TODO*/ - errors = 0; - } - if (rc != DBSQL_SUCCESS) { - _pydbsql_seterror(rc); - goto error; - } - - rc = _dbsql_step_with_busyhandler(statement, self); - if (rc == DBSQL_DONE) { - self->inTransaction = 1; - } else { - _pydbsql_seterror(rc); - } - - Py_BEGIN_ALLOW_THREADS - rc = self->db->finalize(statement, &errors); - Py_END_ALLOW_THREADS - - if (errors) { - free(errors); /*TODO*/ - errors = 0; - } - if (rc != DBSQL_SUCCESS && !PyErr_Occurred()) { - _pydbsql_seterror(rc); - } - -error: - if (PyErr_Occurred()) { - return NULL; - } else { - Py_INCREF(Py_None); - return Py_None; - } -} - -PyObject* pydbsql_connection_commit(pydbsql_Connection* self, PyObject* args) -{ - int rc; - const char* tail; - dbsql_stmt_t* statement; - char *errors; - - if (!pydbsql_check_thread(self) || !pydbsql_check_connection(self)) { - return NULL; - } - - if (self->inTransaction) { - Py_BEGIN_ALLOW_THREADS - rc = self->db->prepare(self->db, "COMMIT", &tail, &statement, &errors); - Py_END_ALLOW_THREADS - - if (errors) { - free(errors); /*TODO*/ - errors = 0; - } - if (rc != DBSQL_SUCCESS) { - _pydbsql_seterror(rc); - goto error; - } - - rc = _dbsql_step_with_busyhandler(statement, self); - if (rc == DBSQL_DONE) { - self->inTransaction = 0; - } else { - _pydbsql_seterror(rc); - } - - Py_BEGIN_ALLOW_THREADS - rc = self->db->finalize(statement, &errors); - Py_END_ALLOW_THREADS - if (errors) { - free(errors); /*TODO*/ - errors = 0; - } - if (rc != DBSQL_SUCCESS && !PyErr_Occurred()) { - _pydbsql_seterror(rc); - } - - } - -error: - if (PyErr_Occurred()) { - return NULL; - } else { - Py_INCREF(Py_None); - return Py_None; - } -} - -PyObject* pydbsql_connection_rollback(pydbsql_Connection* self, PyObject* args) -{ - int rc; - const char* tail; - dbsql_stmt_t* statement; - char *errors; - - if (!pydbsql_check_thread(self) || !pydbsql_check_connection(self)) { - return NULL; - } - - if (self->inTransaction) { - pydbsql_reset_all_statements(self); - - Py_BEGIN_ALLOW_THREADS - rc = self->db->prepare(self->db, "ROLLBACK", &tail, &statement, - &errors); - Py_END_ALLOW_THREADS - - if (errors) { - free(errors); /*TODO*/ - errors = 0; - } - if (rc != DBSQL_SUCCESS) { - _pydbsql_seterror(rc); - goto error; - } - - rc = _dbsql_step_with_busyhandler(statement, self); - if (rc == DBSQL_DONE) { - self->inTransaction = 0; - } else { - _pydbsql_seterror(rc); - } - - Py_BEGIN_ALLOW_THREADS - rc = self->db->finalize(statement, &errors); - Py_END_ALLOW_THREADS - - if (errors) { - free(errors); /*TODO*/ - errors = 0; - } - if (rc != DBSQL_SUCCESS && !PyErr_Occurred()) { - _pydbsql_seterror(rc); - } - - } - -error: - if (PyErr_Occurred()) { - return NULL; - } else { - Py_INCREF(Py_None); - return Py_None; - } -} - -void _pydbsql_set_result(dbsql_func_t* context, PyObject* py_val) -{ - long longval; - const char* buffer; - Py_ssize_t buflen; - PyObject* stringval; - - if ((!py_val) || PyErr_Occurred()) { - dbsql_set_result_null(context); - } else if (py_val == Py_None) { - dbsql_set_result_null(context); - } else if (PyInt_Check(py_val)) { - longval = PyInt_AsLong(py_val); - dbsql_set_result_int64(context, (PY_LONG_LONG)longval); - } else if (PyFloat_Check(py_val)) { - dbsql_set_result_double(context, PyFloat_AsDouble(py_val)); - } else if (PyBuffer_Check(py_val)) { - if (PyObject_AsCharBuffer(py_val, &buffer, &buflen) != 0) { - PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer"); - } else { - dbsql_set_result_blob(context, buffer, buflen, DBSQL_TRANSIENT); - } - } else if (PyString_Check(py_val)) { - dbsql_set_result_varchar(context, PyString_AsString(py_val), -1, DBSQL_TRANSIENT); - } else if (PyUnicode_Check(py_val)) { - stringval = PyUnicode_AsUTF8String(py_val); - if (stringval) { - dbsql_set_result_varchar(context, PyString_AsString(stringval), -1, DBSQL_TRANSIENT); - Py_DECREF(stringval); - } - } else { - /* TODO: raise error */ - } -} - -PyObject* _pydbsql_build_py_params(dbsql_func_t *context, int argc, dbsql_value_t** argv) -{ - PyObject* args; - int i; - dbsql_value_t* cur_value; - PyObject* cur_py_value; - const char* val_str; - - args = PyTuple_New(argc); - if (!args) { - return NULL; - } - - for (i = 0; i < argc; i++) { - cur_value = argv[i]; -#if 0 - PY_LONG_LONG val_int; - Py_ssize_t buflen; - void* raw_buffer; - switch (dbsql_value_type(argv[i])) { /* TODO: types */ - case DBSQL_INTEGER: - val_int = dbsql_value_int64(cur_value); - cur_py_value = PyInt_FromLong((long)val_int); - break; - case DBSQL_FLOAT: - cur_py_value = PyFloat_FromDouble(dbsql_value_double(cur_value)); - break; - case DBSQL_VARCHAR: - val_str = (const char*)dbsql_value_varchar(cur_value); - cur_py_value = PyUnicode_DecodeUTF8(val_str, strlen(val_str), NULL); - /* TODO: have a way to show errors here */ - if (!cur_py_value) { - PyErr_Clear(); - Py_INCREF(Py_None); - cur_py_value = Py_None; - } - break; - case DBSQL_BLOB: - buflen = dbsql_value_bytes(cur_value); - cur_py_value = PyBuffer_New(buflen); - if (!cur_py_value) { - break; - } - if (PyObject_AsWriteBuffer(cur_py_value, &raw_buffer, &buflen)) { - Py_DECREF(cur_py_value); - cur_py_value = NULL; - break; - } - memcpy(raw_buffer, dbsql_value_blob(cur_value), buflen); - break; - case DBSQL_NULL: - default: - Py_INCREF(Py_None); - cur_py_value = Py_None; - } -#else - val_str = (const char*)(cur_value); - cur_py_value = PyString_FromString(val_str); - if (!cur_py_value) { - PyErr_Clear(); - Py_INCREF(Py_None); - cur_py_value = Py_None; - } - break; -#endif - - if (!cur_py_value) { - Py_DECREF(args); - return NULL; - } - - PyTuple_SetItem(args, i, cur_py_value); - - } - - return args; -} - -void _pydbsql_func_callback(dbsql_func_t* context, int argc, dbsql_value_t** argv) -{ - PyObject* args; - PyObject* py_func; - PyObject* py_retval = NULL; - - PyGILState_STATE threadstate; - - threadstate = PyGILState_Ensure(); - - py_func = (PyObject*)dbsql_user_data(context); - - args = _pydbsql_build_py_params(context, argc, argv); - if (args) { - py_retval = PyObject_CallObject(py_func, args); - Py_DECREF(args); - } - - if (py_retval) { - _pydbsql_set_result(context, py_retval); - Py_DECREF(py_retval); - } else { - if (_enable_callback_tracebacks) { - PyErr_Print(); - } else { - PyErr_Clear(); - } - _dbsql_result_error(context, "user-defined function raised exception", -1); - } - - PyGILState_Release(threadstate); -} - -static void _pydbsql_step_callback(dbsql_func_t *context, int argc, dbsql_value_t** params) -{ - PyObject* args; - PyObject* function_result = NULL; - PyObject* aggregate_class; - PyObject** aggregate_instance; - PyObject* stepmethod = NULL; - - PyGILState_STATE threadstate; - - threadstate = PyGILState_Ensure(); - - aggregate_class = (PyObject*)dbsql_user_data(context); - - aggregate_instance = (PyObject**)dbsql_aggregate_context(context, sizeof(PyObject*)); - - if (*aggregate_instance == 0) { - *aggregate_instance = PyObject_CallFunction(aggregate_class, ""); - - if (PyErr_Occurred()) { - *aggregate_instance = 0; - if (_enable_callback_tracebacks) { - PyErr_Print(); - } else { - PyErr_Clear(); - } - _dbsql_result_error(context, "user-defined aggregate's '__init__' method raised error", -1); - goto error; - } - } - - stepmethod = PyObject_GetAttrString(*aggregate_instance, "step"); - if (!stepmethod) { - goto error; - } - - args = _pydbsql_build_py_params(context, argc, params); - if (!args) { - goto error; - } - - function_result = PyObject_CallObject(stepmethod, args); - Py_DECREF(args); - - if (!function_result) { - if (_enable_callback_tracebacks) { - PyErr_Print(); - } else { - PyErr_Clear(); - } - _dbsql_result_error(context, "user-defined aggregate's 'step' method raised error", -1); - } - -error: - Py_XDECREF(stepmethod); - Py_XDECREF(function_result); - - PyGILState_Release(threadstate); -} - -void _pydbsql_final_callback(dbsql_func_t* context) -{ - PyObject* function_result = NULL; - PyObject** aggregate_instance; - PyObject* aggregate_class; - - PyGILState_STATE threadstate; - - threadstate = PyGILState_Ensure(); - - aggregate_class = (PyObject*)dbsql_user_data(context); - - aggregate_instance = (PyObject**)dbsql_aggregate_context(context, sizeof(PyObject*)); - if (!*aggregate_instance) { - /* this branch is executed if there was an exception in the aggregate's - * __init__ */ - - goto error; - } - - function_result = PyObject_CallMethod(*aggregate_instance, "finalize", ""); - if (!function_result) { - if (_enable_callback_tracebacks) { - PyErr_Print(); - } else { - PyErr_Clear(); - } - _dbsql_result_error(context, "user-defined aggregate's 'finalize' method raised error", -1); - } else { - _pydbsql_set_result(context, function_result); - } - -error: - Py_XDECREF(*aggregate_instance); - Py_XDECREF(function_result); - - PyGILState_Release(threadstate); -} - -void _pydbsql_drop_unused_statement_references(pydbsql_Connection* self) -{ - PyObject* new_list; - PyObject* weakref; - int i; - - /* we only need to do this once in a while */ - if (self->created_statements++ < 200) { - return; - } - - self->created_statements = 0; - - new_list = PyList_New(0); - if (!new_list) { - return; - } - - for (i = 0; i < PyList_Size(self->statements); i++) { - weakref = PyList_GetItem(self->statements, i); - if (PyWeakref_GetObject(weakref) != Py_None) { - if (PyList_Append(new_list, weakref) != 0) { - Py_DECREF(new_list); - return; - } - } - } - - Py_DECREF(self->statements); - self->statements = new_list; -} - -PyObject* pydbsql_connection_create_function(pydbsql_Connection* self, PyObject* args, PyObject* kwargs) -{ - static char *kwlist[] = {"name", "narg", "func", NULL, NULL}; - - PyObject* func; - char* name; - int narg; - int rc; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "siO", kwlist, - &name, &narg, &func)) - { - return NULL; - } - - rc = self->db->create_function(self->db, name, narg, DBSQL_UTF8_ENCODED, - (void*)func, _pydbsql_func_callback, - NULL , NULL); - - if (rc != DBSQL_SUCCESS) { - PyErr_SetString(pydbsql_OperationalError, "Error creating function"); - return NULL; - } else { - PyDict_SetItem(self->function_pinboard, func, Py_None); - - Py_INCREF(Py_None); - return Py_None; - } -} - -PyObject* pydbsql_connection_create_aggregate(pydbsql_Connection* self, PyObject* args, PyObject* kwargs) -{ - PyObject* aggregate_class; - - int n_arg; - char* name; - static char *kwlist[] = { "name", "n_arg", "aggregate_class", NULL }; - int rc; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "siO:create_aggregate", - kwlist, &name, &n_arg, &aggregate_class)) { - return NULL; - } - - rc = self->db->create_function(self->db, name, n_arg, DBSQL_UTF8_ENCODED, - (void*)aggregate_class, NULL, - &_pydbsql_step_callback, - &_pydbsql_final_callback); - if (rc != DBSQL_SUCCESS) { - PyErr_SetString(pydbsql_OperationalError, "Error creating aggregate"); - return NULL; - } else { - PyDict_SetItem(self->function_pinboard, aggregate_class, Py_None); - - Py_INCREF(Py_None); - return Py_None; - } -} - -static int _authorizer_callback(void* user_arg, int action, const char* arg1, const char* arg2 , const char* dbname, const char* access_attempt_source) -{ - PyObject *ret; - int rc; - PyGILState_STATE gilstate; - - gilstate = PyGILState_Ensure(); - ret = PyObject_CallFunction((PyObject*)user_arg, "issss", action, arg1, arg2, dbname, access_attempt_source); - - if (!ret) { - if (_enable_callback_tracebacks) { - PyErr_Print(); - } else { - PyErr_Clear(); - } - - rc = DBSQL_DENY; - } else { - if (PyInt_Check(ret)) { - rc = (int)PyInt_AsLong(ret); - } else { - rc = DBSQL_DENY; - } - Py_DECREF(ret); - } - - PyGILState_Release(gilstate); - return rc; -} - -PyObject* pydbsql_connection_set_authorizer(pydbsql_Connection* self, PyObject* args, PyObject* kwargs) -{ - PyObject* authorizer_cb; - - static char *kwlist[] = { "authorizer_callback", NULL }; - int rc; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:set_authorizer", - kwlist, &authorizer_cb)) { - return NULL; - } - - rc = self->db->set_authorizer(self->db, _authorizer_callback, (void*)authorizer_cb); - - if (rc != DBSQL_SUCCESS) { - PyErr_SetString(pydbsql_OperationalError, "Error setting authorizer callback"); - return NULL; - } else { - PyDict_SetItem(self->function_pinboard, authorizer_cb, Py_None); - - Py_INCREF(Py_None); - return Py_None; - } -} - -int pydbsql_check_thread(pydbsql_Connection* self) -{ - if (self->check_same_thread) { - if (PyThread_get_thread_ident() != self->thread_ident) { - PyErr_Format(pydbsql_ProgrammingError, - "DBSQL objects created in a thread can only be used in that same thread." - "The object was created in thread id %ld and this is thread id %ld", - self->thread_ident, PyThread_get_thread_ident()); - return 0; - } - - } - - return 1; -} - -static PyObject* pydbsql_connection_get_isolation_level(pydbsql_Connection* self, void* unused) -{ - Py_INCREF(self->isolation_level); - return self->isolation_level; -} - -static PyObject* pydbsql_connection_get_total_changes(pydbsql_Connection* self, void* unused) -{ - if (!pydbsql_check_connection(self)) { - return NULL; - } else { - return Py_BuildValue("i", self->db->total_change_count(self->db)); - } -} - -static int pydbsql_connection_set_isolation_level(pydbsql_Connection* self, PyObject* isolation_level) -{ - PyObject* res; - PyObject* begin_statement; - - Py_XDECREF(self->isolation_level); - - if (self->begin_statement) { - PyMem_Free(self->begin_statement); - self->begin_statement = NULL; - } - - if (isolation_level == Py_None) { - Py_INCREF(Py_None); - self->isolation_level = Py_None; - - res = pydbsql_connection_commit(self, NULL); - if (!res) { - return -1; - } - Py_DECREF(res); - - self->inTransaction = 0; - } else { - Py_INCREF(isolation_level); - self->isolation_level = isolation_level; - - begin_statement = PyString_FromString("BEGIN "); - if (!begin_statement) { - return -1; - } - PyString_Concat(&begin_statement, isolation_level); - if (!begin_statement) { - return -1; - } - - self->begin_statement = PyMem_Malloc(PyString_Size(begin_statement) + 2); - if (!self->begin_statement) { - return -1; - } - - strcpy(self->begin_statement, PyString_AsString(begin_statement)); - Py_DECREF(begin_statement); - } - - return 0; -} - -PyObject* pydbsql_connection_call(pydbsql_Connection* self, PyObject* args, PyObject* kwargs) -{ - PyObject* sql; - pydbsql_Statement* statement; - PyObject* weakref; - int rc; - - if (!PyArg_ParseTuple(args, "O", &sql)) { - return NULL; - } - - _pydbsql_drop_unused_statement_references(self); - - statement = PyObject_New(pydbsql_Statement, &pydbsql_StatementType); - if (!statement) { - return NULL; - } - - rc = pydbsql_statement_create(statement, self, sql); - - if (rc != DBSQL_SUCCESS) { - if (rc == PYDBSQL_TOO_MUCH_SQL) { - PyErr_SetString(pydbsql_Warning, "You can only execute one statement at a time."); - } else if (rc == PYDBSQL_SQL_WRONG_TYPE) { - PyErr_SetString(pydbsql_Warning, "SQL is of wrong type. Must be string or unicode."); - } else { - _pydbsql_seterror(rc); - } - - Py_DECREF(statement); - statement = 0; - } else { - weakref = PyWeakref_NewRef((PyObject*)statement, NULL); - if (!weakref) { - Py_DECREF(statement); - statement = 0; - goto error; - } - - if (PyList_Append(self->statements, weakref) != 0) { - Py_DECREF(weakref); - statement = 0; - goto error; - } - - Py_DECREF(weakref); - } - -error: - return (PyObject*)statement; -} - -PyObject* pydbsql_connection_execute(pydbsql_Connection* self, PyObject* args, PyObject* kwargs) -{ - PyObject* cursor = 0; - PyObject* result = 0; - PyObject* method = 0; - - cursor = PyObject_CallMethod((PyObject*)self, "cursor", ""); - if (!cursor) { - goto error; - } - - method = PyObject_GetAttrString(cursor, "execute"); - if (!method) { - Py_DECREF(cursor); - cursor = 0; - goto error; - } - - result = PyObject_CallObject(method, args); - if (!result) { - Py_DECREF(cursor); - cursor = 0; - } - -error: - Py_XDECREF(result); - Py_XDECREF(method); - - return cursor; -} - -PyObject* pydbsql_connection_executemany(pydbsql_Connection* self, PyObject* args, PyObject* kwargs) -{ - PyObject* cursor = 0; - PyObject* result = 0; - PyObject* method = 0; - - cursor = PyObject_CallMethod((PyObject*)self, "cursor", ""); - if (!cursor) { - goto error; - } - - method = PyObject_GetAttrString(cursor, "executemany"); - if (!method) { - Py_DECREF(cursor); - cursor = 0; - goto error; - } - - result = PyObject_CallObject(method, args); - if (!result) { - Py_DECREF(cursor); - cursor = 0; - } - -error: - Py_XDECREF(result); - Py_XDECREF(method); - - return cursor; -} - -PyObject* pydbsql_connection_executescript(pydbsql_Connection* self, PyObject* args, PyObject* kwargs) -{ - PyObject* cursor = 0; - PyObject* result = 0; - PyObject* method = 0; - - cursor = PyObject_CallMethod((PyObject*)self, "cursor", ""); - if (!cursor) { - goto error; - } - - method = PyObject_GetAttrString(cursor, "executescript"); - if (!method) { - Py_DECREF(cursor); - cursor = 0; - goto error; - } - - result = PyObject_CallObject(method, args); - if (!result) { - Py_DECREF(cursor); - cursor = 0; - } - -error: - Py_XDECREF(result); - Py_XDECREF(method); - - return cursor; -} - -#if 0 -/* ------------------------- COLLATION CODE ------------------------ */ - -static int -pydbsql_collation_callback( - void* context, - int text1_length, const void* text1_data, - int text2_length, const void* text2_data) -{ - PyObject* callback = (PyObject*)context; - PyObject* string1 = 0; - PyObject* string2 = 0; - PyGILState_STATE gilstate; - - PyObject* retval = NULL; - int result = 0; - - gilstate = PyGILState_Ensure(); - - if (PyErr_Occurred()) { - goto finally; - } - - string1 = PyString_FromStringAndSize((const char*)text1_data, text1_length); - string2 = PyString_FromStringAndSize((const char*)text2_data, text2_length); - - if (!string1 || !string2) { - goto finally; /* failed to allocate strings */ - } - - retval = PyObject_CallFunctionObjArgs(callback, string1, string2, NULL); - - if (!retval) { - /* execution failed */ - goto finally; - } - - result = PyInt_AsLong(retval); - if (PyErr_Occurred()) { - result = 0; - } - -finally: - Py_XDECREF(string1); - Py_XDECREF(string2); - Py_XDECREF(retval); - - PyGILState_Release(gilstate); - - return result; -} -#endif - -static PyObject * -pydbsql_connection_interrupt(pydbsql_Connection* self, PyObject* args) -{ - PyObject* retval = NULL; - - if (!pydbsql_check_connection(self)) { - goto finally; - } - - self->db->interrupt(self->db); - - Py_INCREF(Py_None); - retval = Py_None; - -finally: - return retval; -} - -static PyObject * -pydbsql_connection_create_collation(pydbsql_Connection* self, PyObject* args) -{ - PyObject* callable; - PyObject* uppercase_name = 0; - PyObject* name; - PyObject* retval; - char* chk; - - if (!pydbsql_check_thread(self) || !pydbsql_check_connection(self)) { - goto finally; - } - - if (!PyArg_ParseTuple(args, "O!O:create_collation(name, callback)", &PyString_Type, &name, &callable)) { - goto finally; - } - - uppercase_name = PyObject_CallMethod(name, "upper", ""); - if (!uppercase_name) { - goto finally; - } - - chk = PyString_AsString(uppercase_name); - while (*chk) { - if ((*chk >= '0' && *chk <= '9') - || (*chk >= 'A' && *chk <= 'Z') - || (*chk == '_')) - { - chk++; - } else { - PyErr_SetString(pydbsql_ProgrammingError, "invalid character in collation name"); - goto finally; - } - } - - if (callable != Py_None && !PyCallable_Check(callable)) { - PyErr_SetString(PyExc_TypeError, "parameter must be callable"); - goto finally; - } - - if (callable != Py_None) { - PyDict_SetItem(self->collations, uppercase_name, callable); - } else { - PyDict_DelItem(self->collations, uppercase_name); - } - - -/* TODO: rc = self->db->create_collation(self->db, - PyString_AsString(uppercase_name), - DBSQL_UTF8, - (callable != Py_None) ? callable : NULL, - (callable != Py_None) ? pydbsql_collation_callback : NULL); - if (rc != DBSQL_SUCCESS) { - PyDict_DelItem(self->collations, uppercase_name); - _pydbsql_seterror(self->db); - goto finally; - } -*/ -finally: - Py_XDECREF(uppercase_name); - - if (PyErr_Occurred()) { - retval = NULL; - } else { - Py_INCREF(Py_None); - retval = Py_None; - } - - return retval; -} - -static char connection_doc[] = -PyDoc_STR("DBSQL database connection object."); - -static PyGetSetDef connection_getset[] = { - {"isolation_level", (getter)pydbsql_connection_get_isolation_level, (setter)pydbsql_connection_set_isolation_level}, - {"total_changes", (getter)pydbsql_connection_get_total_changes, (setter)0}, - {NULL} -}; - -static PyMethodDef connection_methods[] = { - {"cursor", (PyCFunction)pydbsql_connection_cursor, METH_VARARGS|METH_KEYWORDS, - PyDoc_STR("Return a cursor for the connection.")}, - {"close", (PyCFunction)pydbsql_connection_close, METH_NOARGS, - PyDoc_STR("Closes the connection.")}, - {"commit", (PyCFunction)pydbsql_connection_commit, METH_NOARGS, - PyDoc_STR("Commit the current transaction.")}, - {"rollback", (PyCFunction)pydbsql_connection_rollback, METH_NOARGS, - PyDoc_STR("Roll back the current transaction.")}, - {"create_function", (PyCFunction)pydbsql_connection_create_function, METH_VARARGS|METH_KEYWORDS, - PyDoc_STR("Creates a new function. Non-standard.")}, - {"create_aggregate", (PyCFunction)pydbsql_connection_create_aggregate, METH_VARARGS|METH_KEYWORDS, - PyDoc_STR("Creates a new aggregate. Non-standard.")}, - {"set_authorizer", (PyCFunction)pydbsql_connection_set_authorizer, METH_VARARGS|METH_KEYWORDS, - PyDoc_STR("Sets authorizer callback. Non-standard.")}, - {"execute", (PyCFunction)pydbsql_connection_execute, METH_VARARGS, - PyDoc_STR("Executes a SQL statement. Non-standard.")}, - {"executemany", (PyCFunction)pydbsql_connection_executemany, METH_VARARGS, - PyDoc_STR("Repeatedly executes a SQL statement. Non-standard.")}, - {"executescript", (PyCFunction)pydbsql_connection_executescript, METH_VARARGS, - PyDoc_STR("Executes a multiple SQL statements at once. Non-standard.")}, - {"create_collation", (PyCFunction)pydbsql_connection_create_collation, METH_VARARGS, - PyDoc_STR("Creates a collation function. Non-standard.")}, - {"interrupt", (PyCFunction)pydbsql_connection_interrupt, METH_NOARGS, - PyDoc_STR("Abort any pending database operation. Non-standard.")}, - {NULL, NULL} -}; - -static struct PyMemberDef connection_members[] = -{ - {"Warning", T_OBJECT, offsetof(pydbsql_Connection, Warning), RO}, - {"Error", T_OBJECT, offsetof(pydbsql_Connection, Error), RO}, - {"InterfaceError", T_OBJECT, offsetof(pydbsql_Connection, InterfaceError), RO}, - {"DatabaseError", T_OBJECT, offsetof(pydbsql_Connection, DatabaseError), RO}, - {"DataError", T_OBJECT, offsetof(pydbsql_Connection, DataError), RO}, - {"OperationalError", T_OBJECT, offsetof(pydbsql_Connection, OperationalError), RO}, - {"IntegrityError", T_OBJECT, offsetof(pydbsql_Connection, IntegrityError), RO}, - {"InternalError", T_OBJECT, offsetof(pydbsql_Connection, InternalError), RO}, - {"ProgrammingError", T_OBJECT, offsetof(pydbsql_Connection, ProgrammingError), RO}, - {"NotSupportedError", T_OBJECT, offsetof(pydbsql_Connection, NotSupportedError), RO}, - {"row_factory", T_OBJECT, offsetof(pydbsql_Connection, row_factory)}, - {"text_factory", T_OBJECT, offsetof(pydbsql_Connection, text_factory)}, - {NULL} -}; - -PyTypeObject pydbsql_ConnectionType = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - MODULE_NAME ".Connection", /* tp_name */ - sizeof(pydbsql_Connection), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)pydbsql_connection_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)pydbsql_connection_call, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */ - connection_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - connection_methods, /* tp_methods */ - connection_members, /* tp_members */ - connection_getset, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)pydbsql_connection_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0 /* tp_free */ -}; - -extern int pydbsql_connection_setup_types(void) -{ - pydbsql_ConnectionType.tp_new = PyType_GenericNew; - return PyType_Ready(&pydbsql_ConnectionType); -} diff --git a/src/py/src/cursor.c b/src/py/src/cursor.c index 0239555..e69de29 100644 --- a/src/py/src/cursor.c +++ b/src/py/src/cursor.c @@ -1,1091 +0,0 @@ -/*- - * DBSQL - A SQL database engine. - * - * Copyright (C) 2007 DBSQL Group, Inc - All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * There are special exceptions to the terms and conditions of the GPL as it - * is applied to this software. View the full text of the exception in file - * LICENSE_EXCEPTIONS in the directory of this software distribution. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * http://creativecommons.org/licenses/GPL/2.0/ - * - * $Id: api.c 7 2007-02-03 13:34:17Z gburd $ - */ - -/* cursor.c - the cursor type - * - * Copyright (C) 2004-2006 Gerhard Häring - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -#include "cursor.h" -#include "module.h" -#include "util.h" -#include "dbsqlcompat.h" - -/* used to decide wether to call PyInt_FromLong or PyLong_FromLongLong */ -#ifndef INT32_MIN -#define INT32_MIN (-2147483647 - 1) -#endif -#ifndef INT32_MAX -#define INT32_MAX 2147483647 -#endif - -PyObject* pydbsql_cursor_iternext(pydbsql_Cursor* self); - -static pydbsql_StatementKind detect_statement_type(char* statement) -{ - char buf[20]; - char* src; - char* dst; - - src = statement; - /* skip over whitepace */ - while (*src == '\r' || *src == '\n' || *src == ' ' || *src == '\t') { - src++; - } - - if (*src == 0) - return STATEMENT_INVALID; - - dst = buf; - *dst = 0; - while (isalpha(*src) && dst - buf < sizeof(buf) - 2) { - *dst++ = tolower(*src++); - } - - *dst = 0; - - if (!strcmp(buf, "select")) { - return STATEMENT_SELECT; - } else if (!strcmp(buf, "insert")) { - return STATEMENT_INSERT; - } else if (!strcmp(buf, "update")) { - return STATEMENT_UPDATE; - } else if (!strcmp(buf, "delete")) { - return STATEMENT_DELETE; - } else if (!strcmp(buf, "replace")) { - return STATEMENT_REPLACE; - } else { - return STATEMENT_OTHER; - } -} - -int pydbsql_cursor_init(pydbsql_Cursor* self, PyObject* args, PyObject* kwargs) -{ - pydbsql_Connection* connection; - - if (!PyArg_ParseTuple(args, "O!", &pydbsql_ConnectionType, &connection)) - { - return -1; - } - - Py_INCREF(connection); - self->connection = connection; - self->statement = NULL; - self->next_row = NULL; - - self->row_cast_map = PyList_New(0); - if (!self->row_cast_map) { - return -1; - } - - Py_INCREF(Py_None); - self->description = Py_None; - - Py_INCREF(Py_None); - self->lastrowid= Py_None; - - self->arraysize = 1; - - self->rowcount = PyInt_FromLong(-1L); - if (!self->rowcount) { - return -1; - } - - Py_INCREF(Py_None); - self->row_factory = Py_None; - - if (!pydbsql_check_thread(self->connection)) { - return -1; - } - - return 0; -} - -void pydbsql_cursor_dealloc(pydbsql_Cursor* self) -{ - int rc; - - /* Reset the statement if the user has not closed the cursor */ - if (self->statement) { - rc = pydbsql_statement_reset(self->statement); - Py_DECREF(self->statement); - } - - Py_XDECREF(self->connection); - Py_XDECREF(self->row_cast_map); - Py_XDECREF(self->description); - Py_XDECREF(self->lastrowid); - Py_XDECREF(self->rowcount); - Py_XDECREF(self->row_factory); - Py_XDECREF(self->next_row); - - self->ob_type->tp_free((PyObject*)self); -} - -PyObject* _pydbsql_get_converter(PyObject* key) -{ - PyObject* upcase_key; - PyObject* retval; - - upcase_key = PyObject_CallMethod(key, "upper", ""); - if (!upcase_key) { - return NULL; - } - - retval = PyDict_GetItem(converters, upcase_key); - Py_DECREF(upcase_key); - - return retval; -} - -int pydbsql_build_row_cast_map(pydbsql_Cursor* self) -{ - int i; - const char* type_start = (const char*)-1; - const char* pos; - - const char* colname; - const char* decltype; - PyObject* py_decltype; - PyObject* converter; - PyObject* key; - - if (!self->connection->detect_types) { - return 0; - } - - Py_XDECREF(self->row_cast_map); - self->row_cast_map = PyList_New(0); - - for (i = 0; i < dbsql_column_count(self->statement->st); i++) { - converter = NULL; - - if (self->connection->detect_types & PARSE_COLNAMES) { - colname = dbsql_column_name(self->statement->st, i); - if (colname) { - for (pos = colname; *pos != 0; pos++) { - if (*pos == '[') { - type_start = pos + 1; - } else if (*pos == ']' && type_start != (const char*)-1) { - key = PyString_FromStringAndSize(type_start, pos - type_start); - if (!key) { - /* creating a string failed, but it is too complicated - * to propagate the error here, we just assume there is - * no converter and proceed */ - break; - } - - converter = _pydbsql_get_converter(key); - Py_DECREF(key); - break; - } - } - } - } - - if (!converter && self->connection->detect_types & PARSE_DECLTYPES) { - decltype = dbsql_column_decltype(self->statement->st, i); - if (decltype) { - for (pos = decltype;;pos++) { - if (*pos == ' ' || *pos == 0) { - py_decltype = PyString_FromStringAndSize(decltype, pos - decltype); - if (!py_decltype) { - return -1; - } - break; - } - } - - converter = _pydbsql_get_converter(py_decltype); - Py_DECREF(py_decltype); - } - } - - if (!converter) { - converter = Py_None; - } - - if (PyList_Append(self->row_cast_map, converter) != 0) { - if (converter != Py_None) { - Py_DECREF(converter); - } - Py_XDECREF(self->row_cast_map); - self->row_cast_map = NULL; - - return -1; - } - } - - return 0; -} - -PyObject* _pydbsql_build_column_name(const char* colname) -{ - const char* pos; - - if (!colname) { - Py_INCREF(Py_None); - return Py_None; - } - - for (pos = colname;; pos++) { - if (*pos == 0 || *pos == '[') { - if ((*pos == '[') && (pos > colname) && (*(pos-1) == ' ')) { - pos--; - } - return PyString_FromStringAndSize(colname, pos - colname); - } - } -} - -PyObject* pydbsql_unicode_from_string(const char* val_str, int optimize) -{ - const char* check; - int is_ascii = 0; - - if (optimize) { - is_ascii = 1; - - check = val_str; - while (*check) { - if (*check & 0x80) { - is_ascii = 0; - break; - } - - check++; - } - } - - if (is_ascii) { - return PyString_FromString(val_str); - } else { - return PyUnicode_DecodeUTF8(val_str, strlen(val_str), NULL); - } -} - -/* - * Returns a row from the currently active DBSQL statement - * - * Precondidition: - * - dbsql_step() has been called before and it returned DBSQL_ROW. - */ -PyObject* _pydbsql_fetch_one_row(pydbsql_Cursor* self) -{ - int i, numcols; - PyObject* row; - PyObject* item = NULL; - int coltype; - PY_LONG_LONG intval; - PyObject* converter; - PyObject* converted; - Py_ssize_t nbytes; - PyObject* buffer; - void* raw_buffer; - const char* val_str; - char buf[200]; - const char* colname; - - Py_BEGIN_ALLOW_THREADS - numcols = dbsql_data_count(self->statement->st); - Py_END_ALLOW_THREADS - - row = PyTuple_New(numcols); - if (!row) { - return NULL; - } - - for (i = 0; i < numcols; i++) { - if (self->connection->detect_types) { - converter = PyList_GetItem(self->row_cast_map, i); - if (!converter) { - converter = Py_None; - } - } else { - converter = Py_None; - } - - if (converter != Py_None) { - nbytes = dbsql_column_bytes(self->statement->st, i); - val_str = (const char*)dbsql_column_blob(self->statement->st, i); - if (!val_str) { - Py_INCREF(Py_None); - converted = Py_None; - } else { - item = PyString_FromStringAndSize(val_str, nbytes); - if (!item) { - return NULL; - } - converted = PyObject_CallFunction(converter, "O", item); - Py_DECREF(item); - if (!converted) { - break; - } - } - } else { - Py_BEGIN_ALLOW_THREADS - coltype = dbsql_column_type(self->statement->st, i); - Py_END_ALLOW_THREADS - if (coltype == DBSQL_NULL) { - Py_INCREF(Py_None); - converted = Py_None; - } else if (coltype == DBSQL_INTEGER) { - intval = dbsql_column_int64(self->statement->st, i); - if (intval < INT32_MIN || intval > INT32_MAX) { - converted = PyLong_FromLongLong(intval); - } else { - converted = PyInt_FromLong((long)intval); - } - } else if (coltype == DBSQL_FLOAT) { - converted = PyFloat_FromDouble(dbsql_column_double(self->statement->st, i)); - } else if (coltype == DBSQL_TEXT) { - val_str = (const char*)dbsql_column_text(self->statement->st, i); - if ((self->connection->text_factory == (PyObject*)&PyUnicode_Type) - || (self->connection->text_factory == pydbsql_OptimizedUnicode)) { - - converted = pydbsql_unicode_from_string(val_str, - self->connection->text_factory == pydbsql_OptimizedUnicode ? 1 : 0); - - if (!converted) { - colname = dbsql_column_name(self->statement->st, i); - if (!colname) { - colname = ""; - } - PyOS_snprintf(buf, sizeof(buf) - 1, "Could not decode to UTF-8 column '%s' with text '%s'", - colname , val_str); - PyErr_SetString(pydbsql_OperationalError, buf); - } - } else if (self->connection->text_factory == (PyObject*)&PyString_Type) { - converted = PyString_FromString(val_str); - } else { - converted = PyObject_CallFunction(self->connection->text_factory, "s", val_str); - } - } else { - /* coltype == DBSQL_BLOB */ - nbytes = dbsql_column_bytes(self->statement->st, i); - buffer = PyBuffer_New(nbytes); - if (!buffer) { - break; - } - if (PyObject_AsWriteBuffer(buffer, &raw_buffer, &nbytes)) { - break; - } - memcpy(raw_buffer, dbsql_column_blob(self->statement->st, i), nbytes); - converted = buffer; - } - } - - if (converted) { - PyTuple_SetItem(row, i, converted); - } else { - Py_INCREF(Py_None); - PyTuple_SetItem(row, i, Py_None); - } - } - - if (PyErr_Occurred()) { - Py_DECREF(row); - row = NULL; - } - - return row; -} - -PyObject* _pydbsql_query_execute(pydbsql_Cursor* self, int multiple, PyObject* args) -{ - PyObject* operation; - PyObject* operation_bytestr = NULL; - char* operation_cstr; - PyObject* parameters_list = NULL; - PyObject* parameters_iter = NULL; - PyObject* parameters = NULL; - int i; - int rc; - PyObject* func_args; - PyObject* result; - int numcols; - PY_LONG_LONG lastrowid; - int statement_type; - PyObject* descriptor; - PyObject* second_argument = NULL; - long rowcount = 0; - - if (!pydbsql_check_thread(self->connection) || !pydbsql_check_connection(self->connection)) { - return NULL; - } - - Py_XDECREF(self->next_row); - self->next_row = NULL; - - if (multiple) { - /* executemany() */ - if (!PyArg_ParseTuple(args, "OO", &operation, &second_argument)) { - return NULL; - } - - if (!PyString_Check(operation) && !PyUnicode_Check(operation)) { - PyErr_SetString(PyExc_ValueError, "operation parameter must be str or unicode"); - return NULL; - } - - if (PyIter_Check(second_argument)) { - /* iterator */ - Py_INCREF(second_argument); - parameters_iter = second_argument; - } else { - /* sequence */ - parameters_iter = PyObject_GetIter(second_argument); - if (!parameters_iter) { - return NULL; - } - } - } else { - /* execute() */ - if (!PyArg_ParseTuple(args, "O|O", &operation, &second_argument)) { - return NULL; - } - - if (!PyString_Check(operation) && !PyUnicode_Check(operation)) { - PyErr_SetString(PyExc_ValueError, "operation parameter must be str or unicode"); - return NULL; - } - - parameters_list = PyList_New(0); - if (!parameters_list) { - return NULL; - } - - if (second_argument == NULL) { - second_argument = PyTuple_New(0); - if (!second_argument) { - goto error; - } - } else { - Py_INCREF(second_argument); - } - if (PyList_Append(parameters_list, second_argument) != 0) { - Py_DECREF(second_argument); - goto error; - } - Py_DECREF(second_argument); - - parameters_iter = PyObject_GetIter(parameters_list); - if (!parameters_iter) { - goto error; - } - } - - if (self->statement != NULL) { - /* There is an active statement */ - rc = pydbsql_statement_reset(self->statement); - } - - if (PyString_Check(operation)) { - operation_cstr = PyString_AsString(operation); - } else { - operation_bytestr = PyUnicode_AsUTF8String(operation); - if (!operation_bytestr) { - goto error; - } - - operation_cstr = PyString_AsString(operation_bytestr); - } - - /* reset description and rowcount */ - Py_DECREF(self->description); - Py_INCREF(Py_None); - self->description = Py_None; - - Py_DECREF(self->rowcount); - self->rowcount = PyInt_FromLong(-1L); - if (!self->rowcount) { - goto error; - } - - statement_type = detect_statement_type(operation_cstr); - if (self->connection->begin_statement) { - switch (statement_type) { - case STATEMENT_UPDATE: - case STATEMENT_DELETE: - case STATEMENT_INSERT: - case STATEMENT_REPLACE: - if (!self->connection->inTransaction) { - result = _pydbsql_connection_begin(self->connection); - if (!result) { - goto error; - } - Py_DECREF(result); - } - break; - case STATEMENT_OTHER: - /* it's a DDL statement or something similar - - we better COMMIT first so it works for all cases */ - if (self->connection->inTransaction) { - result = pydbsql_connection_commit(self->connection, NULL); - if (!result) { - goto error; - } - Py_DECREF(result); - } - break; - case STATEMENT_SELECT: - if (multiple) { - PyErr_SetString(pydbsql_ProgrammingError, - "You cannot execute SELECT statements in executemany()."); - goto error; - } - break; - } - } - - func_args = PyTuple_New(1); - if (!func_args) { - goto error; - } - Py_INCREF(operation); - if (PyTuple_SetItem(func_args, 0, operation) != 0) { - goto error; - } - - if (self->statement) { - (void)pydbsql_statement_reset(self->statement); - Py_DECREF(self->statement); - } - - self->statement = (pydbsql_Statement*)pydbsql_cache_get(self->connection->statement_cache, func_args); - Py_DECREF(func_args); - - if (!self->statement) { - goto error; - } - - if (self->statement->in_use) { - Py_DECREF(self->statement); - self->statement = PyObject_New(pydbsql_Statement, &pydbsql_StatementType); - if (!self->statement) { - goto error; - } - rc = pydbsql_statement_create(self->statement, self->connection, operation); - if (rc != DBSQL_SUCCESS) { - self->statement = 0; - goto error; - } - } - - pydbsql_statement_reset(self->statement); - pydbsql_statement_mark_dirty(self->statement); - - while (1) { - parameters = PyIter_Next(parameters_iter); - if (!parameters) { - break; - } - - pydbsql_statement_mark_dirty(self->statement); - - pydbsql_statement_bind_parameters(self->statement, parameters); - if (PyErr_Occurred()) { - goto error; - } - - if (pydbsql_build_row_cast_map(self) != 0) { - PyErr_SetString(pydbsql_OperationalError, "Error while building row_cast_map"); - goto error; - } - - /* Keep trying the SQL statement until the schema stops changing. */ - while (1) { - /* Actually execute the SQL statement. */ - rc = _dbsql_step_with_busyhandler(self->statement->st, self->connection); - if (rc == DBSQL_DONE || rc == DBSQL_ROW) { - /* If it worked, let's get out of the loop */ - break; - } - /* Something went wrong. Re-set the statement and try again. */ - rc = pydbsql_statement_reset(self->statement); - if (rc == DBSQL_SCHEMA) { - /* If this was a result of the schema changing, let's try - again. */ - rc = pydbsql_statement_recompile(self->statement, parameters); - if (rc == DBSQL_SUCCESS) { - continue; - } else { - /* If the database gave us an error, promote it to Python. */ - _pydbsql_seterror(self->connection->db); - goto error; - } - } else { - if (PyErr_Occurred()) { - /* there was an error that occurred in a user-defined callback */ - if (_enable_callback_tracebacks) { - PyErr_Print(); - } else { - PyErr_Clear(); - } - } - _pydbsql_seterror(self->connection->db); - goto error; - } - } - - if (rc == DBSQL_ROW || (rc == DBSQL_DONE && statement_type == STATEMENT_SELECT)) { - Py_BEGIN_ALLOW_THREADS - numcols = dbsql_column_count(self->statement->st); - Py_END_ALLOW_THREADS - - if (self->description == Py_None) { - Py_DECREF(self->description); - self->description = PyTuple_New(numcols); - if (!self->description) { - goto error; - } - for (i = 0; i < numcols; i++) { - descriptor = PyTuple_New(7); - if (!descriptor) { - goto error; - } - PyTuple_SetItem(descriptor, 0, _pydbsql_build_column_name(dbsql_column_name(self->statement->st, i))); - Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 1, Py_None); - Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 2, Py_None); - Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 3, Py_None); - Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 4, Py_None); - Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 5, Py_None); - Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 6, Py_None); - PyTuple_SetItem(self->description, i, descriptor); - } - } - } - - if (rc == DBSQL_ROW) { - if (multiple) { - PyErr_SetString(pydbsql_ProgrammingError, "executemany() can only execute DML statements."); - goto error; - } - - self->next_row = _pydbsql_fetch_one_row(self); - } else if (rc == DBSQL_DONE && !multiple) { - pydbsql_statement_reset(self->statement); - Py_DECREF(self->statement); - self->statement = 0; - } - - switch (statement_type) { - case STATEMENT_UPDATE: - case STATEMENT_DELETE: - case STATEMENT_INSERT: - case STATEMENT_REPLACE: - Py_BEGIN_ALLOW_THREADS - rowcount += (long)dbsql_changes(self->connection->db); - Py_END_ALLOW_THREADS - Py_DECREF(self->rowcount); - self->rowcount = PyInt_FromLong(rowcount); - } - - Py_DECREF(self->lastrowid); - if (statement_type == STATEMENT_INSERT) { - Py_BEGIN_ALLOW_THREADS - lastrowid = dbsql_last_insert_rowid(self->connection->db); - Py_END_ALLOW_THREADS - self->lastrowid = PyInt_FromLong((long)lastrowid); - } else { - Py_INCREF(Py_None); - self->lastrowid = Py_None; - } - - if (multiple) { - rc = pydbsql_statement_reset(self->statement); - } - Py_XDECREF(parameters); - } - -error: - Py_XDECREF(operation_bytestr); - Py_XDECREF(parameters); - Py_XDECREF(parameters_iter); - Py_XDECREF(parameters_list); - - if (PyErr_Occurred()) { - return NULL; - } else { - Py_INCREF(self); - return (PyObject*)self; - } -} - -PyObject* pydbsql_cursor_execute(pydbsql_Cursor* self, PyObject* args) -{ - return _pydbsql_query_execute(self, 0, args); -} - -PyObject* pydbsql_cursor_executemany(pydbsql_Cursor* self, PyObject* args) -{ - return _pydbsql_query_execute(self, 1, args); -} - -PyObject* pydbsql_cursor_executescript(pydbsql_Cursor* self, PyObject* args) -{ - PyObject* script_obj; - PyObject* script_str = NULL; - const char* script_cstr; - dbsql_stmt_t* statement; - int rc; - PyObject* result; - int statement_completed = 0; - - if (!PyArg_ParseTuple(args, "O", &script_obj)) { - return NULL; - } - - if (!pydbsql_check_thread(self->connection) || !pydbsql_check_connection(self->connection)) { - return NULL; - } - - if (PyString_Check(script_obj)) { - script_cstr = PyString_AsString(script_obj); - } else if (PyUnicode_Check(script_obj)) { - script_str = PyUnicode_AsUTF8String(script_obj); - if (!script_str) { - return NULL; - } - - script_cstr = PyString_AsString(script_str); - } else { - PyErr_SetString(PyExc_ValueError, "script argument must be unicode or string."); - return NULL; - } - - /* commit first */ - result = pydbsql_connection_commit(self->connection, NULL); - if (!result) { - goto error; - } - Py_DECREF(result); - - while (1) { - if (!dbsql_complete(script_cstr)) { - break; - } - statement_completed = 1; - - rc = dbsql_prepare(self->connection->db, - script_cstr, - -1, - &statement, - &script_cstr); - if (rc != DBSQL_SUCCESS) { - _pydbsql_seterror(self->connection->db); - goto error; - } - - /* execute statement, and ignore results of SELECT statements */ - rc = DBSQL_ROW; - while (rc == DBSQL_ROW) { - rc = _dbsql_step_with_busyhandler(statement, self->connection); - } - - if (rc != DBSQL_DONE) { - (void)dbsql_finalize(statement); - _pydbsql_seterror(self->connection->db); - goto error; - } - - rc = dbsql_finalize(statement); - if (rc != DBSQL_SUCCESS) { - _pydbsql_seterror(self->connection->db); - goto error; - } - } - -error: - Py_XDECREF(script_str); - - if (!statement_completed) { - PyErr_SetString(pydbsql_ProgrammingError, "you did not provide a complete SQL statement"); - } - - if (PyErr_Occurred()) { - return NULL; - } else { - Py_INCREF(self); - return (PyObject*)self; - } -} - -PyObject* pydbsql_cursor_getiter(pydbsql_Cursor *self) -{ - Py_INCREF(self); - return (PyObject*)self; -} - -PyObject* pydbsql_cursor_iternext(pydbsql_Cursor *self) -{ - PyObject* next_row_tuple; - PyObject* next_row; - int rc; - - if (!pydbsql_check_thread(self->connection) || !pydbsql_check_connection(self->connection)) { - return NULL; - } - - if (!self->next_row) { - if (self->statement) { - (void)pydbsql_statement_reset(self->statement); - Py_DECREF(self->statement); - self->statement = NULL; - } - return NULL; - } - - next_row_tuple = self->next_row; - self->next_row = NULL; - - if (self->row_factory != Py_None) { - next_row = PyObject_CallFunction(self->row_factory, "OO", self, next_row_tuple); - Py_DECREF(next_row_tuple); - } else { - next_row = next_row_tuple; - } - - if (self->statement) { - rc = _dbsql_step_with_busyhandler(self->statement->st, self->connection); - if (rc != DBSQL_DONE && rc != DBSQL_ROW) { - Py_DECREF(next_row); - _pydbsql_seterror(self->connection->db); - return NULL; - } - - if (rc == DBSQL_ROW) { - self->next_row = _pydbsql_fetch_one_row(self); - } - } - - return next_row; -} - -PyObject* pydbsql_cursor_fetchone(pydbsql_Cursor* self, PyObject* args) -{ - PyObject* row; - - row = pydbsql_cursor_iternext(self); - if (!row && !PyErr_Occurred()) { - Py_INCREF(Py_None); - return Py_None; - } - - return row; -} - -PyObject* pydbsql_cursor_fetchmany(pydbsql_Cursor* self, PyObject* args) -{ - PyObject* row; - PyObject* list; - int maxrows = self->arraysize; - int counter = 0; - - if (!PyArg_ParseTuple(args, "|i", &maxrows)) { - return NULL; - } - - list = PyList_New(0); - if (!list) { - return NULL; - } - - /* just make sure we enter the loop */ - row = Py_None; - - while (row) { - row = pydbsql_cursor_iternext(self); - if (row) { - PyList_Append(list, row); - Py_DECREF(row); - } else { - break; - } - - if (++counter == maxrows) { - break; - } - } - - if (PyErr_Occurred()) { - Py_DECREF(list); - return NULL; - } else { - return list; - } -} - -PyObject* pydbsql_cursor_fetchall(pydbsql_Cursor* self, PyObject* args) -{ - PyObject* row; - PyObject* list; - - list = PyList_New(0); - if (!list) { - return NULL; - } - - /* just make sure we enter the loop */ - row = (PyObject*)Py_None; - - while (row) { - row = pydbsql_cursor_iternext(self); - if (row) { - PyList_Append(list, row); - Py_DECREF(row); - } - } - - if (PyErr_Occurred()) { - Py_DECREF(list); - return NULL; - } else { - return list; - } -} - -PyObject* pydbsql_noop(pydbsql_Connection* self, PyObject* args) -{ - /* don't care, return None */ - Py_INCREF(Py_None); - return Py_None; -} - -PyObject* pydbsql_cursor_close(pydbsql_Cursor* self, PyObject* args) -{ - if (!pydbsql_check_thread(self->connection) || !pydbsql_check_connection(self->connection)) { - return NULL; - } - - if (self->statement) { - (void)pydbsql_statement_reset(self->statement); - Py_DECREF(self->statement); - self->statement = 0; - } - - Py_INCREF(Py_None); - return Py_None; -} - -static PyMethodDef cursor_methods[] = { - {"execute", (PyCFunction)pydbsql_cursor_execute, METH_VARARGS, - PyDoc_STR("Executes a SQL statement.")}, - {"executemany", (PyCFunction)pydbsql_cursor_executemany, METH_VARARGS, - PyDoc_STR("Repeatedly executes a SQL statement.")}, - {"executescript", (PyCFunction)pydbsql_cursor_executescript, METH_VARARGS, - PyDoc_STR("Executes a multiple SQL statements at once. Non-standard.")}, - {"fetchone", (PyCFunction)pydbsql_cursor_fetchone, METH_NOARGS, - PyDoc_STR("Fetches several rows from the resultset.")}, - {"fetchmany", (PyCFunction)pydbsql_cursor_fetchmany, METH_VARARGS, - PyDoc_STR("Fetches all rows from the resultset.")}, - {"fetchall", (PyCFunction)pydbsql_cursor_fetchall, METH_NOARGS, - PyDoc_STR("Fetches one row from the resultset.")}, - {"close", (PyCFunction)pydbsql_cursor_close, METH_NOARGS, - PyDoc_STR("Closes the cursor.")}, - {"setinputsizes", (PyCFunction)pydbsql_noop, METH_VARARGS, - PyDoc_STR("Required by DB-API. Does nothing in pydbsql.")}, - {"setoutputsize", (PyCFunction)pydbsql_noop, METH_VARARGS, - PyDoc_STR("Required by DB-API. Does nothing in pydbsql.")}, - {NULL, NULL} -}; - -static struct PyMemberDef cursor_members[] = -{ - {"connection", T_OBJECT, offsetof(pydbsql_Cursor, connection), RO}, - {"description", T_OBJECT, offsetof(pydbsql_Cursor, description), RO}, - {"arraysize", T_INT, offsetof(pydbsql_Cursor, arraysize), 0}, - {"lastrowid", T_OBJECT, offsetof(pydbsql_Cursor, lastrowid), RO}, - {"rowcount", T_OBJECT, offsetof(pydbsql_Cursor, rowcount), RO}, - {"row_factory", T_OBJECT, offsetof(pydbsql_Cursor, row_factory), 0}, - {NULL} -}; - -static char cursor_doc[] = -PyDoc_STR("DBSQL database cursor class."); - -PyTypeObject pydbsql_CursorType = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - MODULE_NAME ".Cursor", /* tp_name */ - sizeof(pydbsql_Cursor), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)pydbsql_cursor_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_ITER|Py_TPFLAGS_BASETYPE, /* tp_flags */ - cursor_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc)pydbsql_cursor_getiter, /* tp_iter */ - (iternextfunc)pydbsql_cursor_iternext, /* tp_iternext */ - cursor_methods, /* tp_methods */ - cursor_members, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)pydbsql_cursor_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0 /* tp_free */ -}; - -extern int pydbsql_cursor_setup_types(void) -{ - pydbsql_CursorType.tp_new = PyType_GenericNew; - return PyType_Ready(&pydbsql_CursorType); -} diff --git a/src/py/src/module.c b/src/py/src/module.c index 5a3fe46..e69de29 100644 --- a/src/py/src/module.c +++ b/src/py/src/module.c @@ -1,422 +0,0 @@ -/*- - * DBSQL - A SQL database engine. - * - * Copyright (C) 2007 DBSQL Group, Inc - All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * There are special exceptions to the terms and conditions of the GPL as it - * is applied to this software. View the full text of the exception in file - * LICENSE_EXCEPTIONS in the directory of this software distribution. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * http://creativecommons.org/licenses/GPL/2.0/ - * - * $Id: api.c 7 2007-02-03 13:34:17Z gburd $ - */ - -/* module.c - the module itself - * - * Copyright (C) 2004-2006 Gerhard Häring - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -#include "connection.h" -#include "statement.h" -#include "cursor.h" -#include "cache.h" -#include "prepare_protocol.h" -#include "microprotocols.h" -#include "row.h" - -#if DBSQL_VERSION_NUMBER >= 3003003 -#define HAVE_SHARED_CACHE -#endif - -/* static objects at module-level */ - -PyObject* pydbsql_Error, *pydbsql_Warning, *pydbsql_InterfaceError, *pydbsql_DatabaseError, - *pydbsql_InternalError, *pydbsql_OperationalError, *pydbsql_ProgrammingError, - *pydbsql_IntegrityError, *pydbsql_DataError, *pydbsql_NotSupportedError, *pydbsql_OptimizedUnicode; - -PyObject* converters; -int _enable_callback_tracebacks; - -static PyObject* module_connect(PyObject* self, PyObject* args, PyObject* - kwargs) -{ - /* Python seems to have no way of extracting a single keyword-arg at - * C-level, so this code is redundant with the one in connection_init in - * connection.c and must always be copied from there ... */ - - static char *kwlist[] = {"database", "timeout", "detect_types", "isolation_level", "check_same_thread", "factory", "cached_statements", NULL, NULL}; - char* database; - int detect_types = 0; - PyObject* isolation_level; - PyObject* factory = NULL; - int check_same_thread = 1; - int cached_statements; - double timeout = 5.0; - - PyObject* result; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|diOiOi", kwlist, - &database, &timeout, &detect_types, &isolation_level, &check_same_thread, &factory, &cached_statements)) - { - return NULL; - } - - if (factory == NULL) { - factory = (PyObject*)&pydbsql_ConnectionType; - } - - result = PyObject_Call(factory, args, kwargs); - - return result; -} - -static PyObject* module_complete(PyObject* self, PyObject* args, PyObject* - kwargs) -{ - static char *kwlist[] = {"statement", NULL, NULL}; - char* statement; - - PyObject* result; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist, &statement)) - { - return NULL; - } - - if (dbsql_complete_stmt(statement)) { - result = Py_True; - } else { - result = Py_False; - } - - Py_INCREF(result); - - return result; -} - -#ifdef HAVE_SHARED_CACHE -static PyObject* module_enable_shared_cache(PyObject* self, PyObject* args, PyObject* - kwargs) -{ - static char *kwlist[] = {"do_enable", NULL, NULL}; - int do_enable; - int rc; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &do_enable)) - { - return NULL; - } - - rc = dbsql_enable_shared_cache(do_enable); - - if (rc != DBSQL_SUCCESS) { - PyErr_SetString(pydbsql_OperationalError, "Changing the shared_cache flag failed"); - return NULL; - } else { - Py_INCREF(Py_None); - return Py_None; - } -} -#endif /* HAVE_SHARED_CACHE */ - -static PyObject* module_register_adapter(PyObject* self, PyObject* args, PyObject* kwargs) -{ - PyTypeObject* type; - PyObject* caster; - - if (!PyArg_ParseTuple(args, "OO", &type, &caster)) { - return NULL; - } - - microprotocols_add(type, (PyObject*)&pydbsql_PrepareProtocolType, caster); - - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject* module_register_converter(PyObject* self, PyObject* args, PyObject* kwargs) -{ - PyObject* orig_name; - PyObject* name = NULL; - PyObject* callable; - PyObject* retval = NULL; - - if (!PyArg_ParseTuple(args, "SO", &orig_name, &callable)) { - return NULL; - } - - /* convert the name to upper case */ - name = PyObject_CallMethod(orig_name, "upper", ""); - if (!name) { - goto error; - } - - if (PyDict_SetItem(converters, name, callable) != 0) { - goto error; - } - - Py_INCREF(Py_None); - retval = Py_None; -error: - Py_XDECREF(name); - return retval; -} - -static PyObject* enable_callback_tracebacks(PyObject* self, PyObject* args, PyObject* kwargs) -{ - if (!PyArg_ParseTuple(args, "i", &_enable_callback_tracebacks)) { - return NULL; - } - - Py_INCREF(Py_None); - return Py_None; -} - -static void converters_init(PyObject* dict) -{ - converters = PyDict_New(); - if (!converters) { - return; - } - - PyDict_SetItemString(dict, "converters", converters); -} - -static PyMethodDef module_methods[] = { - {"connect", (PyCFunction)module_connect, METH_VARARGS|METH_KEYWORDS, PyDoc_STR("Creates a connection.")}, - {"complete_statement", (PyCFunction)module_complete, METH_VARARGS|METH_KEYWORDS, PyDoc_STR("Checks if a string contains a complete SQL statement. Non-standard.")}, -#ifdef HAVE_SHARED_CACHE - {"enable_shared_cache", (PyCFunction)module_enable_shared_cache, METH_VARARGS|METH_KEYWORDS, PyDoc_STR("Enable or disable shared cache mode for the calling thread. Experimental/Non-standard.")}, -#endif - {"register_adapter", (PyCFunction)module_register_adapter, METH_VARARGS, PyDoc_STR("Registers an adapter with pydbsql's adapter registry. Non-standard.")}, - {"register_converter", (PyCFunction)module_register_converter, METH_VARARGS, PyDoc_STR("Registers a converter with pydbsql. Non-standard.")}, - {"adapt", (PyCFunction)psyco_microprotocols_adapt, METH_VARARGS, psyco_microprotocols_adapt_doc}, - {"enable_callback_tracebacks", (PyCFunction)enable_callback_tracebacks, METH_VARARGS, PyDoc_STR("Enable or disable callback functions throwing errors to stderr.")}, - {NULL, NULL} -}; - -struct _IntConstantPair { - char* constant_name; - int constant_value; -}; - -typedef struct _IntConstantPair IntConstantPair; - -static IntConstantPair _int_constants[] = { - {"PARSE_DECLTYPES", PARSE_DECLTYPES}, - {"PARSE_COLNAMES", PARSE_COLNAMES}, - - {"DBSQL_SUCCESS", DBSQL_SUCCESS}, - {"DBSQL_DENY", DBSQL_DENY}, - {"DBSQL_IGNORE", DBSQL_IGNORE}, - {"DBSQL_CREATE_INDEX", DBSQL_CREATE_INDEX}, - {"DBSQL_CREATE_TABLE", DBSQL_CREATE_TABLE}, - {"DBSQL_CREATE_TEMP_INDEX", DBSQL_CREATE_TEMP_INDEX}, - {"DBSQL_CREATE_TEMP_TABLE", DBSQL_CREATE_TEMP_TABLE}, - {"DBSQL_CREATE_TEMP_TRIGGER", DBSQL_CREATE_TEMP_TRIGGER}, - {"DBSQL_CREATE_TEMP_VIEW", DBSQL_CREATE_TEMP_VIEW}, - {"DBSQL_CREATE_TRIGGER", DBSQL_CREATE_TRIGGER}, - {"DBSQL_CREATE_VIEW", DBSQL_CREATE_VIEW}, - {"DBSQL_DELETE", DBSQL_DELETE}, - {"DBSQL_DROP_INDEX", DBSQL_DROP_INDEX}, - {"DBSQL_DROP_TABLE", DBSQL_DROP_TABLE}, - {"DBSQL_DROP_TEMP_INDEX", DBSQL_DROP_TEMP_INDEX}, - {"DBSQL_DROP_TEMP_TABLE", DBSQL_DROP_TEMP_TABLE}, - {"DBSQL_DROP_TEMP_TRIGGER", DBSQL_DROP_TEMP_TRIGGER}, - {"DBSQL_DROP_TEMP_VIEW", DBSQL_DROP_TEMP_VIEW}, - {"DBSQL_DROP_TRIGGER", DBSQL_DROP_TRIGGER}, - {"DBSQL_DROP_VIEW", DBSQL_DROP_VIEW}, - {"DBSQL_INSERT", DBSQL_INSERT}, - {"DBSQL_PRAGMA", DBSQL_PRAGMA}, - {"DBSQL_READ", DBSQL_READ}, - {"DBSQL_SELECT", DBSQL_SELECT}, - {"DBSQL_TRANSACTION", DBSQL_TRANSACTION}, - {"DBSQL_UPDATE", DBSQL_UPDATE}, - {"DBSQL_ATTACH", DBSQL_ATTACH}, - {"DBSQL_DETACH", DBSQL_DETACH}, -#if 0 /* TODO */ - {"DBSQL_ALTER_TABLE", DBSQL_ALTER_TABLE}, - {"DBSQL_REINDEX", DBSQL_REINDEX}, - {"DBSQL_ANALYZE", DBSQL_ANALYZE}, -#endif - {(char*)NULL, 0} -}; - -PyMODINIT_FUNC init_dbsql(void) -{ - PyObject *module, *dict; - PyObject *tmp_obj; - int i; - - module = Py_InitModule("pydbsql2._dbsql", module_methods); - - if (!module || - (pydbsql_row_setup_types() < 0) || - (pydbsql_cursor_setup_types() < 0) || - (pydbsql_connection_setup_types() < 0) || - (pydbsql_cache_setup_types() < 0) || - (pydbsql_statement_setup_types() < 0) || - (pydbsql_prepare_protocol_setup_types() < 0) - ) { - return; - } - - Py_INCREF(&pydbsql_ConnectionType); - PyModule_AddObject(module, "Connection", (PyObject*) &pydbsql_ConnectionType); - Py_INCREF(&pydbsql_CursorType); - PyModule_AddObject(module, "Cursor", (PyObject*) &pydbsql_CursorType); - Py_INCREF(&pydbsql_CacheType); - PyModule_AddObject(module, "Statement", (PyObject*)&pydbsql_StatementType); - Py_INCREF(&pydbsql_StatementType); - PyModule_AddObject(module, "Cache", (PyObject*) &pydbsql_CacheType); - Py_INCREF(&pydbsql_PrepareProtocolType); - PyModule_AddObject(module, "PrepareProtocol", (PyObject*) &pydbsql_PrepareProtocolType); - Py_INCREF(&pydbsql_RowType); - PyModule_AddObject(module, "Row", (PyObject*) &pydbsql_RowType); - - if (!(dict = PyModule_GetDict(module))) { - goto error; - } - - /*** Create DB-API Exception hierarchy */ - - if (!(pydbsql_Error = PyErr_NewException(MODULE_NAME ".Error", PyExc_StandardError, NULL))) { - goto error; - } - PyDict_SetItemString(dict, "Error", pydbsql_Error); - - if (!(pydbsql_Warning = PyErr_NewException(MODULE_NAME ".Warning", PyExc_StandardError, NULL))) { - goto error; - } - PyDict_SetItemString(dict, "Warning", pydbsql_Warning); - - /* Error subclasses */ - - if (!(pydbsql_InterfaceError = PyErr_NewException(MODULE_NAME ".InterfaceError", pydbsql_Error, NULL))) { - goto error; - } - PyDict_SetItemString(dict, "InterfaceError", pydbsql_InterfaceError); - - if (!(pydbsql_DatabaseError = PyErr_NewException(MODULE_NAME ".DatabaseError", pydbsql_Error, NULL))) { - goto error; - } - PyDict_SetItemString(dict, "DatabaseError", pydbsql_DatabaseError); - - /* pydbsql_DatabaseError subclasses */ - - if (!(pydbsql_InternalError = PyErr_NewException(MODULE_NAME ".InternalError", pydbsql_DatabaseError, NULL))) { - goto error; - } - PyDict_SetItemString(dict, "InternalError", pydbsql_InternalError); - - if (!(pydbsql_OperationalError = PyErr_NewException(MODULE_NAME ".OperationalError", pydbsql_DatabaseError, NULL))) { - goto error; - } - PyDict_SetItemString(dict, "OperationalError", pydbsql_OperationalError); - - if (!(pydbsql_ProgrammingError = PyErr_NewException(MODULE_NAME ".ProgrammingError", pydbsql_DatabaseError, NULL))) { - goto error; - } - PyDict_SetItemString(dict, "ProgrammingError", pydbsql_ProgrammingError); - - if (!(pydbsql_IntegrityError = PyErr_NewException(MODULE_NAME ".IntegrityError", pydbsql_DatabaseError,NULL))) { - goto error; - } - PyDict_SetItemString(dict, "IntegrityError", pydbsql_IntegrityError); - - if (!(pydbsql_DataError = PyErr_NewException(MODULE_NAME ".DataError", pydbsql_DatabaseError, NULL))) { - goto error; - } - PyDict_SetItemString(dict, "DataError", pydbsql_DataError); - - if (!(pydbsql_NotSupportedError = PyErr_NewException(MODULE_NAME ".NotSupportedError", pydbsql_DatabaseError, NULL))) { - goto error; - } - PyDict_SetItemString(dict, "NotSupportedError", pydbsql_NotSupportedError); - - /* We just need "something" unique for pydbsql_OptimizedUnicode. It does not really - * need to be a string subclass. Just anything that can act as a special - * marker for us. So I pulled PyCell_Type out of my magic hat. - */ - Py_INCREF((PyObject*)&PyCell_Type); - pydbsql_OptimizedUnicode = (PyObject*)&PyCell_Type; - PyDict_SetItemString(dict, "OptimizedUnicode", pydbsql_OptimizedUnicode); - - /* Set integer constants */ - for (i = 0; _int_constants[i].constant_name != 0; i++) { - tmp_obj = PyInt_FromLong(_int_constants[i].constant_value); - if (!tmp_obj) { - goto error; - } - PyDict_SetItemString(dict, _int_constants[i].constant_name, tmp_obj); - Py_DECREF(tmp_obj); - } - - if (!(tmp_obj = PyString_FromString(PYDBSQL_VERSION))) { - goto error; - } - PyDict_SetItemString(dict, "version", tmp_obj); - Py_DECREF(tmp_obj); - - if (!(tmp_obj = PyString_FromString(DBSQL_VERSION_STRING))) { - goto error; - } - PyDict_SetItemString(dict, "dbsql_version", tmp_obj); - Py_DECREF(tmp_obj); - - /* initialize microprotocols layer */ - microprotocols_init(dict); - - /* initialize the default converters */ - converters_init(dict); - - _enable_callback_tracebacks = 0; - - /* Original comment form _bsddb.c in the Python core. This is also still - * needed nowadays for Python 2.3/2.4. - * - * PyEval_InitThreads is called here due to a quirk in python 1.5 - * - 2.2.1 (at least) according to Russell Williamson : - * The global interepreter lock is not initialized until the first - * thread is created using thread.start_new_thread() or fork() is - * called. that would cause the ALLOW_THREADS here to segfault due - * to a null pointer reference if no threads or child processes - * have been created. This works around that and is a no-op if - * threads have already been initialized. - * (see pybsddb-users mailing list post on 2002-08-07) - */ - PyEval_InitThreads(); - -error: - if (PyErr_Occurred()) - { - PyErr_SetString(PyExc_ImportError, "pydbsql2._dbsql: init failed"); - } -} diff --git a/src/py/src/prepare_protocol.c b/src/py/src/prepare_protocol.c index a147e88..e69de29 100644 --- a/src/py/src/prepare_protocol.c +++ b/src/py/src/prepare_protocol.c @@ -1,106 +0,0 @@ -/*- - * DBSQL - A SQL database engine. - * - * Copyright (C) 2007 DBSQL Group, Inc - All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * There are special exceptions to the terms and conditions of the GPL as it - * is applied to this software. View the full text of the exception in file - * LICENSE_EXCEPTIONS in the directory of this software distribution. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * http://creativecommons.org/licenses/GPL/2.0/ - * - * $Id: api.c 7 2007-02-03 13:34:17Z gburd $ - */ - -/* prepare_protocol.c - the protocol for preparing values for DBSQL - * - * Copyright (C) 2005-2006 Gerhard Häring - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -#include "prepare_protocol.h" - -int pydbsql_prepare_protocol_init(pydbsql_PrepareProtocol* self, PyObject* args, PyObject* kwargs) -{ - return 0; -} - -void pydbsql_prepare_protocol_dealloc(pydbsql_PrepareProtocol* self) -{ - self->ob_type->tp_free((PyObject*)self); -} - -PyTypeObject pydbsql_PrepareProtocolType= { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - MODULE_NAME ".PrepareProtocol", /* tp_name */ - sizeof(pydbsql_PrepareProtocol), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)pydbsql_prepare_protocol_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - 0, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)pydbsql_prepare_protocol_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0 /* tp_free */ -}; - -extern int pydbsql_prepare_protocol_setup_types(void) -{ - pydbsql_PrepareProtocolType.tp_new = PyType_GenericNew; - pydbsql_PrepareProtocolType.ob_type= &PyType_Type; - return PyType_Ready(&pydbsql_PrepareProtocolType); -} diff --git a/src/py/src/row.c b/src/py/src/row.c index 5a59c0f..e69de29 100644 --- a/src/py/src/row.c +++ b/src/py/src/row.c @@ -1,255 +0,0 @@ -/*- - * DBSQL - A SQL database engine. - * - * Copyright (C) 2007 DBSQL Group, Inc - All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * There are special exceptions to the terms and conditions of the GPL as it - * is applied to this software. View the full text of the exception in file - * LICENSE_EXCEPTIONS in the directory of this software distribution. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * http://creativecommons.org/licenses/GPL/2.0/ - * - * $Id: api.c 7 2007-02-03 13:34:17Z gburd $ - */ - -/* row.c - an enhanced tuple for database rows - * - * Copyright (C) 2005-2006 Gerhard Häring - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -#include "row.h" -#include "cursor.h" -#include "dbsqlcompat.h" - -void pydbsql_row_dealloc(pydbsql_Row* self) -{ - Py_XDECREF(self->data); - Py_XDECREF(self->description); - - self->ob_type->tp_free((PyObject*)self); -} - -int pydbsql_row_init(pydbsql_Row* self, PyObject* args, PyObject* kwargs) -{ - PyObject* data; - pydbsql_Cursor* cursor; - - self->data = 0; - self->description = 0; - - if (!PyArg_ParseTuple(args, "OO", &cursor, &data)) { - return -1; - } - - if (!PyObject_IsInstance((PyObject*)cursor, (PyObject*)&pydbsql_CursorType)) { - PyErr_SetString(PyExc_TypeError, "instance of cursor required for first argument"); - return -1; - } - - if (!PyTuple_Check(data)) { - PyErr_SetString(PyExc_TypeError, "tuple required for second argument"); - return -1; - } - - Py_INCREF(data); - self->data = data; - - Py_INCREF(cursor->description); - self->description = cursor->description; - - return 0; -} - -PyObject* pydbsql_row_subscript(pydbsql_Row* self, PyObject* idx) -{ - long _idx; - char* key; - int nitems, i; - char* compare_key; - - char* p1; - char* p2; - - PyObject* item; - - if (PyInt_Check(idx)) { - _idx = PyInt_AsLong(idx); - item = PyTuple_GetItem(self->data, _idx); - Py_XINCREF(item); - return item; - } else if (PyLong_Check(idx)) { - _idx = PyLong_AsLong(idx); - item = PyTuple_GetItem(self->data, _idx); - Py_XINCREF(item); - return item; - } else if (PyString_Check(idx)) { - key = PyString_AsString(idx); - - nitems = PyTuple_Size(self->description); - - for (i = 0; i < nitems; i++) { - compare_key = PyString_AsString(PyTuple_GET_ITEM(PyTuple_GET_ITEM(self->description, i), 0)); - if (!compare_key) { - return NULL; - } - - p1 = key; - p2 = compare_key; - - while (1) { - if ((*p1 == (char)0) || (*p2 == (char)0)) { - break; - } - - if ((*p1 | 0x20) != (*p2 | 0x20)) { - break; - } - - p1++; - p2++; - } - - if ((*p1 == (char)0) && (*p2 == (char)0)) { - /* found item */ - item = PyTuple_GetItem(self->data, i); - Py_INCREF(item); - return item; - } - - } - - PyErr_SetString(PyExc_IndexError, "No item with that key"); - return NULL; - } else if (PySlice_Check(idx)) { - PyErr_SetString(PyExc_ValueError, "slices not implemented, yet"); - return NULL; - } else { - PyErr_SetString(PyExc_IndexError, "Index must be int or string"); - return NULL; - } -} - -Py_ssize_t pydbsql_row_length(pydbsql_Row* self, PyObject* args, PyObject* kwargs) -{ - return PyTuple_GET_SIZE(self->data); -} - -PyObject* pydbsql_row_keys(pydbsql_Row* self, PyObject* args, PyObject* kwargs) -{ - PyObject* list; - int nitems, i; - - list = PyList_New(0); - if (!list) { - return NULL; - } - nitems = PyTuple_Size(self->description); - - for (i = 0; i < nitems; i++) { - if (PyList_Append(list, PyTuple_GET_ITEM(PyTuple_GET_ITEM(self->description, i), 0)) != 0) { - Py_DECREF(list); - return NULL; - } - } - - return list; -} - -static int pydbsql_row_print(pydbsql_Row* self, FILE *fp, int flags) -{ - return (&PyTuple_Type)->tp_print(self->data, fp, flags); -} - -static PyObject* pydbsql_iter(pydbsql_Row* self) -{ - return PyObject_GetIter(self->data); -} - -PyMappingMethods pydbsql_row_as_mapping = { - /* mp_length */ (lenfunc)pydbsql_row_length, - /* mp_subscript */ (binaryfunc)pydbsql_row_subscript, - /* mp_ass_subscript */ (objobjargproc)0, -}; - -static PyMethodDef pydbsql_row_methods[] = { - {"keys", (PyCFunction)pydbsql_row_keys, METH_NOARGS, - PyDoc_STR("Returns the keys of the row.")}, - {NULL, NULL} -}; - - -PyTypeObject pydbsql_RowType = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - MODULE_NAME ".Row", /* tp_name */ - sizeof(pydbsql_Row), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)pydbsql_row_dealloc, /* tp_dealloc */ - (printfunc)pydbsql_row_print, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */ - 0, /* tp_doc */ - (traverseproc)0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc)pydbsql_iter, /* tp_iter */ - 0, /* tp_iternext */ - pydbsql_row_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)pydbsql_row_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0 /* tp_free */ -}; - -extern int pydbsql_row_setup_types(void) -{ - pydbsql_RowType.tp_new = PyType_GenericNew; - pydbsql_RowType.tp_as_mapping = &pydbsql_row_as_mapping; - return PyType_Ready(&pydbsql_RowType); -} diff --git a/src/py/src/statement.c b/src/py/src/statement.c index 449b5e3..e69de29 100644 --- a/src/py/src/statement.c +++ b/src/py/src/statement.c @@ -1,457 +0,0 @@ -/*- - * DBSQL - A SQL database engine. - * - * Copyright (C) 2007 DBSQL Group, Inc - All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * There are special exceptions to the terms and conditions of the GPL as it - * is applied to this software. View the full text of the exception in file - * LICENSE_EXCEPTIONS in the directory of this software distribution. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * http://creativecommons.org/licenses/GPL/2.0/ - * - * $Id: api.c 7 2007-02-03 13:34:17Z gburd $ - */ - -/* statement.c - the statement type - * - * Copyright (C) 2005-2006 Gerhard Häring - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -#include "statement.h" -#include "cursor.h" -#include "connection.h" -#include "microprotocols.h" -#include "prepare_protocol.h" -#include "dbsqlcompat.h" - -/* prototypes */ -static int pydbsql_check_remaining_sql(const char* tail); - -typedef enum { - LINECOMMENT_1, - IN_LINECOMMENT, - COMMENTSTART_1, - IN_COMMENT, - COMMENTEND_1, - NORMAL -} parse_remaining_sql_state; - -int pydbsql_statement_create(pydbsql_Statement* self, pydbsql_Connection* connection, PyObject* sql) -{ - const char* tail; - int rc; - PyObject* sql_str; - char* sql_cstr; - char* errors; - - self->st = NULL; - self->in_use = 0; - - if (PyString_Check(sql)) { - sql_str = sql; - Py_INCREF(sql_str); - } else if (PyUnicode_Check(sql)) { - sql_str = PyUnicode_AsUTF8String(sql); - if (!sql_str) { - rc = PYDBSQL_SQL_WRONG_TYPE; - return rc; - } - } else { - rc = PYDBSQL_SQL_WRONG_TYPE; - return rc; - } - - self->in_weakreflist = NULL; - self->sql = sql_str; - - sql_cstr = PyString_AsString(sql_str); - - rc = connection->db->prepare(connection->db, sql_cstr, &tail, &self->st, - &errors); - - self->db = connection->db; - - if (errors) - free(errors); - - if (rc == DBSQL_SUCCESS && pydbsql_check_remaining_sql(tail)) { - (void)self->db->finalize(self->st, &errors); - self->st = NULL; - rc = PYDBSQL_TOO_MUCH_SQL; - if (errors) - free(errors); - } - - return rc; -} - -int pydbsql_statement_bind_parameter(pydbsql_Statement* self, int pos, PyObject* parameter) -{ - int rc = DBSQL_SUCCESS; - long longval; -#ifdef HAVE_LONG_LONG - PY_LONG_LONG longlongval; -#endif - const char* buffer; - char* string; - Py_ssize_t buflen; - PyObject* stringval; - - if (parameter == Py_None) { - rc = dbsql_bind_null(self->st, pos); - } else if (PyInt_Check(parameter)) { - longval = PyInt_AsLong(parameter); - rc = dbsql_bind_int64(self->st, pos, (dbsql_int64)longval); -#ifdef HAVE_LONG_LONG - } else if (PyLong_Check(parameter)) { - longlongval = PyLong_AsLongLong(parameter); - /* in the overflow error case, longlongval is -1, and an exception is set */ - rc = dbsql_bind_int64(self->st, pos, (dbsql_int64)longlongval); -#endif - } else if (PyFloat_Check(parameter)) { - rc = dbsql_bind_double(self->st, pos, PyFloat_AsDouble(parameter)); - } else if (PyBuffer_Check(parameter)) { - if (PyObject_AsCharBuffer(parameter, &buffer, &buflen) == 0) { - rc = dbsql_bind_blob(self->st, pos, buffer, buflen, DBSQL_TRANSIENT); - } else { - PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer"); - rc = -1; - } - } else if PyString_Check(parameter) { - string = PyString_AsString(parameter); - rc = dbsql_bind_text(self->st, pos, string, -1, DBSQL_TRANSIENT); - } else if PyUnicode_Check(parameter) { - stringval = PyUnicode_AsUTF8String(parameter); - string = PyString_AsString(stringval); - rc = dbsql_bind_text(self->st, pos, string, -1, DBSQL_TRANSIENT); - Py_DECREF(stringval); - } else { - rc = -1; - } - - return rc; -} - -void pydbsql_statement_bind_parameters(pydbsql_Statement* self, PyObject* parameters) -{ - PyObject* current_param; - PyObject* adapted; - const char* binding_name; - int i; - int rc; - int num_params_needed; - int num_params; - - Py_BEGIN_ALLOW_THREADS - num_params_needed = dbsql_bind_parameter_count(self->st); - Py_END_ALLOW_THREADS - - if (PyDict_Check(parameters)) { - /* parameters passed as dictionary */ - for (i = 1; i <= num_params_needed; i++) { - Py_BEGIN_ALLOW_THREADS - binding_name = dbsql_bind_parameter_name(self->st, i); - Py_END_ALLOW_THREADS - if (!binding_name) { - PyErr_Format(pydbsql_ProgrammingError, "Binding %d has no name, but you supplied a dictionary (which has only names).", i); - return; - } - - binding_name++; /* skip first char (the colon) */ - current_param = PyDict_GetItemString(parameters, binding_name); - if (!current_param) { - PyErr_Format(pydbsql_ProgrammingError, "You did not supply a value for binding %d.", i); - return; - } - - Py_INCREF(current_param); - adapted = microprotocols_adapt(current_param, (PyObject*)&pydbsql_PrepareProtocolType, NULL); - if (adapted) { - Py_DECREF(current_param); - } else { - PyErr_Clear(); - adapted = current_param; - } - - rc = pydbsql_statement_bind_parameter(self, i, adapted); - Py_DECREF(adapted); - - if (rc != DBSQL_SUCCESS) { - PyErr_Format(pydbsql_InterfaceError, "Error binding parameter :%s - probably unsupported type.", binding_name); - return; - } - } - } else { - /* parameters passed as sequence */ - num_params = PySequence_Length(parameters); - if (num_params != num_params_needed) { - PyErr_Format(pydbsql_ProgrammingError, "Incorrect number of bindings supplied. The current statement uses %d, and there are %d supplied.", - num_params_needed, num_params); - return; - } - for (i = 0; i < num_params; i++) { - current_param = PySequence_GetItem(parameters, i); - if (!current_param) { - return; - } - adapted = microprotocols_adapt(current_param, (PyObject*)&pydbsql_PrepareProtocolType, NULL); - - if (adapted) { - Py_DECREF(current_param); - } else { - PyErr_Clear(); - adapted = current_param; - } - - rc = pydbsql_statement_bind_parameter(self, i + 1, adapted); - Py_DECREF(adapted); - - if (rc != DBSQL_SUCCESS) { - PyErr_Format(pydbsql_InterfaceError, "Error binding parameter %d - probably unsupported type.", i); - return; - } - } - } -} - -int pydbsql_statement_recompile(pydbsql_Statement* self, PyObject* params) -{ - const char* tail; - int rc; - char* sql_cstr; - dbsql_stmt_t* new_st; - - sql_cstr = PyString_AsString(self->sql); - - rc = dbsql_prepare(self->db, - sql_cstr, - -1, - &new_st, - &tail); - - if (rc == DBSQL_SUCCESS) { - /* The efficient dbsql_transfer_bindings is only available in DBSQL - * version 3.2.2 or later. For older DBSQL releases, that might not - * even define DBSQL_VERSION_NUMBER, we do it the manual way. - */ -#ifdef DBSQL_VERSION_NUMBER -#if DBSQL_VERSION_NUMBER >= 3002002 - (void)dbsql_transfer_bindings(self->st, new_st); -#endif -#else - statement_bind_parameters(self, params); -#endif - - (void)dbsql_finalize(self->st); - self->st = new_st; - } - - return rc; -} - -int pydbsql_statement_finalize(pydbsql_Statement* self) -{ - int rc; - - rc = DBSQL_SUCCESS; - if (self->st) { - Py_BEGIN_ALLOW_THREADS - rc = dbsql_finalize(self->st); - Py_END_ALLOW_THREADS - self->st = NULL; - } - - self->in_use = 0; - - return rc; -} - -int pydbsql_statement_reset(pydbsql_Statement* self) -{ - int rc; - - rc = DBSQL_SUCCESS; - - if (self->in_use && self->st) { - Py_BEGIN_ALLOW_THREADS - rc = dbsql_reset(self->st); - Py_END_ALLOW_THREADS - - if (rc == DBSQL_SUCCESS) { - self->in_use = 0; - } - } - - return rc; -} - -void pydbsql_statement_mark_dirty(pydbsql_Statement* self) -{ - self->in_use = 1; -} - -void pydbsql_statement_dealloc(pydbsql_Statement* self) -{ - int rc; - - if (self->st) { - Py_BEGIN_ALLOW_THREADS - rc = dbsql_finalize(self->st); - Py_END_ALLOW_THREADS - } - - self->st = NULL; - - Py_XDECREF(self->sql); - - if (self->in_weakreflist != NULL) { - PyObject_ClearWeakRefs((PyObject*)self); - } - - self->ob_type->tp_free((PyObject*)self); -} - -/* - * Checks if there is anything left in an SQL string after DBSQL compiled it. - * This is used to check if somebody tried to execute more than one SQL command - * with one execute()/executemany() command, which the DB-API and we don't - * allow. - * - * Returns 1 if there is more left than should be. 0 if ok. - */ -static int pydbsql_check_remaining_sql(const char* tail) -{ - const char* pos = tail; - - parse_remaining_sql_state state = NORMAL; - - for (;;) { - switch (*pos) { - case 0: - return 0; - case '-': - if (state == NORMAL) { - state = LINECOMMENT_1; - } else if (state == LINECOMMENT_1) { - state = IN_LINECOMMENT; - } - break; - case ' ': - case '\t': - break; - case '\n': - case 13: - if (state == IN_LINECOMMENT) { - state = NORMAL; - } - break; - case '/': - if (state == NORMAL) { - state = COMMENTSTART_1; - } else if (state == COMMENTEND_1) { - state = NORMAL; - } else if (state == COMMENTSTART_1) { - return 1; - } - break; - case '*': - if (state == NORMAL) { - return 1; - } else if (state == LINECOMMENT_1) { - return 1; - } else if (state == COMMENTSTART_1) { - state = IN_COMMENT; - } else if (state == IN_COMMENT) { - state = COMMENTEND_1; - } - break; - default: - if (state == COMMENTEND_1) { - state = IN_COMMENT; - } else if (state == IN_LINECOMMENT) { - } else if (state == IN_COMMENT) { - } else { - return 1; - } - } - - pos++; - } - - return 0; -} - -PyTypeObject pydbsql_StatementType = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - MODULE_NAME ".Statement", /* tp_name */ - sizeof(pydbsql_Statement), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)pydbsql_statement_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */ - 0, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - offsetof(pydbsql_Statement, in_weakreflist), /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)0, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0 /* tp_free */ -}; - -extern int pydbsql_statement_setup_types(void) -{ - pydbsql_StatementType.tp_new = PyType_GenericNew; - return PyType_Ready(&pydbsql_StatementType); -} diff --git a/src/safety.c b/src/safety.c index c8c391b..71dd64a 100644 --- a/src/safety.c +++ b/src/safety.c @@ -44,8 +44,7 @@ * PUBLIC: int __safety_on __P((DBSQL *)); */ int -__safety_on(dbp) - DBSQL *dbp; +__safety_on(DBSQL* dbp) { if (dbp->magic == DBSQL_STATUS_OPEN) { dbp->magic = DBSQL_STATUS_BUSY; @@ -68,8 +67,7 @@ __safety_on(dbp) * PUBLIC: int __safety_off __P((DBSQL *)); */ int -__safety_off(dbp) - DBSQL *dbp; +__safety_off(DBSQL* dbp) { if (dbp->magic == DBSQL_STATUS_BUSY) { dbp->magic = DBSQL_STATUS_OPEN; @@ -95,8 +93,7 @@ __safety_off(dbp) * PUBLIC: int __safety_check __P((DBSQL *)); */ int -__safety_check(dbp) - DBSQL *dbp; +__safety_check(DBSQL* dbp) { if (dbp->pVdbe != 0) { dbp->magic = DBSQL_STATUS_ERROR; diff --git a/src/sm.c b/src/sm.c index 61dbc68..5cb82a9 100644 --- a/src/sm.c +++ b/src/sm.c @@ -77,8 +77,7 @@ __sm_bt_compare(db, dbt1, dbt2) * otherwise 0; */ static int -__sm_is_threaded(sm) - sm_t *sm; +__sm_is_threaded(sm_t* sm) { int flags; return F_ISSET(sm->dbp, DBSQL_Threaded); @@ -98,9 +97,7 @@ __sm_is_threaded(sm) * STATIC: static u_int32_t __sm_next_from_seq __P((sm_t *, DB_TXN *)); */ static u_int32_t -__sm_next_from_seq(sm, txn) - sm_t *sm; - DB_TXN *txn; +__sm_next_from_seq(sm_t* sm, DB_TXN* txn) { int rc; db_seq_t val; @@ -223,9 +220,7 @@ __sm_meta_init(sm, txn, name, init) * STATIC: static int __sm_init __P((sm_t *, int *)); */ static int -__sm_init(sm, init) - sm_t *sm; - int *init; +__sm_init(sm_t* sm, int* init) { int rc = DBSQL_SUCCESS; int flags = 0; @@ -383,8 +378,7 @@ __sm_create(dbp, name, is_temp, in_memory, smp) * PUBLIC: int __sm_close_db __P((sm_t *)); */ int -__sm_close_db(sm) - sm_t *sm; +__sm_close_db(sm_t* sm) { int rc; hash_ele_t *p; @@ -419,8 +413,7 @@ __sm_close_db(sm) * PUBLIC: int __sm_checkpoint __P((sm_t *)); */ int -__sm_checkpoint(sm) - sm_t *sm; +__sm_checkpoint(sm_t* sm) { DBSQL_ASSERT(sm != 0); if (sm->dbp->dbenv) @@ -435,8 +428,7 @@ __sm_checkpoint(sm) * PUBLIC: char *__sm_get_database_name __P((sm_t *)); */ char * -__sm_get_database_name(sm) - sm_t *sm; +__sm_get_database_name(sm_t* sm) { DBSQL_ASSERT(sm != 0); return (sm->name); @@ -448,8 +440,7 @@ __sm_get_database_name(sm) * PUBLIC: int __sm_begin_txn __P((sm_t *)); */ int -__sm_begin_txn(sm) - sm_t *sm; +__sm_begin_txn(sm_t* sm) { DBSQL_ASSERT(sm); return (sm->dbp->dbenv->txn_begin(sm->dbp->dbenv, 0, &sm->txn, 0)); @@ -465,8 +456,7 @@ __sm_begin_txn(sm) * PUBLIC: int __sm_commit_txn __P((sm_t *)); */ int -__sm_commit_txn(sm) - sm_t *sm; +__sm_commit_txn(sm_t* sm) { DBSQL_ASSERT(sm); if (sm->txn) @@ -485,8 +475,7 @@ __sm_commit_txn(sm) * PUBLIC: int __sm_abort_txn __P((sm_t *)); */ int -__sm_abort_txn(sm) - sm_t *sm; +__sm_abort_txn(sm_t* sm) { DBSQL_ASSERT(sm); if (sm->txn) @@ -506,11 +495,7 @@ __sm_abort_txn(sm) * PUBLIC: int __sm_cursor __P((sm_t *, int, int, sm_cursor_t **)); */ int -__sm_cursor(sm, id, write, smcp) - sm_t *sm; - int id; - int write; - sm_cursor_t **smcp; +__sm_cursor(sm_t* sm, int id, int write, sm_cursor_t* *smcp) { int rc; sm_rec_t *smr; @@ -561,8 +546,7 @@ __sm_cursor(sm, id, write, smcp) * PUBLIC: int __sm_close_cursor __P((sm_cursor_t *)); */ int -__sm_close_cursor(smc) - sm_cursor_t *smc; +__sm_close_cursor(sm_cursor_t* smc) { int rc = DBSQL_SUCCESS; DBSQL_ASSERT(smc != 0); @@ -675,9 +659,7 @@ __sm_moveto(smc, item, len, result) * PUBLIC: int __sm_next __P((sm_cursor_t *, int *)); */ int -__sm_next(smc, result) - sm_cursor_t *smc; - int *result; +__sm_next(sm_cursor_t* smc, int* result) { int rc = DBSQL_SUCCESS; DBT key, data; @@ -718,9 +700,7 @@ __sm_next(smc, result) * PUBLIC: int __sm_prev __P((sm_cursor_t *, int *)); */ int -__sm_prev(smc, result) - sm_cursor_t *smc; - int *result; +__sm_prev(sm_cursor_t* smc, int* result) { int rc = DBSQL_SUCCESS; DBT key, data; @@ -762,9 +742,7 @@ __sm_prev(smc, result) * PUBLIC: int __sm_key_size __P((sm_cursor_t *, int *)); */ int -__sm_key_size(smc, size) - sm_cursor_t *smc; - int *size; +__sm_key_size(sm_cursor_t* smc, int* size) { int rc = DBSQL_SUCCESS; DBT key, data; @@ -806,9 +784,7 @@ __sm_key_size(smc, size) * PUBLIC: int __sm_data_size __P((sm_cursor_t *, int *)); */ int -__sm_data_size(smc, size) - sm_cursor_t *smc; - int *size; +__sm_data_size(sm_cursor_t* smc, int* size) { int rc = DBSQL_SUCCESS; DBT key, data; @@ -951,11 +927,7 @@ __sm_key(smc, offset, len, value) * PUBLIC: size_t __sm_data __P((sm_cursor_t *, size_t, size_t, char *)); */ size_t -__sm_data(smc, offset, len, value) - sm_cursor_t *smc; - size_t offset; - size_t len; - char *value; +__sm_data(sm_cursor_t* smc, size_t offset, size_t len, char* value) { size_t amt = 0; DBT key, data; @@ -998,9 +970,7 @@ __sm_data(smc, offset, len, value) * PUBLIC: int __sm_first __P((sm_cursor_t *, int *)); */ int -__sm_first(smc, result) - sm_cursor_t *smc; - int *result; +__sm_first(sm_cursor_t* smc, int* result) { int rc = DBSQL_SUCCESS; DBT key, data; @@ -1039,9 +1009,7 @@ __sm_first(smc, result) * PUBLIC: int __sm_last __P((sm_cursor_t *, int *)); */ int -__sm_last(smc, result) - sm_cursor_t *smc; - int *result; +__sm_last(sm_cursor_t* smc, int* result) { int rc = DBSQL_SUCCESS; DBT key, data; @@ -1125,8 +1093,7 @@ __sm_insert(smc, k, k_len, v, v_len) * PUBLIC: int __sm_delete __P((sm_cursor_t *)); */ int -__sm_delete(smc) - sm_cursor_t *smc; +__sm_delete(sm_cursor_t* smc) { int rc = DBSQL_SUCCESS; @@ -1148,9 +1115,7 @@ __sm_delete(smc) * PUBLIC: int __sm_drop_table __P((sm_t *, int)); */ int -__sm_drop_table(sm, id) - sm_t *sm; - int id; +__sm_drop_table(sm_t* sm, int id) { int rc; sm_rec_t *smr; @@ -1182,9 +1147,7 @@ __sm_drop_table(sm, id) * PUBLIC: int __sm_clear_table __P((sm_t *, int)); */ int -__sm_clear_table(sm, id) - sm_t *sm; - int id; +__sm_clear_table(sm_t* sm, int id) { int rc; u_int32_t count = 0; @@ -1210,11 +1173,7 @@ __sm_clear_table(sm, id) * STATIC: static int __sm_resource __P((sm_t *, u_int32_t *, int, int)); */ static int -__sm_resource(sm, id, type, init) - sm_t *sm; - u_int32_t *id; - int type; - int init; +__sm_resource(sm_t* sm, u_int32_t* id, int type, int init) { int rc, flags; char name[1024]; @@ -1272,9 +1231,7 @@ __sm_resource(sm, id, type, init) * PUBLIC: int __sm_open_table __P((sm_t *, int *)); */ int -__sm_open_table(sm, id) - sm_t *sm; - int *id; +__sm_open_table(sm_t* sm, int* id) { return __sm_resource(sm, id, SMR_TYPE_TABLE, 0); } @@ -1286,9 +1243,7 @@ __sm_open_table(sm, id) * PUBLIC: int __sm_create_table __P((sm_t *, int *)); */ int -__sm_create_table(sm, id) - sm_t *sm; - int *id; +__sm_create_table(sm_t* sm, int* id) { return __sm_resource(sm, id, SMR_TYPE_TABLE, 1); } @@ -1299,9 +1254,7 @@ __sm_create_table(sm, id) * PUBLIC: int __sm_create_index __P((sm_t *, int *)); */ int -__sm_create_index(sm, id) - sm_t *sm; - int *id; +__sm_create_index(sm_t* sm, int* id) { return __sm_resource(sm, id, SMR_TYPE_INDEX, 1); } @@ -1312,10 +1265,7 @@ __sm_create_index(sm, id) * PUBLIC: int __sm_set_format_version __P((sm_t *, int, u_int32_t)); */ int -__sm_set_format_version(sm, id, ver) - sm_t *sm; - int id; - u_int32_t ver; +__sm_set_format_version(sm_t* sm, int id, u_int32_t ver) { int rc; DBT key, data; @@ -1355,9 +1305,7 @@ __sm_set_format_version(sm, id, ver) * PUBLIC: int __sm_get_format_version __P((sm_t *, u_int32_t *)); */ int -__sm_get_format_version(sm, ver) - sm_t *sm; - u_int32_t *ver; +__sm_get_format_version(sm_t* sm, u_int32_t* ver) { int rc; DBT key, data; @@ -1408,9 +1356,7 @@ __sm_get_format_version(sm, ver) * PUBLIC: int __sm_set_schema_sig __P((sm_t *, u_int32_t)); */ int -__sm_set_schema_sig(sm, sig) - sm_t *sm; - u_int32_t sig; +__sm_set_schema_sig(sm_t* sm, u_int32_t sig) { int rc; char *k = SM_SCHEMA_SIG; @@ -1449,9 +1395,7 @@ __sm_set_schema_sig(sm, sig) * PUBLIC: int __sm_get_schema_sig __P((sm_t *, u_int32_t *)); */ int -__sm_get_schema_sig(sm, sig) - sm_t *sm; - u_int32_t *sig; +__sm_get_schema_sig(sm_t* sm, u_int32_t* sig) { int rc; DBT key, data; diff --git a/src/sql_fns.c b/src/sql_fns.c index bf6d7f9..ac3440c 100644 --- a/src/sql_fns.c +++ b/src/sql_fns.c @@ -531,8 +531,7 @@ __sum_step(context, argc, argv) } static void -__sum_finalize(context) - dbsql_func_t *context; +__sum_finalize(dbsql_func_t* context) { sum_ctx_t *p; p = dbsql_aggregate_context(context, sizeof(*p)); @@ -540,8 +539,7 @@ __sum_finalize(context) } static void -__avg_finalize(context) - dbsql_func_t *context; +__avg_finalize(dbsql_func_t* context) { sum_ctx_t *p; p = dbsql_aggregate_context(context, sizeof(*p)); @@ -587,8 +585,7 @@ __std_dev_step(context, argc, argv) * __std_dev_finalize -- */ static void -__std_dev_finalize(context) - dbsql_func_t *context; +__std_dev_finalize(dbsql_func_t* context) { double rN = dbsql_aggregate_count(context); std_dev_ctx_t *p = dbsql_aggregate_context(context, sizeof(*p)); @@ -628,8 +625,7 @@ __count_step(context, argc, argv) * __count_finalize -- */ static void -__count_finalize(context) - dbsql_func_t *context; +__count_finalize(dbsql_func_t* context) { count_ctx_t *p; p = dbsql_aggregate_context(context, sizeof(*p)); @@ -713,8 +709,7 @@ __max_step(context, argc, argv) * __min_max_finalize -- */ static void -__min_max_finalize(context) - dbsql_func_t *context; +__min_max_finalize(dbsql_func_t* context) { min_max_ctx_t *p; p = dbsql_aggregate_context(context, sizeof(*p)); @@ -735,8 +730,7 @@ __min_max_finalize(context) * PUBLIC: void __register_builtin_funcs __P((DBSQL *)); */ void -__register_builtin_funcs(dbp) - DBSQL *dbp; +__register_builtin_funcs(DBSQL* dbp) { static struct { char *name; diff --git a/src/vdbe.c b/src/vdbe.c index d21a894..74f57f3 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -185,10 +185,7 @@ __api_step(p, n, values, col_names) * STATIC: static int __agg_insert __P((agg_t *, char *, int)); */ static int -__agg_insert(p, key, len) - agg_t *p; - char *key; - int len; +__agg_insert(agg_t* p, char* key, int len) { agg_elem_t *elem, *old; int i; @@ -221,8 +218,7 @@ __agg_insert(p, key, len) * STATIC: static agg_elem_t *__agg_in_focus __P((agg_t *p)); */ static agg_elem_t * -__agg_in_focus(p) - agg_t *p; +__agg_in_focus(agg_t* p) { if (p->pCurrent) { return p->pCurrent; @@ -245,8 +241,7 @@ __agg_in_focus(p) * STATIC: static int __entity_as_string __P((mem_t *)); */ static int -__entity_as_string(stack) - mem_t *stack; +__entity_as_string(mem_t* stack) { if ((stack->flags & MEM_Str) == 0) { int fg = stack->flags; @@ -277,8 +272,7 @@ __entity_as_string(stack) * STATIC: static int __entity_to_string __P((mem_t *)); */ static int -__entity_to_string(stack) - mem_t *stack; +__entity_to_string(mem_t* stack) { if ((stack->flags & MEM_Dyn) == 0) { int fg = stack->flags; @@ -309,8 +303,7 @@ __entity_to_string(stack) * STATIC: static int __entity_ephem_to_dyn __P((mem_t * stack)); */ static int -__entity_ephem_to_dyn(stack) - mem_t *stack; +__entity_ephem_to_dyn(mem_t* stack) { if ((stack->flags & MEM_Ephem) != 0) { char *z; @@ -332,8 +325,7 @@ __entity_ephem_to_dyn(stack) * STATIC: static void __entity_release_mem __P((mem_t *)); */ static void -__entity_release_mem(stack) - mem_t *stack; +__entity_release_mem(mem_t* stack) { if ((stack->flags & MEM_Dyn) != 0) { __dbsql_free(NULL, stack->z); @@ -347,9 +339,7 @@ __entity_release_mem(stack) * STATIC: static void __pop_stack __P((mem_t **, int)); */ static void -__pop_stack(stack, n) - mem_t **stack; - int n; +__pop_stack(mem_t* *stack, int n) { mem_t *tos = *stack; while(n > 0) { @@ -369,8 +359,7 @@ __pop_stack(stack, n) * STATIC: static void __entity_to_int __P((mem_t *)); */ static void -__entity_to_int(stack) - mem_t *stack; +__entity_to_int(mem_t* stack) { if ((stack->flags & MEM_Int) == 0) { if (stack->flags & MEM_Real) { @@ -395,8 +384,7 @@ __entity_to_int(stack) * STATIC: static void __entity_to_real __P((mem_t *)); */ static void -__entity_to_real(stack) - mem_t *stack; +__entity_to_real(mem_t* stack) { if ((stack->flags & MEM_Real) == 0) { if (stack->flags & MEM_Str) { @@ -420,9 +408,7 @@ __entity_to_real(stack) * STATIC: static sorter_t * __sorted_merge __P((sorter_t *, sorter_t *)); */ static sorter_t * -__sorted_merge(left, right) - sorter_t *left; - sorter_t *right; +__sorted_merge(sorter_t* left, sorter_t* right) { sorter_t head; sorter_t *tail; @@ -459,10 +445,7 @@ __sorted_merge(left, right) * STATIC: static char *__fgets __P((char *, int, FILE *)); */ static char * -__fgets(buf, len, in) - char *buf; - int len; - FILE *in; +__fgets(char* buf, int len, FILE* in) { int i, c; for(i = 0; i < (len - 1) && (c = getc(in)) != EOF; i++) { @@ -492,9 +475,7 @@ __fgets(buf, len, in) * STATIC: static int __expand_cursor_array_size __P((vdbe_t *, int)); */ static int -__expand_cursor_array_size(vm, num_cursors) - vdbe_t *vm; - int num_cursors; +__expand_cursor_array_size(vdbe_t* vm, int num_cursors) { if (num_cursors >= vm->nCursor) { if (__dbsql_realloc(NULL, ((num_cursors + 1) * @@ -556,8 +537,7 @@ __expand_cursor_array_size(vm, num_cursors) * PUBLIC: int __vdbe_exec __P((vdbe_t *)); */ int -__vdbe_exec(p) - vdbe_t *p; +__vdbe_exec(vdbe_t* p) { int pc; /* The program counter */ vdbe_op_t *pOp; /* Current operation */ diff --git a/src/vdbe_method.c b/src/vdbe_method.c index 45efd63..6a55c78 100644 --- a/src/vdbe_method.c +++ b/src/vdbe_method.c @@ -50,8 +50,7 @@ int dbsql_vdbe_add_op_trace = 0; * PUBLIC: vdbe_t *__vdbe_create __P((DBSQL *)); */ vdbe_t * -__vdbe_create(dbp) - DBSQL *dbp; +__vdbe_create(DBSQL* dbp) { vdbe_t *vm; if (__dbsql_calloc(dbp, 1, sizeof(vdbe_t), &vm) == ENOMEM) @@ -74,9 +73,7 @@ __vdbe_create(dbp) * PUBLIC: void __vdbe_trace __P((vdbe_t *, FILE *)); */ void -__vdbe_trace(vm, trace) - vdbe_t *vm; - FILE *trace; +__vdbe_trace(vdbe_t* vm, FILE* trace) { vm->trace = trace; } @@ -101,11 +98,7 @@ __vdbe_trace(vm, trace) * PUBLIC: int __vdbe_add_op __P((vdbe_t *, int, int, int)); */ int -__vdbe_add_op(vm, op, p1, p2) - vdbe_t *vm; - int op; - int p1; - int p2; +__vdbe_add_op(vdbe_t* vm, int op, int p1, int p2) { int i; @@ -155,8 +148,7 @@ __vdbe_add_op(vm, op, p1, p2) * PUBLIC: int __vdbe_make_label __P((vdbe_t *)); */ int -__vdbe_make_label(vm) - vdbe_t *vm; +__vdbe_make_label(vdbe_t* vm) { int i; i = vm->nLabel++; @@ -187,9 +179,7 @@ __vdbe_make_label(vm) * PUBLIC: void __vdbe_resolve_label __P((vdbe_t *, int)); */ void -__vdbe_resolve_label(vm, x) - vdbe_t *vm; - int x; +__vdbe_resolve_label(vdbe_t* vm, int x) { int j; DBSQL_ASSERT(vm->magic == VDBE_MAGIC_INIT); @@ -212,8 +202,7 @@ __vdbe_resolve_label(vm, x) * PUBLIC: int __vdbe_current_addr __P((vdbe_t *)); */ int -__vdbe_current_addr(vm) - vdbe_t *vm; +__vdbe_current_addr(vdbe_t* vm) { DBSQL_ASSERT(vm->magic == VDBE_MAGIC_INIT); return vm->nOp; @@ -277,10 +266,7 @@ __vdbe_add_op_list(vm, num_op, op) * PUBLIC: void __vdbe_change_p1 __P((vdbe_t *, int, int)); */ void -__vdbe_change_p1(vm, addr, val) - vdbe_t *vm; - int addr; - int val; +__vdbe_change_p1(vdbe_t* vm, int addr, int val) { DBSQL_ASSERT(vm->magic == VDBE_MAGIC_INIT); if (vm && addr >= 0 && vm->nOp > addr && vm->aOp) { @@ -296,10 +282,7 @@ __vdbe_change_p1(vm, addr, val) * PUBLIC: void __vdbe_change_p2 __P((vdbe_t *, int, int)); */ void -__vdbe_change_p2(vm, addr, val) - vdbe_t *vm; - int addr; - int val; +__vdbe_change_p2(vdbe_t* vm, int addr, int val) { DBSQL_ASSERT(val >= 0); DBSQL_ASSERT(vm->magic == VDBE_MAGIC_INIT); @@ -374,9 +357,7 @@ __vdbe_change_p3(vm, addr, p3, n) * PUBLIC: void __vdbe_dequote_p3 __P((vdbe_t *, int)); */ void -__vdbe_dequote_p3(vm, addr) - vdbe_t *vm; - int addr; +__vdbe_dequote_p3(vdbe_t* vm, int addr) { vdbe_op_t *op; DBSQL_ASSERT(vm->magic == VDBE_MAGIC_INIT); @@ -408,9 +389,7 @@ __vdbe_dequote_p3(vm, addr) * PUBLIC: void __vdbe_compress_space __P((vdbe_t *, int)); */ void -__vdbe_compress_space(vm, addr) - vdbe_t *vm; - int addr; +__vdbe_compress_space(vdbe_t* vm, int addr) { unsigned char *z; int i, j; @@ -455,10 +434,7 @@ __vdbe_compress_space(vm, addr) * PUBLIC: int __vdbe_find_op __P((vdbe_t *, int, int)); */ int -__vdbe_find_op(vm, op, p2) - vdbe_t *vm; - int op; - int p2; +__vdbe_find_op(vdbe_t* vm, int op, int p2) { int i; DBSQL_ASSERT(vm->magic == VDBE_MAGIC_INIT); @@ -476,9 +452,7 @@ __vdbe_find_op(vm, op, p2) * PUBLIC: vdbe_op_t *__vdbe_get_op __P((vdbe_t *, int)); */ vdbe_op_t * -__vdbe_get_op(vm, addr) - vdbe_t *vm; - int addr; +__vdbe_get_op(vdbe_t* vm, int addr) { DBSQL_ASSERT(vm->magic == VDBE_MAGIC_INIT); DBSQL_ASSERT(addr >= 0 && addr < vm->nOp); @@ -552,8 +526,7 @@ dbsql_set_result_string(p, result, n) * EXTERN: void dbsql_set_result_null __P((dbsql_func_t *)); */ void -dbsql_set_result_null(p) - dbsql_func_t *p; +dbsql_set_result_null(dbsql_func_t* p) { DBSQL_ASSERT(!p->isStep); if (p->s.flags & MEM_Dyn) { @@ -570,9 +543,7 @@ dbsql_set_result_null(p) * EXTERN: void dbsql_set_result_int __P((dbsql_func_t *, int)); */ void -dbsql_set_result_int(p, result) - dbsql_func_t *p; - int result; +dbsql_set_result_int(dbsql_func_t* p, int result) { DBSQL_ASSERT(!p->isStep); if (p->s.flags & MEM_Dyn) { @@ -601,9 +572,7 @@ dbsql_set_result_int64(p, result) /*TODO*/ * EXTERN: void dbsql_set_result_double __P((dbsql_func_t *, double)); */ void -dbsql_set_result_double(p, result) - dbsql_func_t *p; - double result; +dbsql_set_result_double(dbsql_func_t* p, double result) { DBSQL_ASSERT(!p->isStep); if (p->s.flags & MEM_Dyn) { @@ -670,8 +639,7 @@ dbsql_set_result_varchar(p, result, size, finalize) /*TODO*/ * EXTERN: void *dbsql_user_data __P((dbsql_func_t *)); */ void * -dbsql_user_data(p) - dbsql_func_t *p; +dbsql_user_data(dbsql_func_t* p) { DBSQL_ASSERT(p && p->pFunc); return p->pFunc->pUserData; @@ -690,9 +658,7 @@ dbsql_user_data(p) * EXTERN: void *dbsql_aggregate_context __P((dbsql_func_t *, int)); */ void * -dbsql_aggregate_context(p, num_bytes) - dbsql_func_t *p; - int num_bytes; +dbsql_aggregate_context(dbsql_func_t* p, int num_bytes) { DBSQL_ASSERT(p && p->pFunc && p->pFunc->xStep); if (p->pAgg == 0) { @@ -718,8 +684,7 @@ dbsql_aggregate_context(p, num_bytes) * EXTERN: int dbsql_aggregate_count __P((dbsql_func_t *)); */ int -dbsql_aggregate_count(p) - dbsql_func_t *p; +dbsql_aggregate_count(dbsql_func_t* p) { DBSQL_ASSERT(p && p->pFunc && p->pFunc->xStep); return p->cnt; @@ -733,10 +698,7 @@ dbsql_aggregate_count(p) * PUBLIC: void __vdbe_print_op __P((FILE *, int, vdbe_op_t *)); */ void -__vdbe_print_op(out, pc, op) - FILE *out; - int pc; - vdbe_op_t *op; +__vdbe_print_op(FILE* out, int pc, vdbe_op_t* op) { char *p3; char ptr[40]; @@ -766,8 +728,7 @@ __vdbe_print_op(out, pc, op) * PUBLIC: int __vdbe_list __P((vdbe_t *)); */ int -__vdbe_list(vm) - vdbe_t *vm; +__vdbe_list(vdbe_t* vm) { int i; DBSQL *db = vm->db; @@ -853,12 +814,7 @@ __vdbe_list(vm) * explain_p True if the EXPLAIN keywords is present */ void -__vdbe_make_ready(vm, num_var, callback, callback_arg, explain_p) - vdbe_t *vm; - int num_var; - dbsql_callback callback; - void *callback_arg; - int explain_p; +__vdbe_make_ready(vdbe_t* vm, int num_var, dbsql_callback callback, void* callback_arg, int explain_p) { int n; @@ -936,8 +892,7 @@ __vdbe_make_ready(vm, num_var, callback, callback_arg, explain_p) * PUBLIC: void __vdbe_sorter_reset __P((vdbe_t *)); */ void -__vdbe_sorter_reset(vm) - vdbe_t *vm; +__vdbe_sorter_reset(vdbe_t* vm) { while(vm->pSort) { sorter_t *s = vm->pSort; @@ -961,8 +916,7 @@ __vdbe_sorter_reset(vm) * PUBLIC: void __vdbe_agg_reset __P((agg_t *)); */ void -__vdbe_agg_reset(agg) - agg_t *agg; +__vdbe_agg_reset(agg_t* agg) { int i; hash_ele_t *p; @@ -1004,8 +958,7 @@ __vdbe_agg_reset(agg) * PUBLIC: void __vdbe_keylist_free __P((keylist_t *)); */ void -__vdbe_keylist_free(p) - keylist_t *p; +__vdbe_keylist_free(keylist_t* p) { while(p) { keylist_t *next = p->pNext; @@ -1022,8 +975,7 @@ __vdbe_keylist_free(p) * PUBLIC: void __vdbe_cleanup_cursor __P((cursor_t *)); */ void -__vdbe_cleanup_cursor(cx) - cursor_t *cx; +__vdbe_cleanup_cursor(cursor_t* cx) { if (cx->pCursor) { __sm_close_cursor(cx->pCursor); @@ -1042,8 +994,7 @@ __vdbe_cleanup_cursor(cx) * STATIC: static void __close_all_cursors __P((vdbe_t *)); */ static void -__close_all_cursors(vm) - vdbe_t *vm; +__close_all_cursors(vdbe_t* vm) { int i; for (i = 0; i < vm->nCursor; i++) { @@ -1065,8 +1016,7 @@ __close_all_cursors(vm) * STATIC: static void __cleanup __P((vdbe_t *)); */ static void -__cleanup(vm) - vdbe_t *vm; +__cleanup(vdbe_t* vm) { int i; if (vm->aStack) { @@ -1142,9 +1092,7 @@ __cleanup(vm) * PUBLIC: int __vdbe_reset __P((vdbe_t *, char **)); */ int -__vdbe_reset(vm, err_msgs) - vdbe_t *vm; - char **err_msgs; +__vdbe_reset(vdbe_t* vm, char* *err_msgs) { int i; DBSQL *db = vm->db; @@ -1216,9 +1164,7 @@ __vdbe_reset(vm, err_msgs) * PUBLIC: int __vdbe_finalize __P((vdbe_t *, char **)); */ int -__vdbe_finalize(vm, err_msgs) - vdbe_t *vm; - char **err_msgs; +__vdbe_finalize(vdbe_t* vm, char* *err_msgs) { int rc; DBSQL *db; @@ -1292,8 +1238,7 @@ __api_bind(p, i, val, len, copy) * PUBLIC: void __vdbe_delete __P((vdbe_t *)); */ void -__vdbe_delete(vm) - vdbe_t *vm; +__vdbe_delete(vdbe_t* vm) { int i; if (vm == 0) @@ -1348,8 +1293,7 @@ __vdbe_delete(vm) * PUBLIC: int __vdbe_byte_swap __P((int)); */ int -__vdbe_byte_swap(x) - int x; +__vdbe_byte_swap(int x) { union { char buf[sizeof(int)]; @@ -1371,8 +1315,7 @@ __vdbe_byte_swap(x) * PUBLIC: int __vdbe_cursor_moveto __P((cursor_t *)); */ int -__vdbe_cursor_moveto(p) - cursor_t *p; +__vdbe_cursor_moveto(cursor_t* p) { if (p->deferredMoveto) { int res; diff --git a/test/scr050/crashtest1.c b/test/scr050/crashtest1.c index ec7f39b..1ad958f 100644 --- a/test/scr050/crashtest1.c +++ b/test/scr050/crashtest1.c @@ -29,7 +29,7 @@ static void do_some_sql(int parent){ int rc = DBSQL_SUCCESS; sqlite *db; int cnt = 0; - static char zBig[] = + static char zBig[] = "-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" "-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; @@ -50,7 +50,7 @@ static void do_some_sql(int parent){ srand(getpid()); while( rc==DBSQL_SUCCESS ){ cnt++; - rc = dbsql_exec_printf(db, + rc = dbsql_exec_printf(db, "INSERT INTO t1 VALUES(%d,'%d%s')", 0, 0, &zErr, rand(), rand(), zBig); } diff --git a/test/scr050/dbsql_tclsh.c b/test/scr050/dbsql_tclsh.c index 0a78013..43e9a3c 100644 --- a/test/scr050/dbsql_tclsh.c +++ b/test/scr050/dbsql_tclsh.c @@ -103,10 +103,7 @@ struct callback_data { * Decode a pointer encoded in a string to an pointer to a structure. */ static int -get_dbsql_from_ptr(interp, args, dbsqlp) - Tcl_Interp *interp; - const char *args; - DBSQL **dbsqlp; +get_dbsql_from_ptr(Tcl_Interp *interp, const char *args, DBSQL **dbsqlp) { if (sscanf(args, PTR_FMT, (void**)dbsqlp) != 1 && (args[0] != '0' || args[1] != 'x' || @@ -123,10 +120,7 @@ get_dbsql_from_ptr(interp, args, dbsqlp) * Decode a pointer to an sqlvm_t object. */ static int -get_sqlvm_from_ptr(interp, args, sqlvmp) - Tcl_Interp *interp; - const char *args; - dbsql_stmt_t **sqlvmp; +get_sqlvm_from_ptr(Tcl_Interp *interp, const char *args, dbsql_stmt_t **sqlvmp) { if (sscanf(args, PTR_FMT, (void**)sqlvmp) != 1) { Tcl_AppendResult(interp, @@ -150,10 +144,7 @@ get_sqlvm_from_ptr(interp, args, sqlvmp) * that helps. If nothing works, a fatal error is generated. */ static int -__encode_as_ptr(interp, ptr, p) - Tcl_Interp *interp; - char *ptr; - void *p; +__encode_as_ptr(Tcl_Interp* interp, char* ptr, void* p) { void *p2; @@ -180,11 +171,7 @@ __encode_as_ptr(interp, ptr, p) * Returns: The name of an open database. */ static int -t__dbsql_env_create(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +t__dbsql_env_create(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { DBSQL *dbp; char *err_msgs; @@ -215,11 +202,7 @@ t__dbsql_env_create(_dbctx, interp, argc, argv) * The callback routine for DBSQL->exec_printf(). */ static int -exec_printf_cb(arg, argc, argv, name) - void *arg; - int argc; - char **argv; - char **name; +exec_printf_cb(void* arg, int argc, char* *argv, char* *name) { Tcl_DString *str; int i; @@ -246,11 +229,7 @@ exec_printf_cb(arg, argc, argv, name) * one %s or %q. STRING is the value inserted into %s or %q. */ static int -t__exec_printf(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +t__exec_printf(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { DBSQL *dbp; Tcl_DString str; @@ -291,11 +270,7 @@ FIXME * Return the result. */ static int -test_xprintf(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +test_xprintf(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { int i; char *result = 0; @@ -324,11 +299,7 @@ test_xprintf(_dbctx, interp, argc, argv) * one %s or %q. STRING is the value inserted into %s or %q. */ static int -t__get_table_printf(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +t__get_table_printf(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { DBSQL *dbp; Tcl_DString str; @@ -379,11 +350,7 @@ t__get_table_printf(_dbctx, interp, argc, argv) * Returns the integer ROWID of the most recent insert. */ static int -t__last_rowid(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +t__last_rowid(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { DBSQL *dbp; dbsql_ctx_t *dbctx = (dbsql_ctx_t *)_dbctx; @@ -410,11 +377,7 @@ t__last_rowid(_dbctx, interp, argc, argv) * Closes the database. */ static int -t__test_close(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +t__test_close(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { DBSQL *dbp; @@ -490,11 +453,7 @@ dstr_append(p, z, divider) * Invoked for each callback from dbsql_exec */ static int -exec_func_callback(data, argc, argv, notused) - void *data; - int argc; - char **argv; - char **notused; +exec_func_callback(void* data, int argc, char* *argv, char* *notused) { struct dstr *p; int i; @@ -552,11 +511,7 @@ exec_func(context, argc, argv) * to test the DBSQL_MISUSE detection logic. */ static int -t__create_function(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +t__create_function(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { DBSQL *dbp; extern void Md5_Register(DBSQL*); @@ -586,7 +541,7 @@ typedef struct cnt { /* * count_step -- - * + * */ static void count_step(context, argc, argv) @@ -603,11 +558,10 @@ count_step(context, argc, argv) /* * count_finalize -- - * + * */ static void -count_finalize(context) - dbsql_func_t *context; +count_finalize(dbsql_func_t* context) { cnt_t *p; p = dbsql_aggregate_context(context, sizeof(*p)); @@ -627,11 +581,7 @@ count_finalize(context) * to test the DBSQL_MISUSE detection logic. */ static int -t__create_aggregate(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +t__create_aggregate(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { DBSQL *dbp; @@ -659,11 +609,7 @@ TODO * Call mprintf with three integer arguments. */ static int -dbsql_mprintf_int(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +dbsql_mprintf_int(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { int a[3], i; char *buf; @@ -692,11 +638,7 @@ dbsql_mprintf_int(_dbctx, interp, argc, argv) * Call mprintf with two integer arguments and one string argument. */ static int -dbsql_mprintf_str(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +dbsql_mprintf_str(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { int a[3], i; char *buf; @@ -725,11 +667,7 @@ dbsql_mprintf_str(_dbctx, interp, argc, argv) * Call mprintf with two integer arguments and one double argument */ static int -dbsql_mprintf_double(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +dbsql_mprintf_double(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { int a[3], i; double r; @@ -764,11 +702,7 @@ dbsql_mprintf_double(_dbctx, interp, argc, argv) */ #ifdef MEMORY_DEBUG static int -dbsql_malloc_fail(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +dbsql_malloc_fail(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { int n; @@ -796,11 +730,7 @@ dbsql_malloc_fail(_dbctx, interp, argc, argv) */ #ifdef MEMORY_DEBUG static int -dbsql_malloc_stat(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +dbsql_malloc_stat(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { char buf[200]; @@ -822,11 +752,7 @@ dbsql_malloc_stat(_dbctx, interp, argc, argv) * the event of a program crash. */ static int -t__dbsql_abort(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +t__dbsql_abort(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { COMPQUIET(_dbctx, NULL); @@ -878,11 +804,7 @@ test_func(context, argc, argv) * Register the test SQL function on the database DB under the name NAME. */ static int -t__register_func(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +t__register_func(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { DBSQL *dbp; int rc; @@ -913,11 +835,7 @@ t__register_func(_dbctx, interp, argc, argv) * Return non-zero should cause the query to abort. */ static int -__remember_data_types(interp, cols, argv, colv) - Tcl_Interp *interp; - int cols; - char **argv; - char **colv; +__remember_data_types(Tcl_Interp* interp, int cols, char* *argv, char* *colv) { int i; Tcl_Obj *list, *elem; @@ -946,11 +864,7 @@ __remember_data_types(interp, cols, argv, colv) * against the database connection. */ static int -t__dbsql_datatypes(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +t__dbsql_datatypes(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { DBSQL *dbp; int rc; @@ -981,11 +895,7 @@ t__dbsql_datatypes(_dbctx, interp, argc, argv) * into TAILVAR. */ static int -t__dbsql_compile(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +t__dbsql_compile(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { DBSQL *dbp; dbsql_stmt_t *vm; @@ -1029,11 +939,7 @@ t__dbsql_compile(_dbctx, interp, argc, argv) * Column results are written into three variables. */ static int -t__dbsql_step(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +t__dbsql_step(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { DBSQL *dbp; dbsql_stmt_t *vm; @@ -1102,11 +1008,7 @@ t__dbsql_step(_dbctx, interp, argc, argv) * Shutdown a virtual machine. */ static int -t__dbsql_finalize(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +t__dbsql_finalize(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { DBSQL *dbp; dbsql_stmt_t *vm; @@ -1142,11 +1044,7 @@ t__dbsql_finalize(_dbctx, interp, argc, argv) * Reset a virtual machine and prepare it to be run again. */ static int -t__dbsql_reset(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +t__dbsql_reset(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { DBSQL *dbp; dbsql_stmt_t *vm; @@ -1193,11 +1091,7 @@ static char *dbsql_static_bind_value = 0; * of the VALUE is made. */ static int -t__dbsql_bind(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +t__dbsql_bind(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { DBSQL *dbp; dbsql_stmt_t *vm; @@ -1252,11 +1146,7 @@ t__dbsql_bind(_dbctx, interp, argc, argv) * fire. Then additional breakpoints can be set to trace down the bug. */ static int -t__dbsql_breakpoint(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +t__dbsql_breakpoint(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { COMPQUIET(_dbctx, NULL); @@ -1267,8 +1157,7 @@ t__dbsql_breakpoint(_dbctx, interp, argc, argv) * Register commands with the TCL interpreter. */ int -__testset_1_init(interp) - Tcl_Interp *interp; +__testset_1_init(Tcl_Interp* interp) { extern int dbsql_search_count; extern int dbsql_interrupt_count; @@ -1343,11 +1232,7 @@ FIXME * col_names Name for each column */ static int -__tcl_process_row(_data, ncol, col, col_names) - void *_data; - int ncol; - char **col; - char **col_names; +__tcl_process_row(void* _data, int ncol, char* *col, char* *col_names) { callback_data_t *data = (callback_data_t*)_data; int i, rc; @@ -1388,7 +1273,7 @@ __tcl_process_row(_data, ncol, col, col_names) Tcl_DStringFree(&tcol); Tcl_ExternalToUtfDString(NULL, col_names[i+ncol], -1, &tcol); - Tcl_SetVar2(data->interp, data->array, + Tcl_SetVar2(data->interp, data->array, Tcl_DStringValue(&type), Tcl_DStringValue(&tcol), TCL_LIST_ELEMENT | @@ -1408,7 +1293,7 @@ __tcl_process_row(_data, ncol, col, col_names) Tcl_DStringInit(&tcol); Tcl_ExternalToUtfDString(NULL, z, -1, &tcol); Tcl_SetVar2(data->interp, data->array, - data->col_names[i], + data->col_names[i], Tcl_DStringValue(&tcol), 0); Tcl_DStringFree(&tcol); } @@ -1557,11 +1442,7 @@ __tcl_process_row2(_data, ncol, col, col_names) * col_names Name for each column */ static int -__tcl_process_row3(_data, ncol, col, col_names) - void *_data; - int ncol; - char **col; - char **col_names; +__tcl_process_row3(void* _data, int ncol, char* *col, char* *col_names) { Tcl_Interp *interp = (Tcl_Interp*)_data; Tcl_Obj *elem; @@ -1589,8 +1470,7 @@ __tcl_process_row3(_data, ncol, col, col_names) * Called when the command is deleted. */ static void -__tcl_delete_cmd(_dbctx) - void *_dbctx; +__tcl_delete_cmd(void* _dbctx) { dbsql_ctx_t *dbctx = (dbsql_ctx_t*)_dbctx; dbctx->dbp->close(dbctx->dbp); @@ -1647,8 +1527,7 @@ __tcl_busy_handler(cd, table, tries) * This routine is invoked as the 'progress callback' for the database. */ static int -__tcl_progress_handler(cd) - void *cd; +__tcl_progress_handler(void* cd) { int rc; dbsql_ctx_t *dbctx = (dbsql_ctx_t*)cd; @@ -1690,8 +1569,7 @@ __tcl_trace_handler(_dbctx, sql) * of being committed. */ static int -__tcl_commit_handler(_dbctx) - void *_dbctx; +__tcl_commit_handler(void* _dbctx) { int rc; dbsql_ctx_t *dbctx = (dbsql_ctx_t*)_dbctx; @@ -1727,7 +1605,7 @@ __tcl_eval_sql_fn(context, argc, argv) rc = Tcl_Eval(p->interp, Tcl_DStringValue(&cmd)); if (rc) { dbsql_set_result_error(context, - Tcl_GetStringResult(p->interp), -1); + Tcl_GetStringResult(p->interp), -1); } else { dbsql_set_result_string(context, Tcl_GetStringResult(p->interp), -1); @@ -1957,7 +1835,7 @@ __tcl_dbsql_cmd_impl(_dbctx, interp, objc, objv) case DBSQL__PROGRESS: /* * $db progress ?N CALLBACK? - * + * * Invoke the given callback every N virtual machine * opcodes while executing queries. */ @@ -2336,8 +2214,7 @@ __tcl_sql_func_randstr(context, argc, argv) * external linkage. */ void -__register_tcl_sql_funcs(dbp) - DBSQL *dbp; +__register_tcl_sql_funcs(DBSQL* dbp) { static struct { char *name; @@ -2425,11 +2302,7 @@ __register_tcl_sql_funcs(dbp) * correctly. */ static int -__tcl_dbsql_impl(_dbctx, interp, objc, objv) - void *_dbctx; - Tcl_Interp *interp; - int objc; - Tcl_Obj *const*objv; +__tcl_dbsql_impl(void* _dbctx, Tcl_Interp* interp, int objc, Tcl_Obj* const*objv) { int rc; int mode; @@ -2555,8 +2428,7 @@ __tcl_dbsql_impl(_dbctx, interp, objc, objv) * By using this single name, there are no Tcl namespace issues. */ int -dbsql_init_tcl_interface(interp) - Tcl_Interp *interp; +dbsql_init_tcl_interface(Tcl_Interp* interp) { const char *cmd = "dbsql"; @@ -2594,9 +2466,7 @@ static char main_loop[] = * main -- */ int -main(argc, argv) - int argc; - char **argv; +main(int argc, char* *argv) { int i; const char *info; diff --git a/test/scr050/tcl_dbsql.c b/test/scr050/tcl_dbsql.c index 1415fc0..2ffea0c 100644 --- a/test/scr050/tcl_dbsql.c +++ b/test/scr050/tcl_dbsql.c @@ -14,9 +14,9 @@ /* * If TCL uses UTF-8 and DBSQL is configured to use iso8859, then we - * have to do a translation when going between the two. Set the + * have to do a translation when going between the two. Set the * UTF_TRANSLATION_NEEDED macro to indicate that we need to do - * this translation. + * this translation. */ #if defined(TCL_UTF_MAX) && !defined(DBSQL_UTF8_ENCODING) #define UTF_TRANSLATION_NEEDED 1 @@ -125,7 +125,7 @@ static int __tcl_process_row(_data, ncol, col, col_names) Tcl_DStringFree(&tcol); Tcl_ExternalToUtfDString(NULL, col_names[i+ncol], -1, &tcol); - Tcl_SetVar2(data->interp, data->array, + Tcl_SetVar2(data->interp, data->array, Tcl_DStringValue(&type), Tcl_DStringValue(&tcol), TCL_LIST_ELEMENT | @@ -145,7 +145,7 @@ static int __tcl_process_row(_data, ncol, col, col_names) Tcl_DStringInit(&tcol); Tcl_ExternalToUtfDString(NULL, z, -1, &tcol); Tcl_SetVar2(data->interp, data->array, - data->col_names[i], + data->col_names[i], Tcl_DStringValue(&tcol), 0); Tcl_DStringFree(&tcol); } @@ -294,11 +294,7 @@ __tcl_process_row2(_data, ncol, col, col_names) * col_names Name for each column */ static int -__tcl_process_row3(_data, ncol, col, col_names) - void *_data; - int ncol; - char **col; - char **col_names; +__tcl_process_row3(void* _data, int ncol, char* *col, char* *col_names) { Tcl_Interp *interp = (Tcl_Interp*)_data; Tcl_Obj *elem; @@ -326,8 +322,7 @@ __tcl_process_row3(_data, ncol, col, col_names) * Called when the command is deleted. */ static void -__tcl_delete_cmd(_dbctx) - void *_dbctx; +__tcl_delete_cmd(void* _dbctx) { dbsql_ctx_t *dbctx = (dbsql_ctx_t*)_dbctx; dbctx->dbp->close(dbctx->dbp); @@ -354,7 +349,8 @@ __tcl_delete_cmd(_dbctx) * to execute SQL. */ static int -__tcl_busy_handler(cd, table, tries) +__tcl_busy_handler(dbp, cd, table, tries) + DBSQL *dbp; void *cd; const char *table; int tries; @@ -384,8 +380,7 @@ __tcl_busy_handler(cd, table, tries) * This routine is invoked as the 'progress callback' for the database. */ static int -__tcl_progress_handler(cd) - void *cd; +__tcl_progress_handler(void* cd) { int rc; dbsql_ctx_t *dbctx = (dbsql_ctx_t*)cd; @@ -427,8 +422,7 @@ __tcl_trace_handler(_dbctx, sql) * of being committed. */ static int -__tcl_commit_handler(_dbctx) - void *_dbctx; +__tcl_commit_handler(void* _dbctx) { int rc; dbsql_ctx_t *dbctx = (dbsql_ctx_t*)_dbctx; @@ -464,7 +458,7 @@ __tcl_eval_sql_fn(context, argc, argv) rc = Tcl_Eval(p->interp, Tcl_DStringValue(&cmd)); if (rc) { dbsql_set_result_error(context, - Tcl_GetStringResult(p->interp), -1); + Tcl_GetStringResult(p->interp), -1); } else { dbsql_set_result_string(context, Tcl_GetStringResult(p->interp), -1); @@ -585,7 +579,7 @@ __tcl_dbsql_cmd_impl(_dbctx, interp, objc, objv) "errorcode", "eval", "function", "last_inserted_rowid", "onecolumn", "progress", "timeout", "trace", - 0 + 0 }; enum DBSQL_enum { DBSQL__AUTHORIZER, DBSQL__BUSY, DBSQL__CHANGES, @@ -696,7 +690,7 @@ __tcl_dbsql_cmd_impl(_dbctx, interp, objc, objv) case DBSQL__PROGRESS: /* * $db progress ?N CALLBACK? - * + * * Invoke the given callback every N virtual machine * opcodes while executing queries. */ @@ -923,7 +917,7 @@ __tcl_dbsql_cmd_impl(_dbctx, interp, objc, objv) break; case DBSQL__LAST_INSERT_ROWID: /* - * $db last_inserted_rowid + * $db last_inserted_rowid * * Return an integer which is the ROWID for the most * recent insert. @@ -1050,11 +1044,7 @@ __tcl_dbsql_cmd_impl(_dbctx, interp, objc, objv) * correctly. */ static int -__tcl_dbsql_impl(_dbctx, interp, objc, objv) - void *_dbctx; - Tcl_Interp *interp; - int objc; - Tcl_Obj *const*objv; +__tcl_dbsql_impl(void* _dbctx, Tcl_Interp* interp, int objc, Tcl_Obj* const*objv) { int rc; int mode; @@ -1189,8 +1179,7 @@ __tcl_dbsql_impl(_dbctx, interp, objc, objv) * By using this single name, there are no Tcl namespace issues. */ int -dbsql_init_tcl_interface(interp) - Tcl_Interp *interp; +dbsql_init_tcl_interface(Tcl_Interp* interp) { const char *cmd = "dbsql"; diff --git a/test/scr050/tcl_internal.c b/test/scr050/tcl_internal.c index 060794a..6b9532a 100644 --- a/test/scr050/tcl_internal.c +++ b/test/scr050/tcl_internal.c @@ -30,10 +30,7 @@ * with the name and pointer, id and type. */ DBSQLTCL_INFO * -__dbsql_tcl_new_info(interp, dbp, name) - Tcl_Interp *interp; - DBSQL *dbp; - char *name; +__dbsql_tcl_new_info(Tcl_Interp* interp, DBSQL* dbp, char* name) { DBSQLTCL_INFO *p; int i, ret; @@ -110,8 +107,7 @@ __dbsql_tcl_name_to_info(name) * PUBLIC: void __dbsql_tcl_delete_info __P((DBSQLTCL_INFO *)); */ void -__dbsql_tcl_delete_info(p) - DBSQLTCL_INFO *p; +__dbsql_tcl_delete_info(DBSQLTCL_INFO* p) { if (p == NULL) return; @@ -133,9 +129,7 @@ __dbsql_tcl_delete_info(p) * PUBLIC: void __dbsql_tcl_set_info_dbp __P((DBSQLTCL_INFO *, void *)); */ void -__dbsql_tcl_set_info_dbp(p, data) - DBSQLTCL_INFO *p; - void *data; +__dbsql_tcl_set_info_dbp(DBSQLTCL_INFO* p, void* data) { if (p == NULL) return; @@ -172,8 +166,7 @@ __dbsql_tcl_return_setup(interp, ret, ok, errmsg) msg = dbsql_strerror(ret); Tcl_AppendResult(interp, msg, NULL); - if (ok) - return (TCL_OK); +if(return (TCL_OK)) else { Tcl_SetErrorCode(interp, "DBSQL", msg, NULL); return (TCL_ERROR); @@ -184,10 +177,7 @@ __dbsql_tcl_return_setup(interp, ret, ok, errmsg) * PUBLIC: int __dbsql_tcl_error_setup __P((Tcl_Interp *, int, char *)); */ int -__dbsql_tcl_error_setup(interp, ret, errmsg) - Tcl_Interp *interp; - int ret; - char *errmsg; +__dbsql_tcl_error_setup(Tcl_Interp* interp, int ret, char* errmsg) { Tcl_SetErrno(ret); Tcl_AppendResult(interp, errmsg, ":", Tcl_PosixError(interp), NULL); diff --git a/test/scr050/tcl_md5.c b/test/scr050/tcl_md5.c index bdc5af8..071cd1d 100644 --- a/test/scr050/tcl_md5.c +++ b/test/scr050/tcl_md5.c @@ -169,8 +169,7 @@ MD5Transform(buf, in) * initialization constants. */ static void -MD5Init(pCtx) - MD5Context *pCtx; +MD5Init(MD5Context* pCtx) { struct Context *ctx = (struct Context *)pCtx; ctx->buf[0] = 0x67452301; @@ -376,8 +375,7 @@ md5file_cmd(cd, interp, argc, argv) * Register the two TCL commands above with the TCL interpreter. */ int -__testset_MD5_init(interp) - Tcl_Interp *interp; +__testset_MD5_init(Tcl_Interp* interp) { Tcl_CreateCommand(interp, "md5", (Tcl_CmdProc*)md5_cmd, 0, 0); Tcl_CreateCommand(interp, "md5file", (Tcl_CmdProc*)md5file_cmd, 0, 0); @@ -410,8 +408,7 @@ __tcl_sql_func_md5step(context, argc, argv) } void -__tcl_sql_func_md5finalize(context) - dbsql_func_t *context; +__tcl_sql_func_md5finalize(dbsql_func_t* context) { MD5Context *p; unsigned char digest[16]; diff --git a/test/scr050/tcl_printf.c b/test/scr050/tcl_printf.c index 7179844..5d9363d 100644 --- a/test/scr050/tcl_printf.c +++ b/test/scr050/tcl_printf.c @@ -73,10 +73,7 @@ get_sqlvm_from_ptr(interp, args, sqlvmp) * that helps. If nothing works, a fatal error is generated. */ static int -__encode_as_ptr(interp, ptr, p) - Tcl_Interp *interp; - char *ptr; - void *p; +__encode_as_ptr(Tcl_Interp* interp, char* ptr, void* p) { void *p2; @@ -103,11 +100,7 @@ __encode_as_ptr(interp, ptr, p) * Returns: The name of an open database. */ static int -test_dbsql_env_create(notused, interp, argc, argv) - void *notused; - Tcl_Interp *interp; - int argc; - char **argv; +test_dbsql_env_create(void* notused, Tcl_Interp* interp, int argc, char* *argv) { DBSQL *db; char *err_msgs; @@ -137,11 +130,7 @@ test_dbsql_env_create(notused, interp, argc, argv) * The callback routine for DBSQL->exec_printf(). */ static int -exec_printf_cb(arg, argc, argv, name) - void *arg; - int argc; - char **argv; - char **name; +exec_printf_cb(void* arg, int argc, char* *argv, char* *name) { Tcl_DString *str; int i; @@ -168,11 +157,7 @@ exec_printf_cb(arg, argc, argv, name) * one %s or %q. STRING is the value inserted into %s or %q. */ static int -test_exec_printf(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +test_exec_printf(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { DBSQL *dbp; Tcl_DString str; @@ -211,11 +196,7 @@ test_exec_printf(_dbctx, interp, argc, argv) * Return the result. */ static int -test_xprintf(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +test_xprintf(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { int i; char *result; @@ -240,11 +221,7 @@ test_xprintf(_dbctx, interp, argc, argv) * one %s or %q. STRING is the value inserted into %s or %q. */ static int -test_get_table_printf(notused, interp, argc, argv) - void *notused; - Tcl_Interp *interp; - int argc; - char **argv; +test_get_table_printf(void* notused, Tcl_Interp* interp, int argc, char* *argv) { DBSQL *db; Tcl_DString str; @@ -294,11 +271,7 @@ test_get_table_printf(notused, interp, argc, argv) * Returns the integer ROWID of the most recent insert. */ static int -test_last_rowid(notused, interp, argc, argv) - void *notused; - Tcl_Interp *interp; - int argc; - char **argv; +test_last_rowid(void* notused, Tcl_Interp* interp, int argc, char* *argv) { DBSQL *db; char buf[30]; @@ -323,11 +296,7 @@ test_last_rowid(notused, interp, argc, argv) * Closes the database. */ static int -test_close(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +test_close(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { DBSQL *db; dbsql_ctx_t *dbctx = (dbsql_ctx_t*)_dbctx; @@ -402,11 +371,7 @@ dstr_append(p, z, divider) * Invoked for each callback from dbsql_exec */ static int -exec_func_callback(data, argc, argv, notused) - void *data; - int argc; - char **argv; - char **notused; +exec_func_callback(void* data, int argc, char* *argv, char* *notused) { struct dstr *p; int i; @@ -464,11 +429,7 @@ exec_func(context, argc, argv) * to test the DBSQL_MISUSE detection logic. */ static int -test_create_function(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +test_create_function(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { DBSQL *db; extern void Md5_Register(DBSQL*); @@ -515,8 +476,7 @@ count_step(context, argc, argv) * */ static void -count_finalize(context) - dbsql_func_t *context; +count_finalize(dbsql_func_t* context) { cnt_t *p; p = dbsql_aggregate_context(context, sizeof(*p)); @@ -536,11 +496,7 @@ count_finalize(context) * to test the DBSQL_MISUSE detection logic. */ static int -test_create_aggregate(notused, interp, argc, argv) - void *notused; - Tcl_Interp *interp; - int argc; - char **argv; +test_create_aggregate(void* notused, Tcl_Interp* interp, int argc, char* *argv) { DBSQL *db; @@ -569,11 +525,7 @@ TODO * Call mprintf with three integer arguments. */ static int -dbsql_mprintf_int(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +dbsql_mprintf_int(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { int a[3], i; char *buf; @@ -600,11 +552,7 @@ dbsql_mprintf_int(_dbctx, interp, argc, argv) * Call mprintf with two integer arguments and one string argument. */ static int -dbsql_mprintf_str(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +dbsql_mprintf_str(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { int a[3], i; char *buf; @@ -633,11 +581,7 @@ dbsql_mprintf_str(_dbctx, interp, argc, argv) * Call mprintf with two integer arguments and one double argument */ static int -dbsql_mprintf_double(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +dbsql_mprintf_double(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { int a[3], i; double r; @@ -672,11 +616,7 @@ dbsql_mprintf_double(_dbctx, interp, argc, argv) */ #ifdef MEMORY_DEBUG static int -dbsql_malloc_fail(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +dbsql_malloc_fail(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { int n; @@ -704,11 +644,7 @@ dbsql_malloc_fail(_dbctx, interp, argc, argv) */ #ifdef MEMORY_DEBUG static int -dbsql_malloc_stat(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +dbsql_malloc_stat(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { char buf[200]; @@ -730,11 +666,7 @@ dbsql_malloc_stat(_dbctx, interp, argc, argv) * the event of a program crash. */ static int -dbsql_abort(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +dbsql_abort(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { COMPQUIET(notused, NULL); @@ -786,11 +718,7 @@ test_func(context, argc, argv) * Register the test SQL function on the database DB under the name NAME. */ static int -test_register_func(_dbctx, interp, argc, argv) - void *_dbctx; - Tcl_Interp *interp; - int argc; - char **argv; +test_register_func(void* _dbctx, Tcl_Interp* interp, int argc, char* *argv) { DBSQL *db; int rc; @@ -1113,8 +1041,7 @@ static int test_breakpoint( * Register commands with the TCL interpreter. */ int -__testset_1_Init(interp) - Tcl_Interp *interp; +__testset_1_Init(Tcl_Interp* interp) { extern int dbsql_search_count; extern int dbsql_interrupt_count; diff --git a/test/scr050/tcl_sql_funcs.c b/test/scr050/tcl_sql_funcs.c index 265ccaa..23a488b 100644 --- a/test/scr050/tcl_sql_funcs.c +++ b/test/scr050/tcl_sql_funcs.c @@ -22,8 +22,7 @@ extern void __tcl_sql_func_md5finalize(dbsql_func_t *); * external linkage. */ void -__register_tcl_sql_funcs(dbp) - DBSQL *dbp; +__register_tcl_sql_funcs(DBSQL* dbp) { static struct { char *name; diff --git a/test/scr050/tcl_threads.c b/test/scr050/tcl_threads.c index 373afad..1328bdf 100644 --- a/test/scr050/tcl_threads.c +++ b/test/scr050/tcl_threads.c @@ -50,7 +50,7 @@ static Thread threadset[N_THREAD]; /* -** The main loop for a thread. Threads use busy waiting. +** The main loop for a thread. Threads use busy waiting. */ static void *thread_main(void *pArg){ Thread *p = (Thread*)pArg;