Browse Source

merge php5 pdo_sqlite into head; this source compiles on both php5 and php6.

migration/RELEASE_1_0_0
Wez Furlong 20 years ago
parent
commit
c2a7928496
  1. 2
      ext/pdo_sqlite/pdo_sqlite.c
  2. 9
      ext/pdo_sqlite/php_pdo_sqlite_int.h
  3. 107
      ext/pdo_sqlite/sqlite_driver.c
  4. 25
      ext/pdo_sqlite/sqlite_statement.c

2
ext/pdo_sqlite/pdo_sqlite.c

@ -31,7 +31,7 @@
#include "php_pdo_sqlite_int.h"
#include "zend_exceptions.h"
#define PHP_PDO_SQLITE_MODULE_VERSION "0.9"
#define PHP_PDO_SQLITE_MODULE_VERSION "1.0.1"
/* {{{ pdo_sqlite_functions[] */
zend_function_entry pdo_sqlite_functions[] = {

9
ext/pdo_sqlite/php_pdo_sqlite_int.h

@ -62,8 +62,13 @@ typedef struct {
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

107
ext/pdo_sqlite/sqlite_driver.c

@ -31,6 +31,30 @@
#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;
@ -78,13 +102,8 @@ int _pdo_sqlite_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int li
}
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;
@ -203,7 +222,7 @@ static long sqlite_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSR
}
}
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;
@ -471,11 +490,6 @@ static PHP_METHOD(SQLite, sqliteCreateFunction)
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;
@ -488,21 +502,10 @@ static PHP_METHOD(SQLite, sqliteCreateFunction)
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;
@ -556,11 +559,6 @@ static PHP_METHOD(SQLite, sqliteCreateAggregate)
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;
@ -573,36 +571,14 @@ static PHP_METHOD(SQLite, sqliteCreateAggregate)
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;
@ -686,6 +662,13 @@ static char *make_filename_safe(const char *filename TSRMLS_DC)
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;
@ -742,13 +725,9 @@ static int pdo_sqlite_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS
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;
}
@ -760,7 +739,11 @@ static int pdo_sqlite_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS
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);
}

25
ext/pdo_sqlite/sqlite_statement.c

@ -94,7 +94,6 @@ static int pdo_sqlite_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_d
}
switch (PDO_PARAM_TYPE(param->param_type)) {
case PDO_PARAM_LOB:
case PDO_PARAM_STMT:
return 0;
@ -104,7 +103,23 @@ static int pdo_sqlite_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_d
}
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, &param->parameter);
if (stm) {
SEPARATE_ZVAL_IF_NOT_REF(&param->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) {
@ -114,9 +129,9 @@ static int pdo_sqlite_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_d
} 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;
}
}

Loading…
Cancel
Save