extern pdo_driver_t pdo_sqlite_driver;
extern int _pdo_sqlite_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line TSRMLS_DC);
-#define pdo_sqlite_error(s) _pdo_sqlite_error(s, NULL, __FILE__, __LINE__ TSRMLS_CC)
-#define pdo_sqlite_error_stmt(s) _pdo_sqlite_error(stmt->dbh, stmt, __FILE__, __LINE__ TSRMLS_CC)
+extern int _pdo_sqlite_error_msg(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *sqlstate, const char *msg,
+ const char *file, int line TSRMLS_DC);
+#define pdo_sqlite_error(dbh) _pdo_sqlite_error(dbh, NULL, __FILE__, __LINE__ TSRMLS_CC)
+#define pdo_sqlite_errmsg(dbh, st, msg) _pdo_sqlite_error_msg(dbh, NULL, st, msg, __FILE__, __LINE__ TSRMLS_CC)
+#define pdo_sqlite_error_stmt(stmt) _pdo_sqlite_error(stmt->dbh, stmt, __FILE__, __LINE__ TSRMLS_CC)
+#define pdo_sqlite_errmsg_stmt(stmt, st, msg) _pdo_sqlite_error_msg(stmt->dbh, stmt, st, msg, __FILE__, __LINE__ TSRMLS_CC)
+
extern struct pdo_stmt_methods sqlite_stmt_methods;
#endif
#include "php_pdo_sqlite_int.h"
#include "zend_exceptions.h"
+int _pdo_sqlite_error_msg(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *sqlstate, const char *msg,
+ const char *file, int line TSRMLS_DC)
+{
+ pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data;
+ pdo_error_type *pdo_err = stmt ? &stmt->error_code : &dbh->error_code;
+ pdo_sqlite_error_info *einfo = &H->einfo;
+
+ einfo->errcode = SQLITE_ERROR;
+ einfo->file = file;
+ einfo->line = line;
+ einfo->errmsg = pestrdup(msg, dbh->is_persistent);
+ if (sqlstate) {
+ strcpy(*pdo_err, sqlstate);
+ } else {
+ strcpy(*pdo_err, "HY000");
+ }
+
+ if (!dbh->methods) {
+ zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s] [%d] %s",
+ *pdo_err, einfo->errcode, einfo->errmsg);
+ }
+ return einfo->errcode;
+}
+
int _pdo_sqlite_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line TSRMLS_DC) /* {{{ */
{
pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data;
}
if (!dbh->methods) {
-#if PHP_VERSION_ID > 50200
zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s] [%d] %s",
*pdo_err, einfo->errcode, einfo->errmsg);
-#else
- zend_throw_exception_ex(php_pdo_get_exception(TSRMLS_C), 0 TSRMLS_CC, "SQLSTATE[%s] [%d] %s",
- *pdo_err, einfo->errcode, einfo->errmsg);
-#endif
}
return einfo->errcode;
}
}
-static char *pdo_sqlite_last_insert_id(pdo_dbh_t *dbh, const char *name, unsigned int *len TSRMLS_DC)
+static char *pdo_sqlite_last_insert_id(pdo_dbh_t *dbh, const char *name, int *len TSRMLS_DC)
{
pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data;
char *id;
char *func_name;
int func_name_len;
long argc = -1;
-#ifdef IS_UNICODE
- zval cbname;
-#else
- char *cbname;
-#endif
pdo_dbh_t *dbh;
pdo_sqlite_db_handle *H;
int ret;
dbh = zend_object_store_get_object(getThis() TSRMLS_CC);
PDO_CONSTRUCT_CHECK;
- if (!zend_is_callable(callback, 0, &cbname)) {
-#ifdef IS_UNICODE
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "function '%R' is not callable", Z_TYPE(cbname), Z_UNIVAL(cbname));
- zval_dtor(&cbname);
-#else
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "function '%s' is not callable", cbname);
- efree(cbname);
-#endif
+ if (!zend_is_callable(callback, 0, NULL)) {
+ pdo_sqlite_errmsg(dbh, NULL, "callback is not callable");
RETURN_FALSE;
}
-#ifdef IS_UNICODE
- zval_dtor(&cbname);
-#else
- efree(cbname);
-#endif
H = (pdo_sqlite_db_handle *)dbh->driver_data;
char *func_name;
int func_name_len;
long argc = -1;
-#ifdef IS_UNICODE
- zval cbname;
-#else
- char *cbname;
-#endif
pdo_dbh_t *dbh;
pdo_sqlite_db_handle *H;
int ret;
dbh = zend_object_store_get_object(getThis() TSRMLS_CC);
PDO_CONSTRUCT_CHECK;
- if (!zend_is_callable(step_callback, 0, &cbname)) {
-#ifdef IS_UNICODE
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "function '%R' is not callable", Z_TYPE(cbname), Z_UNIVAL(cbname));
- zval_dtor(&cbname);
-#else
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "function '%s' is not callable", cbname);
- efree(cbname);
-#endif
+ if (!zend_is_callable(step_callback, 0, NULL)) {
+ pdo_sqlite_errmsg(dbh, NULL, "step callback is not callable");
RETURN_FALSE;
}
-#ifdef IS_UNICODE
- zval_dtor(&cbname);
-#else
- efree(cbname);
-#endif
- if (!zend_is_callable(fini_callback, 0, &cbname)) {
-#ifdef IS_UNICODE
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "function '%R' is not callable", Z_TYPE(cbname), Z_UNIVAL(cbname));
- zval_dtor(&cbname);
-#else
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "function '%s' is not callable", cbname);
- efree(cbname);
-#endif
+ if (!zend_is_callable(fini_callback, 0, NULL)) {
+ pdo_sqlite_errmsg(dbh, NULL, "fini callback is not callable");
RETURN_FALSE;
}
-#ifdef IS_UNICODE
- zval_dtor(&cbname);
-#else
- efree(cbname);
-#endif
H = (pdo_sqlite_db_handle *)dbh->driver_data;
return NULL;
}
+#if PHP_MAJOR_VERSION < 6
+ if (PG(safe_mode) && (!php_checkuid(fullpath, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
+ efree(fullpath);
+ return NULL;
+ }
+#endif
+
if (php_check_open_basedir(fullpath TSRMLS_CC)) {
efree(fullpath);
return NULL;
filename = make_filename_safe(dbh->data_source TSRMLS_CC);
if (!filename) {
-#if PHP_VERSION_ID > 50200
zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC,
- "open_basedir prohibits opening %s", dbh->data_source);
-#else
- zend_throw_exception_ex(php_pdo_get_exception(TSRMLS_C), 0 TSRMLS_CC,
- "open_basedir prohibits opening %s", dbh->data_source);
-#endif
+ "safe_mode/open_basedir prohibits opening %s",
+ dbh->data_source);
goto cleanup;
}
goto cleanup;
}
- if ((PG(open_basedir) && *PG(open_basedir))) {
+ if (
+#if PHP_MAJOR_VERSION < 6
+ PG(safe_mode) ||
+#endif
+ (PG(open_basedir) && *PG(open_basedir))) {
sqlite3_set_authorizer(H->db, authorizer, NULL);
}
}
switch (PDO_PARAM_TYPE(param->param_type)) {
- case PDO_PARAM_LOB:
case PDO_PARAM_STMT:
return 0;
}
pdo_sqlite_error_stmt(stmt);
return 0;
-
+
+ case PDO_PARAM_LOB:
+ if (Z_TYPE_P(param->parameter) == IS_RESOURCE) {
+ php_stream *stm;
+ php_stream_from_zval_no_verify(stm, ¶m->parameter);
+ if (stm) {
+ SEPARATE_ZVAL_IF_NOT_REF(¶m->parameter);
+ Z_TYPE_P(param->parameter) = IS_STRING;
+ Z_STRLEN_P(param->parameter) = php_stream_copy_to_mem(stm,
+ &Z_STRVAL_P(param->parameter), PHP_STREAM_COPY_ALL, 0);
+ } else {
+ pdo_raise_impl_error(stmt->dbh, stmt, "HY105", "Expected a stream resource" TSRMLS_CC);
+ return 0;
+ }
+ }
+ /* fall through */
+
case PDO_PARAM_STR:
default:
if (Z_TYPE_P(param->parameter) == IS_NULL) {
} else {
convert_to_string(param->parameter);
if(SQLITE_OK == sqlite3_bind_text(S->stmt, param->paramno + 1,
- Z_STRVAL_P(param->parameter),
- Z_STRLEN_P(param->parameter),
- SQLITE_STATIC)) {
+ Z_STRVAL_P(param->parameter),
+ Z_STRLEN_P(param->parameter),
+ SQLITE_STATIC)) {
return 1;
}
}