sterling Tue Jul 1 20:43:00 2003 EDT Modified files: /php-src/ext/sqlite sess_sqlite.c Log: set synching to off cleanup some silly code Index: php-src/ext/sqlite/sess_sqlite.c diff -u php-src/ext/sqlite/sess_sqlite.c:1.5 php-src/ext/sqlite/sess_sqlite.c:1.6 --- php-src/ext/sqlite/sess_sqlite.c:1.5 Tue Jul 1 20:04:58 2003 +++ php-src/ext/sqlite/sess_sqlite.c Tue Jul 1 20:43:00 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: sess_sqlite.c,v 1.5 2003/07/02 00:04:58 sterling Exp $ */ +/* $Id: sess_sqlite.c,v 1.6 2003/07/02 00:43:00 sterling Exp $ */ #include "php.h" @@ -25,17 +25,11 @@ #include "ext/session/php_session.h" #include <sqlite.h> - +#define SQLITE_RETVAL(__r) ((__r) == SQLITE_OK ? SUCCESS : FAILURE) #define PS_SQLITE_DATA sqlite *db = (sqlite*)PS_GET_MOD_DATA() extern int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out); extern int sqlite_decode_binary(const unsigned char *in, unsigned char *out); -#define CREATE_TBL_QUERY "CREATE TABLE session_data(sess_id TEXT PRIMARY KEY, value TEXT, updated INTEGER)" -#define INSERT_QUERY "REPLACE INTO session_data VALUES('%q', '%q', %d)" -#define SELECT_QUERY "SELECT value FROM session_data WHERE sess_id='%q' LIMIT 1" -#define GC_QUERY "DELETE FROM session_data WHERE (%d - updated) > %d" -#define DELETE_QUERY "DELETE FROM session_data WHERE sess_id='%q'" - PS_FUNCS(sqlite); ps_module ps_mod_sqlite = { @@ -88,11 +82,15 @@ /* allow up to 1 minute when busy */ sqlite_busy_timeout(db, 60000); - /* sqlite_exec(db, "PRAGMA default_synchronous = OFF", NULL, NULL, NULL); */ + sqlite_exec(db, "PRAGMA default_synchronous = OFF", NULL, NULL, NULL); /* This will fail if the table already exists, but that's not a big problem. I'm unclear as to how to check for a table's existence in SQLite -- that would be better here. */ - sqlite_exec(db, CREATE_TBL_QUERY, NULL, NULL, NULL); + sqlite_exec(db, + "CREATE TABLE session_data (" + " sess_id TEXT PRIMARY KEY," + " value TEXT, updated INTEGER " + ")", NULL, NULL, NULL); PS_SET_MOD_DATA(db); @@ -126,7 +124,7 @@ return FAILURE; } - query = sqlite_mprintf(SELECT_QUERY, key); + query = sqlite_mprintf("SELECT value FROM session_data WHERE sess_id='%q' LIMIT 1", key); if (query == NULL) { /* no memory */ return FAILURE; @@ -168,42 +166,47 @@ { PS_SQLITE_DATA; char *error; - int result = SUCCESS; time_t t; char *binary; int binlen; + int rv; t = time(NULL); binary = emalloc((256 * vallen + 1262) / 253); binlen = sqlite_encode_binary((const unsigned char*)val, vallen, binary); - if (SQLITE_OK != sqlite_exec_printf(db, INSERT_QUERY, NULL, NULL, &error, key, binary, t)) { + rv = sqlite_exec_printf(db, "REPLACE INTO session_data VALUES('%q', '%q', %d)", NULL, NULL, &error, key, binary, t); + if (rv != SQLITE_OK) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "SQLite: session write query failed: %s", error); sqlite_freemem(error); - result = FAILURE; } - efree(binary); - return result; + SQLITE_RETVAL(rv); } PS_DESTROY_FUNC(sqlite) { + int rv; PS_SQLITE_DATA; - return SQLITE_OK == sqlite_exec_printf(db, DELETE_QUERY, NULL, NULL, NULL, key) ? - SUCCESS : FAILURE; + rv = sqlite_exec_printf(db, "DELETE FROM session_data WHERE sess_id='%q'", NULL, NULL, NULL, key); + + SQLITE_RETVAL(rv);return rv == SQLITE_OK ? SUCCESS : FAILURE; } PS_GC_FUNC(sqlite) { PS_SQLITE_DATA; + int rv; time_t t = time(NULL); - return SQLITE_OK == sqlite_exec_printf(db, GC_QUERY, NULL, NULL, NULL, t, maxlifetime) ? - SUCCESS : FAILURE; + rv = sqlite_exec_printf(db, + "DELETE FROM session_data WHERE (%d - updated) > %d", + NULL, NULL, NULL, t, maxlifetime); + + SQLITE_RETVAL(rv); } #endif /* HAVE_PHP_SESSION */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php