summaryrefslogtreecommitdiff
path: root/ext/sqlite3/sqlite3.c
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2010-10-21 08:52:46 +0200
committerOndřej Surý <ondrej@sury.org>2010-10-21 08:52:46 +0200
commit01fcdff3849c3691d9aaeaab735846ab6d8895ca (patch)
tree6460876d356113fa7053df36f2aa00baa7db24a9 /ext/sqlite3/sqlite3.c
parent855a09f4eded707941180c9d90acd17c25e29447 (diff)
downloadphp-upstream/5.3.3.tar.gz
Imported Upstream version 5.3.3upstream/5.3.3
Diffstat (limited to 'ext/sqlite3/sqlite3.c')
-rw-r--r--ext/sqlite3/sqlite3.c48
1 files changed, 45 insertions, 3 deletions
diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c
index 372ecda44..1db73e9a0 100644
--- a/ext/sqlite3/sqlite3.c
+++ b/ext/sqlite3/sqlite3.c
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: sqlite3.c 293036 2010-01-03 09:23:27Z sebastian $ */
+/* $Id: sqlite3.c 300631 2010-06-21 11:06:31Z iliaa $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -120,11 +120,13 @@ PHP_METHOD(sqlite3, open)
return;
}
+#if PHP_API_VERSION < 20100412
if (PG(safe_mode) && (!php_checkuid(fullpath, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "safe_mode prohibits opening %s", fullpath);
efree(fullpath);
return;
}
+#endif
if (php_check_open_basedir(fullpath TSRMLS_CC)) {
zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "open_basedir prohibits opening %s", fullpath);
@@ -158,7 +160,11 @@ PHP_METHOD(sqlite3, open)
}
#endif
+#if PHP_API_VERSION < 20100412
if (PG(safe_mode) || (PG(open_basedir) && *PG(open_basedir))) {
+#else
+ if (PG(open_basedir) && *PG(open_basedir)) {
+#endif
sqlite3_set_authorizer(db_obj->db, php_sqlite3_authorizer, NULL);
}
@@ -292,6 +298,33 @@ PHP_METHOD(sqlite3, lastErrorMsg)
}
/* }}} */
+/* {{{ proto bool SQLite3::busyTimeout(int msecs)
+ Sets a busy handler that will sleep until database is not locked or timeout is reached. Passing a value less than or equal to zero turns off all busy handlers. */
+PHP_METHOD(sqlite3, busyTimeout)
+{
+ php_sqlite3_db_object *db_obj;
+ zval *object = getThis();
+ long ms;
+ int return_code;
+ db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC);
+
+ SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)
+
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ms)) {
+ return;
+ }
+
+ return_code = sqlite3_busy_timeout(db_obj->db, ms);
+ if (return_code != SQLITE_OK) {
+ php_sqlite3_error(db_obj, "Unable to set busy timeout: %d, %s", return_code, sqlite3_errmsg(db_obj->db));
+ RETURN_FALSE;
+ }
+
+ RETURN_TRUE;
+}
+/* }}} */
+
+
#ifndef SQLITE_OMIT_LOAD_EXTENSION
/* {{{ proto bool SQLite3::loadExtension(String Shared Library)
Attempts to load an SQLite extension library. */
@@ -1646,6 +1679,10 @@ ZEND_BEGIN_ARG_INFO(arginfo_sqlite3_open, 0)
ZEND_ARG_INFO(0, encryption_key)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO(arginfo_sqlite3_busytimeout, 0)
+ ZEND_ARG_INFO(0, ms)
+ZEND_END_ARG_INFO()
+
#ifndef SQLITE_OMIT_LOAD_EXTENSION
ZEND_BEGIN_ARG_INFO(arginfo_sqlite3_loadextension, 0)
ZEND_ARG_INFO(0, shared_library)
@@ -1730,6 +1767,7 @@ static zend_function_entry php_sqlite3_class_methods[] = {
PHP_ME(sqlite3, lastInsertRowID, arginfo_sqlite3_void, ZEND_ACC_PUBLIC)
PHP_ME(sqlite3, lastErrorCode, arginfo_sqlite3_void, ZEND_ACC_PUBLIC)
PHP_ME(sqlite3, lastErrorMsg, arginfo_sqlite3_void, ZEND_ACC_PUBLIC)
+ PHP_ME(sqlite3, busyTimeout, arginfo_sqlite3_busytimeout, ZEND_ACC_PUBLIC)
#ifndef SQLITE_OMIT_LOAD_EXTENSION
PHP_ME(sqlite3, loadExtension, arginfo_sqlite3_loadextension, ZEND_ACC_PUBLIC)
#endif
@@ -1779,14 +1817,18 @@ static zend_function_entry php_sqlite3_result_class_methods[] = {
*/
static int php_sqlite3_authorizer(void *autharg, int access_type, const char *arg3, const char *arg4, const char *arg5, const char *arg6)
{
- TSRMLS_FETCH();
switch (access_type) {
case SQLITE_ATTACH:
{
- if (strncmp(arg3, ":memory:", sizeof(":memory:")-1)) {
+ if (strncmp(arg3, ":memory:", sizeof(":memory:")-1) && *arg3) {
+ TSRMLS_FETCH();
+
+#if PHP_API_VERSION < 20100412
if (PG(safe_mode) && (!php_checkuid(arg3, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
return SQLITE_DENY;
}
+#endif
+
if (php_check_open_basedir(arg3 TSRMLS_CC)) {
return SQLITE_DENY;
}