diff options
author | Wez Furlong <wez@php.net> | 2003-04-17 16:57:46 +0000 |
---|---|---|
committer | Wez Furlong <wez@php.net> | 2003-04-17 16:57:46 +0000 |
commit | 4eba9b8b467b776ff6c9f11d680ed0907d046066 (patch) | |
tree | 8e128d207d51ca00b4e57c761a4fb3ec0742ab99 /ext/sqlite | |
parent | 3fbb4dbdc031ffefce92b57fec81b0fc94b6aaa2 (diff) | |
download | php-git-4eba9b8b467b776ff6c9f11d680ed0907d046066.tar.gz |
Implement sqlite_busy_timeout() which sets the retry timeout (in milliseconds)
when multiple processes attempt to lock and update the database.
Diffstat (limited to 'ext/sqlite')
-rw-r--r-- | ext/sqlite/php_sqlite.h | 2 | ||||
-rw-r--r-- | ext/sqlite/sqlite.c | 23 |
2 files changed, 25 insertions, 0 deletions
diff --git a/ext/sqlite/php_sqlite.h b/ext/sqlite/php_sqlite.h index 206e20c7a2..40f72902a8 100644 --- a/ext/sqlite/php_sqlite.h +++ b/ext/sqlite/php_sqlite.h @@ -58,6 +58,8 @@ PHP_FUNCTION(sqlite_last_insert_rowid); PHP_FUNCTION(sqlite_escape_string); +PHP_FUNCTION(sqlite_busy_timeout); + #ifdef ZTS #define SQLITE_G(v) TSRMG(sqlite_globals_id, zend_sqlite_globals *, v) #else diff --git a/ext/sqlite/sqlite.c b/ext/sqlite/sqlite.c index 0a799a71a8..831cff2194 100644 --- a/ext/sqlite/sqlite.c +++ b/ext/sqlite/sqlite.c @@ -56,6 +56,7 @@ function_entry sqlite_functions[] = { PHP_FE(sqlite_field_name, NULL) PHP_FE(sqlite_seek, NULL) PHP_FE(sqlite_escape_string, NULL) + PHP_FE(sqlite_busy_timeout, NULL) {NULL, NULL, NULL} }; @@ -243,12 +244,34 @@ PHP_FUNCTION(sqlite_open) /* register the PHP functions */ sqlite_create_function(db, "php", -1, php_sqlite_function_callback, 0); + + /* set default busy handler; keep retrying up until 1/2 second has passed, + * then fail with a busy status code */ + sqlite_busy_timeout(db, 500); ZEND_REGISTER_RESOURCE(return_value, db, le_sqlite_db); } /* }}} */ +/* {{{ proto void sqlite_busy_timeout(resource db, int ms) + Set busy timeout duration. If ms <= 0, all busy handlers are disabled */ +PHP_FUNCTION(sqlite_busy_timeout) +{ + zval *zdb; + sqlite *db; + long ms; + + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zdb, &ms)) { + return; + } + + ZEND_FETCH_RESOURCE(db, sqlite *, &zdb, -1, "sqlite database", le_sqlite_db); + + sqlite_busy_timeout(db, ms); +} +/* }}} */ + /* {{{ proto void sqlite_close(resource db) Closes an open sqlite database */ PHP_FUNCTION(sqlite_close) |