|
|
| version 1.1.1.1, 2012/02/21 23:48:02 | version 1.1.1.3, 2013/07/22 01:32:02 |
|---|---|
| Line 2 | Line 2 |
| +----------------------------------------------------------------------+ | +----------------------------------------------------------------------+ |
| | PHP Version 5 | | | PHP Version 5 | |
| +----------------------------------------------------------------------+ | +----------------------------------------------------------------------+ |
| | Copyright (c) 1997-2012 The PHP Group | | | Copyright (c) 1997-2013 The PHP Group | |
| +----------------------------------------------------------------------+ | +----------------------------------------------------------------------+ |
| | This source file is subject to version 3.01 of the PHP license, | | | This source file is subject to version 3.01 of the PHP license, | |
| | that is bundled with this package in the file LICENSE, and is | | | that is bundled with this package in the file LICENSE, and is | |
| Line 103 PHP_METHOD(sqlite3, open) | Line 103 PHP_METHOD(sqlite3, open) |
| db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC); | db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC); |
| zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC); | zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC); |
| if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls", &filename, &filename_len, &flags, &encryption_key, &encryption_key_len)) { | if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|ls", &filename, &filename_len, &flags, &encryption_key, &encryption_key_len)) { |
| zend_restore_error_handling(&error_handling TSRMLS_CC); | zend_restore_error_handling(&error_handling TSRMLS_CC); |
| return; | return; |
| } | } |
| Line 117 PHP_METHOD(sqlite3, open) | Line 117 PHP_METHOD(sqlite3, open) |
| if (strlen(filename) != filename_len) { | if (strlen(filename) != filename_len) { |
| return; | return; |
| } | } |
| if (strncmp(filename, ":memory:", 8) != 0) { | if (memcmp(filename, ":memory:", sizeof(":memory:")) != 0) { |
| if (!(fullpath = expand_filepath(filename, NULL TSRMLS_CC))) { | if (!(fullpath = expand_filepath(filename, NULL TSRMLS_CC))) { |
| zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Unable to expand filepath", 0 TSRMLS_CC); | zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Unable to expand filepath", 0 TSRMLS_CC); |
| return; | return; |
| Line 730 static int sqlite3_do_callback(struct php_sqlite3_fci | Line 730 static int sqlite3_do_callback(struct php_sqlite3_fci |
| switch (sqlite3_value_type(argv[i])) { | switch (sqlite3_value_type(argv[i])) { |
| case SQLITE_INTEGER: | case SQLITE_INTEGER: |
| #if LONG_MAX > 2147483647 | |
| ZVAL_LONG(*zargs[i + is_agg], sqlite3_value_int64(argv[i])); | |
| #else | |
| ZVAL_LONG(*zargs[i + is_agg], sqlite3_value_int(argv[i])); | ZVAL_LONG(*zargs[i + is_agg], sqlite3_value_int(argv[i])); |
| #endif | |
| break; | break; |
| case SQLITE_FLOAT: | case SQLITE_FLOAT: |
| Line 774 static int sqlite3_do_callback(struct php_sqlite3_fci | Line 778 static int sqlite3_do_callback(struct php_sqlite3_fci |
| if (retval) { | if (retval) { |
| switch (Z_TYPE_P(retval)) { | switch (Z_TYPE_P(retval)) { |
| case IS_LONG: | case IS_LONG: |
| #if LONG_MAX > 2147483647 | |
| sqlite3_result_int64(context, Z_LVAL_P(retval)); | |
| #else | |
| sqlite3_result_int(context, Z_LVAL_P(retval)); | sqlite3_result_int(context, Z_LVAL_P(retval)); |
| #endif | |
| break; | break; |
| case IS_NULL: | case IS_NULL: |
| Line 851 static void php_sqlite3_callback_final(sqlite3_context | Line 859 static void php_sqlite3_callback_final(sqlite3_context |
| } | } |
| /* }}} */ | /* }}} */ |
| static int php_sqlite3_callback_compare(void *coll, int a_len, const void *a, int b_len, const void* b) /* {{{ */ | |
| { | |
| php_sqlite3_collation *collation = (php_sqlite3_collation*)coll; | |
| zval ***zargs = NULL; | |
| zval *retval = NULL; | |
| int ret; | |
| TSRMLS_FETCH(); | |
| collation->fci.fci.size = (sizeof(collation->fci.fci)); | |
| collation->fci.fci.function_table = EG(function_table); | |
| collation->fci.fci.function_name = collation->cmp_func; | |
| collation->fci.fci.symbol_table = NULL; | |
| collation->fci.fci.object_ptr = NULL; | |
| collation->fci.fci.retval_ptr_ptr = &retval; | |
| collation->fci.fci.param_count = 2; | |
| zargs = (zval***)safe_emalloc(2, sizeof(zval**), 0); | |
| zargs[0] = emalloc(sizeof(zval*)); | |
| zargs[1] = emalloc(sizeof(zval*)); | |
| MAKE_STD_ZVAL(*zargs[0]); | |
| ZVAL_STRINGL(*zargs[0], a, a_len, 1); | |
| MAKE_STD_ZVAL(*zargs[1]); | |
| ZVAL_STRINGL(*zargs[1], b, b_len, 1); | |
| collation->fci.fci.params = zargs; | |
| if ((ret = zend_call_function(&collation->fci.fci, &collation->fci.fcc TSRMLS_CC)) == FAILURE) { | |
| php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred while invoking the compare callback"); | |
| } | |
| zval_ptr_dtor(zargs[0]); | |
| zval_ptr_dtor(zargs[1]); | |
| efree(zargs[0]); | |
| efree(zargs[1]); | |
| efree(zargs); | |
| //retval ought to contain a ZVAL_LONG by now | |
| // (the result of a comparison, i.e. most likely -1, 0, or 1) | |
| //I suppose we could accept any scalar return type, though. | |
| if (Z_TYPE_P(retval) != IS_LONG){ | |
| php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred while invoking the compare callback (invalid return type). Collation behaviour is undefined."); | |
| }else{ | |
| ret = Z_LVAL_P(retval); | |
| } | |
| zval_ptr_dtor(&retval); | |
| return ret; | |
| } | |
| /* }}} */ | |
| /* {{{ proto bool SQLite3::createFunction(string name, mixed callback [, int argcount]) | /* {{{ proto bool SQLite3::createFunction(string name, mixed callback [, int argcount]) |
| Allows registration of a PHP function as a SQLite UDF that can be called within SQL statements. */ | Allows registration of a PHP function as a SQLite UDF that can be called within SQL statements. */ |
| PHP_METHOD(sqlite3, createFunction) | PHP_METHOD(sqlite3, createFunction) |
| Line 961 PHP_METHOD(sqlite3, createAggregate) | Line 1023 PHP_METHOD(sqlite3, createAggregate) |
| } | } |
| /* }}} */ | /* }}} */ |
| /* {{{ proto bool SQLite3::createCollation(string name, mixed callback) | |
| Registers a PHP function as a comparator that can be used with the SQL COLLATE operator. Callback must accept two strings and return an integer (as strcmp()). */ | |
| PHP_METHOD(sqlite3, createCollation) | |
| { | |
| php_sqlite3_db_object *db_obj; | |
| zval *object = getThis(); | |
| php_sqlite3_collation *collation; | |
| char *collation_name, *callback_name; | |
| int collation_name_len; | |
| zval *callback_func; | |
| db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC); | |
| SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) | |
| if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &collation_name, &collation_name_len, &callback_func) == FAILURE) { | |
| RETURN_FALSE; | |
| } | |
| if (!collation_name_len) { | |
| RETURN_FALSE; | |
| } | |
| if (!zend_is_callable(callback_func, 0, &callback_name TSRMLS_CC)) { | |
| php_sqlite3_error(db_obj, "Not a valid callback function %s", callback_name); | |
| efree(callback_name); | |
| RETURN_FALSE; | |
| } | |
| efree(callback_name); | |
| collation = (php_sqlite3_collation *)ecalloc(1, sizeof(*collation)); | |
| if (sqlite3_create_collation(db_obj->db, collation_name, SQLITE_UTF8, collation, php_sqlite3_callback_compare) == SQLITE_OK) { | |
| collation->collation_name = estrdup(collation_name); | |
| MAKE_STD_ZVAL(collation->cmp_func); | |
| MAKE_COPY_ZVAL(&callback_func, collation->cmp_func); | |
| collation->next = db_obj->collations; | |
| db_obj->collations = collation; | |
| RETURN_TRUE; | |
| } | |
| efree(collation); | |
| RETURN_FALSE; | |
| } | |
| /* }}} */ | |
| typedef struct { | typedef struct { |
| sqlite3_blob *blob; | sqlite3_blob *blob; |
| size_t position; | size_t position; |
| Line 996 static int php_sqlite3_stream_close(php_stream *stream | Line 1105 static int php_sqlite3_stream_close(php_stream *stream |
| php_stream_sqlite3_data *sqlite3_stream = (php_stream_sqlite3_data *) stream->abstract; | php_stream_sqlite3_data *sqlite3_stream = (php_stream_sqlite3_data *) stream->abstract; |
| if (sqlite3_blob_close(sqlite3_stream->blob) != SQLITE_OK) { | if (sqlite3_blob_close(sqlite3_stream->blob) != SQLITE_OK) { |
| /* Error occured, but it still closed */ | /* Error occurred, but it still closed */ |
| } | } |
| efree(sqlite3_stream); | efree(sqlite3_stream); |
| Line 1300 static int register_bound_parameter_to_sqlite(struct p | Line 1409 static int register_bound_parameter_to_sqlite(struct p |
| /* }}} */ | /* }}} */ |
| /* {{{ proto bool SQLite3Stmt::bindParam(int parameter_number, mixed parameter [, int type]) | /* {{{ proto bool SQLite3Stmt::bindParam(int parameter_number, mixed parameter [, int type]) |
| Bind Paramater to a stmt variable. */ | Bind Parameter to a stmt variable. */ |
| PHP_METHOD(sqlite3stmt, bindParam) | PHP_METHOD(sqlite3stmt, bindParam) |
| { | { |
| php_sqlite3_stmt *stmt_obj; | php_sqlite3_stmt *stmt_obj; |
| Line 1392 PHP_METHOD(sqlite3stmt, execute) | Line 1501 PHP_METHOD(sqlite3stmt, execute) |
| switch (param->type) { | switch (param->type) { |
| case SQLITE_INTEGER: | case SQLITE_INTEGER: |
| convert_to_long(param->parameter); | convert_to_long(param->parameter); |
| #if LONG_MAX > 2147483647 | |
| sqlite3_bind_int64(stmt_obj->stmt, param->param_number, Z_LVAL_P(param->parameter)); | |
| #else | |
| sqlite3_bind_int(stmt_obj->stmt, param->param_number, Z_LVAL_P(param->parameter)); | sqlite3_bind_int(stmt_obj->stmt, param->param_number, Z_LVAL_P(param->parameter)); |
| #endif | |
| break; | break; |
| case SQLITE_FLOAT: | case SQLITE_FLOAT: |
| Line 1749 ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3_createaggregate | Line 1862 ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3_createaggregate |
| ZEND_ARG_INFO(0, argument_count) | ZEND_ARG_INFO(0, argument_count) |
| ZEND_END_ARG_INFO() | ZEND_END_ARG_INFO() |
| ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3_createcollation, 0, 0, 2) | |
| ZEND_ARG_INFO(0, name) | |
| ZEND_ARG_INFO(0, callback) | |
| ZEND_END_ARG_INFO() | |
| ZEND_BEGIN_ARG_INFO_EX(argingo_sqlite3_openblob, 0, 0, 3) | ZEND_BEGIN_ARG_INFO_EX(argingo_sqlite3_openblob, 0, 0, 3) |
| ZEND_ARG_INFO(0, table) | ZEND_ARG_INFO(0, table) |
| ZEND_ARG_INFO(0, column) | ZEND_ARG_INFO(0, column) |
| Line 1812 static zend_function_entry php_sqlite3_class_methods[] | Line 1930 static zend_function_entry php_sqlite3_class_methods[] |
| PHP_ME(sqlite3, querySingle, arginfo_sqlite3_querysingle, ZEND_ACC_PUBLIC) | PHP_ME(sqlite3, querySingle, arginfo_sqlite3_querysingle, ZEND_ACC_PUBLIC) |
| PHP_ME(sqlite3, createFunction, arginfo_sqlite3_createfunction, ZEND_ACC_PUBLIC) | PHP_ME(sqlite3, createFunction, arginfo_sqlite3_createfunction, ZEND_ACC_PUBLIC) |
| PHP_ME(sqlite3, createAggregate, arginfo_sqlite3_createaggregate, ZEND_ACC_PUBLIC) | PHP_ME(sqlite3, createAggregate, arginfo_sqlite3_createaggregate, ZEND_ACC_PUBLIC) |
| PHP_ME(sqlite3, createCollation, arginfo_sqlite3_createcollation, ZEND_ACC_PUBLIC) | |
| PHP_ME(sqlite3, openBlob, argingo_sqlite3_openblob, ZEND_ACC_PUBLIC) | PHP_ME(sqlite3, openBlob, argingo_sqlite3_openblob, ZEND_ACC_PUBLIC) |
| PHP_ME(sqlite3, enableExceptions, argingo_sqlite3_enableexceptions, ZEND_ACC_PUBLIC) | PHP_ME(sqlite3, enableExceptions, argingo_sqlite3_enableexceptions, ZEND_ACC_PUBLIC) |
| /* Aliases */ | /* Aliases */ |
| Line 1855 static int php_sqlite3_authorizer(void *autharg, int a | Line 1974 static int php_sqlite3_authorizer(void *autharg, int a |
| switch (access_type) { | switch (access_type) { |
| case SQLITE_ATTACH: | case SQLITE_ATTACH: |
| { | { |
| if (strncmp(arg3, ":memory:", sizeof(":memory:")-1) && *arg3) { | if (memcmp(arg3, ":memory:", sizeof(":memory:")) && *arg3) { |
| TSRMLS_FETCH(); | TSRMLS_FETCH(); |
| #if PHP_API_VERSION < 20100412 | #if PHP_API_VERSION < 20100412 |
| Line 1908 static void php_sqlite3_object_free_storage(void *obje | Line 2027 static void php_sqlite3_object_free_storage(void *obje |
| { | { |
| php_sqlite3_db_object *intern = (php_sqlite3_db_object *)object; | php_sqlite3_db_object *intern = (php_sqlite3_db_object *)object; |
| php_sqlite3_func *func; | php_sqlite3_func *func; |
| php_sqlite3_collation *collation; | |
| if (!intern) { | if (!intern) { |
| return; | return; |
| Line 1934 static void php_sqlite3_object_free_storage(void *obje | Line 2054 static void php_sqlite3_object_free_storage(void *obje |
| efree(func); | efree(func); |
| } | } |
| while (intern->collations){ | |
| collation = intern->collations; | |
| intern->collations = collation->next; | |
| if (intern->initialised && intern->db){ | |
| sqlite3_create_collation(intern->db, collation->collation_name, SQLITE_UTF8, NULL, NULL); | |
| } | |
| efree((char*)collation->collation_name); | |
| if (collation->cmp_func){ | |
| zval_ptr_dtor(&collation->cmp_func); | |
| } | |
| efree(collation); | |
| } | |
| if (intern->initialised && intern->db) { | if (intern->initialised && intern->db) { |
| sqlite3_close(intern->db); | sqlite3_close(intern->db); |
| intern->initialised = 0; | intern->initialised = 0; |
| Line 2000 static void php_sqlite3_result_object_free_storage(voi | Line 2133 static void php_sqlite3_result_object_free_storage(voi |
| static zend_object_value php_sqlite3_object_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */ | static zend_object_value php_sqlite3_object_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */ |
| { | { |
| zval *tmp; | |
| zend_object_value retval; | zend_object_value retval; |
| php_sqlite3_db_object *intern; | php_sqlite3_db_object *intern; |
| Line 2013 static zend_object_value php_sqlite3_object_new(zend_c | Line 2145 static zend_object_value php_sqlite3_object_new(zend_c |
| zend_llist_init(&(intern->free_list), sizeof(php_sqlite3_free_list *), (llist_dtor_func_t)php_sqlite3_free_list_dtor, 0); | zend_llist_init(&(intern->free_list), sizeof(php_sqlite3_free_list *), (llist_dtor_func_t)php_sqlite3_free_list_dtor, 0); |
| zend_object_std_init(&intern->zo, class_type TSRMLS_CC); | zend_object_std_init(&intern->zo, class_type TSRMLS_CC); |
| zend_hash_copy(intern->zo.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref,(void *) &tmp, sizeof(zval *)); | object_properties_init(&intern->zo, class_type); |
| retval.handle = zend_objects_store_put(intern, NULL, (zend_objects_free_object_storage_t) php_sqlite3_object_free_storage, NULL TSRMLS_CC); | retval.handle = zend_objects_store_put(intern, NULL, (zend_objects_free_object_storage_t) php_sqlite3_object_free_storage, NULL TSRMLS_CC); |
| retval.handlers = (zend_object_handlers *) &sqlite3_object_handlers; | retval.handlers = (zend_object_handlers *) &sqlite3_object_handlers; |
| Line 2024 static zend_object_value php_sqlite3_object_new(zend_c | Line 2156 static zend_object_value php_sqlite3_object_new(zend_c |
| static zend_object_value php_sqlite3_stmt_object_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */ | static zend_object_value php_sqlite3_stmt_object_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */ |
| { | { |
| zval *tmp; | |
| zend_object_value retval; | zend_object_value retval; |
| php_sqlite3_stmt *intern; | php_sqlite3_stmt *intern; |
| Line 2035 static zend_object_value php_sqlite3_stmt_object_new(z | Line 2166 static zend_object_value php_sqlite3_stmt_object_new(z |
| intern->db_obj_zval = NULL; | intern->db_obj_zval = NULL; |
| zend_object_std_init(&intern->zo, class_type TSRMLS_CC); | zend_object_std_init(&intern->zo, class_type TSRMLS_CC); |
| zend_hash_copy(intern->zo.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref,(void *) &tmp, sizeof(zval *)); | object_properties_init(&intern->zo, class_type); |
| retval.handle = zend_objects_store_put(intern, NULL, (zend_objects_free_object_storage_t) php_sqlite3_stmt_object_free_storage, NULL TSRMLS_CC); | retval.handle = zend_objects_store_put(intern, NULL, (zend_objects_free_object_storage_t) php_sqlite3_stmt_object_free_storage, NULL TSRMLS_CC); |
| retval.handlers = (zend_object_handlers *) &sqlite3_stmt_object_handlers; | retval.handlers = (zend_object_handlers *) &sqlite3_stmt_object_handlers; |
| Line 2046 static zend_object_value php_sqlite3_stmt_object_new(z | Line 2177 static zend_object_value php_sqlite3_stmt_object_new(z |
| static zend_object_value php_sqlite3_result_object_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */ | static zend_object_value php_sqlite3_result_object_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */ |
| { | { |
| zval *tmp; | |
| zend_object_value retval; | zend_object_value retval; |
| php_sqlite3_result *intern; | php_sqlite3_result *intern; |
| Line 2059 static zend_object_value php_sqlite3_result_object_new | Line 2189 static zend_object_value php_sqlite3_result_object_new |
| intern->stmt_obj_zval = NULL; | intern->stmt_obj_zval = NULL; |
| zend_object_std_init(&intern->zo, class_type TSRMLS_CC); | zend_object_std_init(&intern->zo, class_type TSRMLS_CC); |
| zend_hash_copy(intern->zo.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref,(void *) &tmp, sizeof(zval *)); | object_properties_init(&intern->zo, class_type); |
| retval.handle = zend_objects_store_put(intern, NULL, (zend_objects_free_object_storage_t) php_sqlite3_result_object_free_storage, NULL TSRMLS_CC); | retval.handle = zend_objects_store_put(intern, NULL, (zend_objects_free_object_storage_t) php_sqlite3_result_object_free_storage, NULL TSRMLS_CC); |
| retval.handlers = (zend_object_handlers *) &sqlite3_result_object_handlers; | retval.handlers = (zend_object_handlers *) &sqlite3_result_object_handlers; |