37 einfo->
errcode = sqlite3_errcode(
H->db);
41 if (einfo->
errcode != SQLITE_OK) {
52 strncpy(*pdo_err,
"42S02",
sizeof(*pdo_err));
55 case SQLITE_INTERRUPT:
56 strncpy(*pdo_err,
"01002",
sizeof(*pdo_err));
60 strncpy(*pdo_err,
"HYC00",
sizeof(*pdo_err));
64 strncpy(*pdo_err,
"22001",
sizeof(*pdo_err));
67 case SQLITE_CONSTRAINT:
68 strncpy(*pdo_err,
"23000",
sizeof(*pdo_err));
73 strncpy(*pdo_err,
"HY000",
sizeof(*pdo_err));
102 H->funcs =
func->next;
106 sqlite3_create_function(
H->db,
116 zend_fcc_dtor(&
func->func);
119 zend_fcc_dtor(&
func->step);
122 zend_fcc_dtor(&
func->fini);
127 while (
H->collations) {
129 collation =
H->collations;
130 H->collations = collation->
next;
134 sqlite3_create_collation(
H->db,
143 zend_fcc_dtor(&collation->
callback);
149static void sqlite_handle_closer(
pdo_dbh_t *dbh)
156 pdo_sqlite_cleanup_callbacks(
H);
158#ifdef HAVE_SQLITE3_CLOSE_V2
159 sqlite3_close_v2(
H->db);
161 sqlite3_close(
H->db);
170 dbh->driver_data =
NULL;
183 stmt->driver_data =
S;
188 H->einfo.errcode = SQLITE_ERROR;
194 if (i == SQLITE_OK) {
211 return sqlite3_changes(
H->db);
231 sqlite3_snprintf(2*
ZSTR_LEN(unquoted) + 3, quoted,
"'%q'",
ZSTR_VAL(unquoted));
237static bool sqlite_handle_begin(
pdo_dbh_t *dbh)
241 if (sqlite3_exec(
H->db,
"BEGIN",
NULL,
NULL,
NULL) != SQLITE_OK) {
248static bool sqlite_handle_commit(
pdo_dbh_t *dbh)
252 if (sqlite3_exec(
H->db,
"COMMIT",
NULL,
NULL,
NULL) != SQLITE_OK) {
259static bool sqlite_handle_rollback(
pdo_dbh_t *dbh)
263 if (sqlite3_exec(
H->db,
"ROLLBACK",
NULL,
NULL,
NULL) != SQLITE_OK) {
285static bool pdo_sqlite_in_transaction(
pdo_dbh_t *dbh)
291 return H->db && sqlite3_get_autocommit(
H->db) == 0;
304 sqlite3_busy_timeout(
H->db, lval * 1000);
310 sqlite3_extended_result_codes(
H->db, lval);
334 fake_argc = argc + is_agg;
354 for (i = 0; i < argc; i++) {
356 switch (sqlite3_value_type(argv[i])) {
358 ZVAL_LONG(&zargs[i + is_agg], sqlite3_value_int(argv[i]));
362 ZVAL_DOUBLE(&zargs[i + is_agg], sqlite3_value_double(argv[i]));
372 ZVAL_STRINGL(&zargs[i + is_agg], (
char*)sqlite3_value_text(argv[i]), sqlite3_value_bytes(argv[i]));
377 zend_call_known_fcc(fcc, &
retval, fake_argc, zargs,
NULL);
381 for (i = is_agg; i < fake_argc; i++) {
390 if (!is_agg || !argv) {
408 if (!try_convert_to_string(&
retval)) {
416 sqlite3_result_error(
context,
"failed to invoke callback", 0);
442static void php_sqlite3_func_step_callback(sqlite3_context *
context,
int argc, sqlite3_value **argv)
449static void php_sqlite3_func_final_callback(sqlite3_context *
context)
456static int php_sqlite3_collation_callback(
void *
context,
int string1_len,
const void *string1,
int string2_len,
const void *string2)
487static void php_sqlite3_func_callback(sqlite3_context *
context,
int argc, sqlite3_value **argv)
523 if (
ret == SQLITE_OK) {
526 zend_fcc_dup(&
func->func, &fcc);
530 func->next =
H->funcs;
581 php_sqlite3_func_step_callback, php_sqlite3_func_final_callback);
582 if (
ret == SQLITE_OK) {
585 zend_fcc_dup(&
func->step, &step_fcc);
586 zend_fcc_dup(&
func->fini, &fini_fcc);
590 func->next =
H->funcs;
634 char *collation_name;
635 size_t collation_name_len;
652 ret = sqlite3_create_collation(
H->db, collation_name, SQLITE_UTF8, collation,
callback);
653 if (
ret == SQLITE_OK) {
656 zend_fcc_dup(&collation->
callback, &fcc);
658 collation->
next =
H->collations;
659 H->collations = collation;
686 return class_PDO_SQLite_Ext_methods;
693static void pdo_sqlite_request_shutdown(
pdo_dbh_t *dbh)
699 pdo_sqlite_cleanup_callbacks(
H);
710 zend_get_gc_buffer_add_fcc(gc_buffer, &
func->func);
713 zend_get_gc_buffer_add_fcc(gc_buffer, &
func->step);
716 zend_get_gc_buffer_add_fcc(gc_buffer, &
func->fini);
724 zend_get_gc_buffer_add_fcc(gc_buffer, &collation->
callback);
726 collation = collation->
next;
731 sqlite_handle_closer,
732 sqlite_handle_preparer,
734 sqlite_handle_quoter,
736 sqlite_handle_commit,
737 sqlite_handle_rollback,
739 pdo_sqlite_last_insert_id,
740 pdo_sqlite_fetch_error_func,
741 pdo_sqlite_get_attribute,
744 pdo_sqlite_request_shutdown,
745 pdo_sqlite_in_transaction,
750static char *make_filename_safe(
const char *filename)
755 if (*filename &&
strncasecmp(filename,
"file:", 5) == 0) {
756 if (
PG(open_basedir) && *
PG(open_basedir)) {
761 if (*filename &&
strcmp(filename,
":memory:")) {
777static int authorizer(
void *autharg,
int access_type,
const char *
arg3,
const char *arg4,
778 const char *arg5,
const char *arg6)
781 switch (access_type) {
782 case SQLITE_ATTACH: {
783 filename = make_filename_safe(
arg3);
797static int pdo_sqlite_handle_factory(
pdo_dbh_t *dbh,
zval *driver_options)
806 H->einfo.errcode = 0;
807 H->einfo.errmsg =
NULL;
817 "open_basedir prohibits opening %s",
824 if (!(
PG(open_basedir) && *
PG(open_basedir))) {
825 flags |= SQLITE_OPEN_URI;
827 i = sqlite3_open_v2(filename, &
H->db,
flags,
NULL);
831 if (i != SQLITE_OK) {
836 if (
PG(open_basedir) && *
PG(open_basedir)) {
837 sqlite3_set_authorizer(
H->db, authorizer,
NULL);
840 if (driver_options) {
843 sqlite3_busy_timeout(
H->db, timeout * 1000);
851 dbh->
methods = &sqlite_methods;
859 pdo_sqlite_handle_factory
file(string $filename, int $flags=0, $context=null)
PHPAPI int php_check_open_basedir(const char *path)
PHPAPI char * expand_filepath(const char *filepath, char *real_path)
PDO_API zend_class_entry * php_pdo_get_exception(void)
PDO_API bool pdo_get_long_param(zend_long *lval, zval *value)
void pdo_throw_exception(unsigned int driver_errcode, char *driver_errmsg, pdo_error_type *pdo_error)
struct php_pcntl_pending_signal * tail
#define PDO_CONSTRUCT_CHECK_WITH_CLEANUP(cleanup)
struct _pdo_dbh_t pdo_dbh_t
#define PDO_DRIVER_HEADER(name)
struct _pdo_stmt_t pdo_stmt_t
@ PDO_DBH_DRIVER_METHOD_KIND_DBH
@ PDO_PLACEHOLDER_POSITIONAL
@ PDO_ATTR_SERVER_VERSION
@ PDO_ATTR_CLIENT_VERSION
int pdo_sqlite_scanner(pdo_scanner_t *s)
@ PDO_SQLITE_ATTR_OPEN_FLAGS
@ PDO_SQLITE_ATTR_EXTENDED_RESULT_CODES
#define pdo_sqlite_error(s)
int pdo_sqlite_create_collation_callback(void *, int, const void *, int, const void *)
const struct pdo_stmt_methods sqlite_stmt_methods
const pdo_driver_t pdo_sqlite_driver
#define SQLITE_OPEN_CREATE
#define SQLITE_OPEN_READWRITE
int _pdo_sqlite_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line)
void pdo_sqlite_create_function_internal(INTERNAL_FUNCTION_PARAMETERS)
void pdo_sqlite_create_collation_internal(INTERNAL_FUNCTION_PARAMETERS, pdo_sqlite_create_collation_callback callback)
void pdo_sqlite_create_aggregate_internal(INTERNAL_FUNCTION_PARAMETERS)
unsigned max_escaped_char_length
pdo_error_type error_code
unsigned alloc_own_columns
const struct pdo_dbh_methods * methods
pdo_error_type error_code
zend_fcall_info_cache callback
struct pdo_sqlite_collation * next
#define INTERNAL_FUNCTION_PARAMETERS
#define INTERNAL_FUNCTION_PARAM_PASSTHRU
ZEND_API zend_result add_next_index_long(zval *arg, zend_long n)
ZEND_API void zend_release_fcall_info_cache(zend_fcall_info_cache *fcc)
ZEND_API zend_result add_next_index_string(zval *arg, const char *str)
ZEND_API const zend_fcall_info empty_fcall_info
ZEND_API const zend_fcall_info_cache empty_fcall_info_cache
struct _zend_fcall_info_cache zend_fcall_info_cache
#define ZEND_PARSE_PARAMETERS_END()
struct _zend_function_entry zend_function_entry
#define ZVAL_STRING(z, s)
#define Z_PARAM_STRING(dest, dest_len)
#define ZEND_PARSE_PARAMETERS_END_EX(failure)
#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args)
#define Z_PARAM_LONG(dest)
struct _zend_fcall_info zend_fcall_info
#define ZEND_FCC_INITIALIZED(fcc)
#define Z_PARAM_FUNC_NO_TRAMPOLINE_FREE(dest_fci, dest_fcc)
#define ZVAL_STRINGL(z, s, l)
#define pestrdup(s, persistent)
#define ecalloc(nmemb, size)
#define pefree(ptr, persistent)
#define safe_emalloc(nmemb, size, offset)
#define pecalloc(nmemb, size, persistent)
strcmp(string $string1, string $string2)
#define strncasecmp(s1, s2, n)
ZEND_API ZEND_COLD zend_object * zend_throw_exception_ex(zend_class_entry *exception_ce, zend_long code, const char *format,...)
struct _zend_string zend_string
ZEND_API zend_string *ZEND_FASTCALL zend_i64_to_str(int64_t num)
ZEND_API void ZEND_FASTCALL convert_to_long(zval *op)
#define ZVAL_NEW_REF(z, r)
#define ZVAL_DOUBLE(z, d)
#define ZVAL_COPY_VALUE(z, v)
ZEND_API void zval_ptr_dtor(zval *zval_ptr)