PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/sqlite3 - sqlite3.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 772 980 78.8 %
Date: 2014-08-04 Functions: 58 65 89.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 5                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2014 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Scott MacVicar <scottmac@php.net>                           |
      16             :    +----------------------------------------------------------------------+
      17             : */
      18             : 
      19             : /* $Id$ */
      20             : 
      21             : #ifdef HAVE_CONFIG_H
      22             : #include "config.h"
      23             : #endif
      24             : 
      25             : #include "php.h"
      26             : #include "php_ini.h"
      27             : #include "ext/standard/info.h"
      28             : #include "php_sqlite3.h"
      29             : #include "php_sqlite3_structs.h"
      30             : #include "main/SAPI.h"
      31             : 
      32             : #include <sqlite3.h>
      33             : 
      34             : #include "zend_exceptions.h"
      35             : #include "zend_interfaces.h"
      36             : #include "SAPI.h"
      37             : 
      38             : ZEND_DECLARE_MODULE_GLOBALS(sqlite3)
      39             : 
      40             : static PHP_GINIT_FUNCTION(sqlite3);
      41             : static int php_sqlite3_authorizer(void *autharg, int access_type, const char *arg3, const char *arg4, const char *arg5, const char *arg6);
      42             : static void sqlite3_param_dtor(void *data);
      43             : static int php_sqlite3_compare_stmt_zval_free(php_sqlite3_free_list **free_list, zval *statement);
      44             : 
      45             : /* {{{ Error Handler
      46             : */
      47          11 : static void php_sqlite3_error(php_sqlite3_db_object *db_obj, char *format, ...)
      48             : {
      49             :         va_list arg;
      50             :         char    *message;
      51             :         TSRMLS_FETCH();
      52             : 
      53          11 :         va_start(arg, format); 
      54          11 :         vspprintf(&message, 0, format, arg);
      55          11 :         va_end(arg);
      56             : 
      57          12 :         if (db_obj && db_obj->exception) {
      58           1 :                 zend_throw_exception(zend_exception_get_default(TSRMLS_C), message, 0 TSRMLS_CC);
      59             :         } else {
      60          10 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", message);
      61             :         }
      62             :         
      63          11 :         if (message) {
      64          11 :                 efree(message);
      65             :         }
      66          11 : }
      67             : /* }}} */
      68             : 
      69             : #define SQLITE3_CHECK_INITIALIZED(db_obj, member, class_name) \
      70             :         if (!(db_obj) || !(member)) { \
      71             :                 php_sqlite3_error(db_obj, "The " #class_name " object has not been correctly initialised"); \
      72             :                 RETURN_FALSE; \
      73             :         }
      74             : 
      75             : #define SQLITE3_CHECK_INITIALIZED_STMT(member, class_name) \
      76             :         if (!(member)) { \
      77             :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "The " #class_name " object has not been correctly initialised"); \
      78             :                 RETURN_FALSE; \
      79             :         }
      80             : 
      81             : /* {{{ PHP_INI
      82             : */
      83             : PHP_INI_BEGIN()
      84             :         STD_PHP_INI_ENTRY("sqlite3.extension_dir",  NULL, PHP_INI_SYSTEM, OnUpdateString, extension_dir, zend_sqlite3_globals, sqlite3_globals)
      85             : PHP_INI_END()
      86             : /* }}} */
      87             : 
      88             : /* Handlers */
      89             : static zend_object_handlers sqlite3_object_handlers;
      90             : static zend_object_handlers sqlite3_stmt_object_handlers;
      91             : static zend_object_handlers sqlite3_result_object_handlers;
      92             : 
      93             : /* Class entries */
      94             : zend_class_entry *php_sqlite3_sc_entry;
      95             : zend_class_entry *php_sqlite3_stmt_entry;
      96             : zend_class_entry *php_sqlite3_result_entry;
      97             : 
      98             : /* {{{ proto void SQLite3::open(String filename [, int Flags [, string Encryption Key]])
      99             :    Opens a SQLite 3 Database, if the build includes encryption then it will attempt to use the key. */
     100          68 : PHP_METHOD(sqlite3, open)
     101             : {
     102             :         php_sqlite3_db_object *db_obj;
     103          68 :         zval *object = getThis();
     104             :         char *filename, *encryption_key, *fullpath;
     105          68 :         int filename_len, encryption_key_len = 0;
     106          68 :         long flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
     107             :         zend_error_handling error_handling;
     108             : 
     109          68 :         db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC);
     110          68 :         zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC);
     111             : 
     112          68 :         if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|ls", &filename, &filename_len, &flags, &encryption_key, &encryption_key_len)) {
     113           1 :                 zend_restore_error_handling(&error_handling TSRMLS_CC);
     114           1 :                 return;
     115             :         }
     116             : 
     117          67 :         zend_restore_error_handling(&error_handling TSRMLS_CC);
     118             : 
     119          67 :         if (db_obj->initialised) {
     120           1 :                 zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Already initialised DB Object", 0 TSRMLS_CC);
     121             :         }
     122             : 
     123          67 :         if (strlen(filename) != filename_len) {
     124           0 :                 return;
     125             :         }
     126          67 :         if (memcmp(filename, ":memory:", sizeof(":memory:")) != 0) {
     127           6 :                 if (!(fullpath = expand_filepath(filename, NULL TSRMLS_CC))) {
     128           1 :                         zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Unable to expand filepath", 0 TSRMLS_CC);
     129           1 :                         return;
     130             :                 }
     131             : 
     132             : #if PHP_API_VERSION < 20100412
     133             :                 if (PG(safe_mode) && (!php_checkuid(fullpath, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
     134             :                         zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "safe_mode prohibits opening %s", fullpath);
     135             :                         efree(fullpath);
     136             :                         return;
     137             :                 }
     138             : #endif
     139             : 
     140           5 :                 if (php_check_open_basedir(fullpath TSRMLS_CC)) {
     141           1 :                         zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "open_basedir prohibits opening %s", fullpath);
     142           1 :                         efree(fullpath);
     143           1 :                         return;
     144             :                 }
     145             :         } else {
     146          61 :                 fullpath = estrdup(filename);
     147             :         }
     148             : 
     149             : #if SQLITE_VERSION_NUMBER >= 3005000
     150          65 :         if (sqlite3_open_v2(fullpath, &(db_obj->db), flags, NULL) != SQLITE_OK) {
     151             : #else
     152             :         if (sqlite3_open(fullpath, &(db_obj->db)) != SQLITE_OK) {
     153             : #endif
     154           1 :                 zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Unable to open database: %s", sqlite3_errmsg(db_obj->db));
     155           1 :                 if (fullpath) {
     156           1 :                         efree(fullpath);
     157             :                 }
     158           1 :                 return;
     159             :         }
     160             : 
     161             : #if SQLITE_HAS_CODEC
     162             :         if (encryption_key_len > 0) {
     163             :                 if (sqlite3_key(db_obj->db, encryption_key, encryption_key_len) != SQLITE_OK) {
     164             :                         zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Unable to open database: %s", sqlite3_errmsg(db_obj->db));
     165             :                         return;
     166             :                 }
     167             :         }
     168             : #endif
     169             : 
     170          64 :         db_obj->initialised = 1;
     171             : 
     172             : #if PHP_API_VERSION < 20100412
     173             :         if (PG(safe_mode) || (PG(open_basedir) && *PG(open_basedir))) {
     174             : #else
     175          64 :         if (PG(open_basedir) && *PG(open_basedir)) {
     176             : #endif
     177           2 :                 sqlite3_set_authorizer(db_obj->db, php_sqlite3_authorizer, NULL);
     178             :         }
     179             : 
     180          64 :         if (fullpath) {
     181          64 :                 efree(fullpath);
     182             :         }
     183             : }
     184             : /* }}} */
     185             : 
     186             : /* {{{ proto bool SQLite3::close()
     187             :    Close a SQLite 3 Database. */
     188          39 : PHP_METHOD(sqlite3, close)
     189             : {
     190             :         php_sqlite3_db_object *db_obj;
     191          39 :         zval *object = getThis();
     192             :         int errcode;
     193          39 :         db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC);
     194             : 
     195          39 :         if (zend_parse_parameters_none() == FAILURE) {
     196           2 :                 return;
     197             :         }
     198             : 
     199          37 :         if (db_obj->initialised) {
     200          37 :         zend_llist_clean(&(db_obj->free_list));
     201          37 :                 if(db_obj->db) {
     202          37 :             errcode = sqlite3_close(db_obj->db);
     203          37 :             if (errcode != SQLITE_OK) {
     204           0 :                             php_sqlite3_error(db_obj, "Unable to close database: %d, %s", errcode, sqlite3_errmsg(db_obj->db));
     205           0 :                 RETURN_FALSE;
     206             :                     }
     207             :         }
     208          37 :                 db_obj->initialised = 0;
     209             :         }
     210             : 
     211          37 :         RETURN_TRUE;
     212             : }
     213             : /* }}} */
     214             : 
     215             : /* {{{ proto bool SQLite3::exec(String Query)
     216             :    Executes a result-less query against a given database. */
     217         105 : PHP_METHOD(sqlite3, exec)
     218             : {
     219             :         php_sqlite3_db_object *db_obj;
     220         105 :         zval *object = getThis();
     221         105 :         char *sql, *errtext = NULL;
     222             :         int sql_len;
     223         105 :         db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC);
     224             : 
     225         105 :         SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)
     226             : 
     227         105 :         if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &sql, &sql_len)) {
     228           1 :                 return;
     229             :         }
     230             : 
     231         104 :         if (sqlite3_exec(db_obj->db, sql, NULL, NULL, &errtext) != SQLITE_OK) {
     232           1 :                 php_sqlite3_error(db_obj, "%s", errtext);
     233           1 :                 sqlite3_free(errtext);
     234           1 :                 RETURN_FALSE;
     235             :         }
     236             : 
     237         103 :         RETURN_TRUE;
     238             : }
     239             : /* }}} */
     240             : 
     241             : /* {{{ proto Array SQLite3::version()
     242             :    Returns the SQLite3 Library version as a string constant and as a number. */
     243           3 : PHP_METHOD(sqlite3, version)
     244             : {
     245           3 :         if (zend_parse_parameters_none() == FAILURE) {
     246           1 :                 return;
     247             :         }
     248             : 
     249           2 :         array_init(return_value);
     250             : 
     251           2 :         add_assoc_string(return_value, "versionString", (char*)sqlite3_libversion(), 1);
     252           2 :         add_assoc_long(return_value, "versionNumber", sqlite3_libversion_number());
     253             : 
     254           2 :         return;
     255             : }
     256             : /* }}} */
     257             : 
     258             : /* {{{ proto int SQLite3::lastInsertRowID()
     259             :    Returns the rowid of the most recent INSERT into the database from the database connection. */
     260           3 : PHP_METHOD(sqlite3, lastInsertRowID)
     261             : {
     262             :         php_sqlite3_db_object *db_obj;
     263           3 :         zval *object = getThis();
     264           3 :         db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC);
     265             : 
     266           3 :         SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)
     267             : 
     268           3 :         if (zend_parse_parameters_none() == FAILURE) {
     269           1 :                 return;
     270             :         }
     271             : 
     272           2 :         RETURN_LONG(sqlite3_last_insert_rowid(db_obj->db));
     273             : }
     274             : /* }}} */
     275             : 
     276             : /* {{{ proto int SQLite3::lastErrorCode()
     277             :    Returns the numeric result code of the most recent failed sqlite API call for the database connection. */
     278           2 : PHP_METHOD(sqlite3, lastErrorCode)
     279             : {
     280             :         php_sqlite3_db_object *db_obj;
     281           2 :         zval *object = getThis();
     282           2 :         db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC);
     283             : 
     284           2 :         SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->db, SQLite3)
     285             : 
     286           2 :         if (zend_parse_parameters_none() == FAILURE) {
     287           1 :                 return;
     288             :         }
     289             : 
     290           1 :         RETURN_LONG(sqlite3_errcode(db_obj->db));
     291             : }
     292             : /* }}} */
     293             : 
     294             : /* {{{ proto string SQLite3::lastErrorMsg()
     295             :    Returns english text describing the most recent failed sqlite API call for the database connection. */
     296           2 : PHP_METHOD(sqlite3, lastErrorMsg)
     297             : {
     298             :         php_sqlite3_db_object *db_obj;
     299           2 :         zval *object = getThis();
     300           2 :         db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC);
     301             : 
     302           2 :         SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->db, SQLite3)
     303             : 
     304           2 :         if (zend_parse_parameters_none() == FAILURE) {
     305           1 :                 return;
     306             :         }
     307             : 
     308           1 :         RETVAL_STRING((char *)sqlite3_errmsg(db_obj->db), 1);
     309             : }
     310             : /* }}} */
     311             : 
     312             : /* {{{ proto bool SQLite3::busyTimeout(int msecs)
     313             :    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. */
     314           0 : PHP_METHOD(sqlite3, busyTimeout)
     315             : {
     316             :         php_sqlite3_db_object *db_obj;
     317           0 :         zval *object = getThis();
     318             :         long ms;
     319             :         int return_code;
     320           0 :         db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC);
     321             : 
     322           0 :         SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)
     323             : 
     324           0 :         if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ms)) {
     325           0 :                 return;
     326             :         }
     327             : 
     328           0 :         return_code = sqlite3_busy_timeout(db_obj->db, ms);
     329           0 :         if (return_code != SQLITE_OK) {
     330           0 :                 php_sqlite3_error(db_obj, "Unable to set busy timeout: %d, %s", return_code, sqlite3_errmsg(db_obj->db));
     331           0 :                 RETURN_FALSE;
     332             :         }
     333             : 
     334           0 :         RETURN_TRUE;
     335             : }
     336             : /* }}} */
     337             : 
     338             : 
     339             : #ifndef SQLITE_OMIT_LOAD_EXTENSION
     340             : /* {{{ proto bool SQLite3::loadExtension(String Shared Library)
     341             :    Attempts to load an SQLite extension library. */
     342           4 : PHP_METHOD(sqlite3, loadExtension)
     343             : {
     344             :         php_sqlite3_db_object *db_obj;
     345           4 :         zval *object = getThis();
     346           4 :         char *extension, *lib_path, *extension_dir, *errtext = NULL;
     347             :         char fullpath[MAXPATHLEN];
     348             :         int extension_len, extension_dir_len;
     349           4 :         db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC);
     350             : 
     351           4 :         SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)
     352             : 
     353           4 :         if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &extension, &extension_len)) {
     354           1 :                 return;
     355             :         }
     356             : 
     357             : #ifdef ZTS
     358             :         if ((strncmp(sapi_module.name, "cgi", 3) != 0) &&
     359             :                 (strcmp(sapi_module.name, "cli") != 0) &&
     360             :                 (strncmp(sapi_module.name, "embed", 5) != 0)
     361             :         ) {             php_sqlite3_error(db_obj, "Not supported in multithreaded Web servers");
     362             :                 RETURN_FALSE;
     363             :         }
     364             : #endif
     365             : 
     366           3 :         if (!SQLITE3G(extension_dir)) {
     367           1 :                 php_sqlite3_error(db_obj, "SQLite Extension are disabled");
     368           1 :                 RETURN_FALSE;
     369             :         }
     370             : 
     371           2 :         if (extension_len == 0) {
     372           1 :                 php_sqlite3_error(db_obj, "Empty string as an extension");
     373           1 :                 RETURN_FALSE;
     374             :         }
     375             : 
     376           1 :         extension_dir = SQLITE3G(extension_dir);
     377           1 :         extension_dir_len = strlen(SQLITE3G(extension_dir));
     378             : 
     379           1 :         if (IS_SLASH(extension_dir[extension_dir_len-1])) {
     380           0 :                 spprintf(&lib_path, 0, "%s%s", extension_dir, extension);
     381             :         } else {
     382           1 :                 spprintf(&lib_path, 0, "%s%c%s", extension_dir, DEFAULT_SLASH, extension);
     383             :         }
     384             : 
     385           1 :         if (!VCWD_REALPATH(lib_path, fullpath)) {
     386           1 :                 php_sqlite3_error(db_obj, "Unable to load extension at '%s'", lib_path);
     387           1 :                 efree(lib_path);
     388           1 :                 RETURN_FALSE;
     389             :         }
     390             : 
     391           0 :         efree(lib_path);
     392             : 
     393           0 :         if (strncmp(fullpath, extension_dir, extension_dir_len) != 0) {
     394           0 :                 php_sqlite3_error(db_obj, "Unable to open extensions outside the defined directory");
     395           0 :                 RETURN_FALSE;
     396             :         }
     397             : 
     398             :         /* Extension loading should only be enabled for when we attempt to load */
     399           0 :         sqlite3_enable_load_extension(db_obj->db, 1);
     400           0 :         if (sqlite3_load_extension(db_obj->db, fullpath, 0, &errtext) != SQLITE_OK) {
     401           0 :                 php_sqlite3_error(db_obj, "%s", errtext);
     402           0 :                 sqlite3_free(errtext);
     403           0 :                 sqlite3_enable_load_extension(db_obj->db, 0);
     404           0 :                 RETURN_FALSE;
     405             :         }
     406           0 :         sqlite3_enable_load_extension(db_obj->db, 0);
     407             : 
     408           0 :         RETURN_TRUE;
     409             : }
     410             : /* }}} */
     411             : #endif
     412             : 
     413             : /* {{{ proto int SQLite3::changes()
     414             :   Returns the number of database rows that were changed (or inserted or deleted) by the most recent SQL statement. */
     415           3 : PHP_METHOD(sqlite3, changes)
     416             : {
     417             :         php_sqlite3_db_object *db_obj;
     418           3 :         zval *object = getThis();
     419           3 :         db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC);
     420             : 
     421           3 :         SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)
     422             : 
     423           3 :         if (zend_parse_parameters_none() == FAILURE) {
     424           1 :                 return;
     425             :         }
     426             : 
     427           2 :         RETURN_LONG(sqlite3_changes(db_obj->db));
     428             : }
     429             : /* }}} */
     430             : 
     431             : /* {{{ proto String SQLite3::escapeString(String value)
     432             :    Returns a string that has been properly escaped. */
     433           1 : PHP_METHOD(sqlite3, escapeString)
     434             : {
     435             :         char *sql, *ret;
     436             :         int sql_len;
     437             : 
     438           1 :         if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &sql, &sql_len)) {
     439           0 :                 return;
     440             :         }
     441             : 
     442           1 :         if (sql_len) {
     443           1 :                 ret = sqlite3_mprintf("%q", sql);
     444           1 :                 if (ret) {
     445           1 :                         RETVAL_STRING(ret, 1);
     446           1 :                         sqlite3_free(ret);
     447             :                 }
     448             :         } else {
     449           0 :                 RETURN_EMPTY_STRING();
     450             :         }
     451             : }
     452             : /* }}} */
     453             : 
     454             : /* {{{ proto SQLite3Stmt SQLite3::prepare(String Query)
     455             :    Returns a prepared SQL statement for execution. */
     456          28 : PHP_METHOD(sqlite3, prepare)
     457             : {
     458             :         php_sqlite3_db_object *db_obj;
     459             :         php_sqlite3_stmt *stmt_obj;
     460          28 :         zval *object = getThis();
     461             :         char *sql;
     462             :         int sql_len, errcode;
     463             :         php_sqlite3_free_list *free_item;
     464             : 
     465          28 :         db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC);
     466             : 
     467          28 :         SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)
     468             : 
     469          28 :         if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &sql, &sql_len)) {
     470           1 :                 return;
     471             :         }
     472             : 
     473          27 :         if (!sql_len) {
     474           1 :                 RETURN_FALSE;
     475             :         }
     476             : 
     477          26 :         object_init_ex(return_value, php_sqlite3_stmt_entry);
     478          26 :         stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(return_value TSRMLS_CC);
     479          26 :         stmt_obj->db_obj = db_obj;
     480          26 :         stmt_obj->db_obj_zval = getThis();
     481             : 
     482             :         Z_ADDREF_P(object);
     483             : 
     484          26 :         errcode = sqlite3_prepare_v2(db_obj->db, sql, sql_len, &(stmt_obj->stmt), NULL);
     485          26 :         if (errcode != SQLITE_OK) {
     486           1 :                 php_sqlite3_error(db_obj, "Unable to prepare statement: %d, %s", errcode, sqlite3_errmsg(db_obj->db));
     487             :                 zval_dtor(return_value);
     488           1 :                 RETURN_FALSE;
     489             :         }
     490             : 
     491          25 :         stmt_obj->initialised = 1;
     492             : 
     493          25 :         free_item = emalloc(sizeof(php_sqlite3_free_list));
     494          25 :         free_item->stmt_obj = stmt_obj;
     495          25 :         free_item->stmt_obj_zval = return_value;
     496             : 
     497          25 :         zend_llist_add_element(&(db_obj->free_list), &free_item);
     498             : }
     499             : /* }}} */
     500             : 
     501             : /* {{{ proto SQLite3Result SQLite3::query(String Query)
     502             :    Returns true or false, for queries that return data it will return a SQLite3Result object. */
     503          26 : PHP_METHOD(sqlite3, query)
     504             : {
     505             :         php_sqlite3_db_object *db_obj;
     506             :         php_sqlite3_result *result;
     507             :         php_sqlite3_stmt *stmt_obj;
     508          26 :         zval *object = getThis();
     509          26 :         zval *stmt = NULL;
     510          26 :         char *sql, *errtext = NULL;
     511             :         int sql_len, return_code;
     512          26 :         db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC);
     513             : 
     514          26 :         SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)
     515             : 
     516          26 :         if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &sql, &sql_len)) {
     517           2 :                 return;
     518             :         }
     519             : 
     520          24 :         if (!sql_len) {
     521           1 :                 RETURN_FALSE;
     522             :         }
     523             : 
     524             :         /* If there was no return value then just execute the query */
     525          23 :         if (!return_value_used) {
     526           3 :                 if (sqlite3_exec(db_obj->db, sql, NULL, NULL, &errtext) != SQLITE_OK) {
     527           2 :                         php_sqlite3_error(db_obj, "%s", errtext);
     528           2 :                         sqlite3_free(errtext);
     529             :                 }
     530           3 :                 return;
     531             :         }
     532             : 
     533          20 :         MAKE_STD_ZVAL(stmt);
     534             : 
     535          20 :         object_init_ex(stmt, php_sqlite3_stmt_entry);
     536          20 :         stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(stmt TSRMLS_CC);
     537          20 :         stmt_obj->db_obj = db_obj;
     538          20 :         stmt_obj->db_obj_zval = getThis();
     539             : 
     540             :         Z_ADDREF_P(object);
     541             : 
     542          20 :         return_code = sqlite3_prepare_v2(db_obj->db, sql, sql_len, &(stmt_obj->stmt), NULL);
     543          20 :         if (return_code != SQLITE_OK) {
     544           1 :                 php_sqlite3_error(db_obj, "Unable to prepare statement: %d, %s", return_code, sqlite3_errmsg(db_obj->db));
     545           1 :                 zval_ptr_dtor(&stmt);
     546           1 :                 RETURN_FALSE;
     547             :         }
     548             : 
     549          19 :         stmt_obj->initialised = 1;
     550             : 
     551          19 :         object_init_ex(return_value, php_sqlite3_result_entry);
     552          19 :         result = (php_sqlite3_result *)zend_object_store_get_object(return_value TSRMLS_CC);
     553          19 :         result->db_obj = db_obj;
     554          19 :         result->stmt_obj = stmt_obj;
     555          19 :         result->stmt_obj_zval = stmt;
     556             : 
     557          19 :         return_code = sqlite3_step(result->stmt_obj->stmt);
     558             : 
     559          19 :         switch (return_code) {
     560             :                 case SQLITE_ROW: /* Valid Row */
     561             :                 case SQLITE_DONE: /* Valid but no results */
     562             :                 {
     563             :                         php_sqlite3_free_list *free_item;
     564          19 :                         free_item = emalloc(sizeof(php_sqlite3_free_list));
     565          19 :                         free_item->stmt_obj = stmt_obj;
     566          19 :                         free_item->stmt_obj_zval = stmt;
     567          19 :                         zend_llist_add_element(&(db_obj->free_list), &free_item);
     568          19 :                         sqlite3_reset(result->stmt_obj->stmt);
     569          19 :                         break;
     570             :                 }
     571             :                 default:
     572           0 :                         php_sqlite3_error(db_obj, "Unable to execute statement: %s", sqlite3_errmsg(db_obj->db));
     573           0 :                         sqlite3_finalize(stmt_obj->stmt);
     574           0 :                         stmt_obj->initialised = 0;
     575             :                         zval_dtor(return_value);
     576           0 :                         RETURN_FALSE;
     577             :         }
     578             : }
     579             : /* }}} */
     580             : 
     581          70 : static zval* sqlite_value_to_zval(sqlite3_stmt *stmt, int column) /* {{{ */
     582             : {
     583             :         zval *data;
     584          70 :         MAKE_STD_ZVAL(data);
     585          70 :         switch (sqlite3_column_type(stmt, column)) {
     586             :                 case SQLITE_INTEGER:
     587          29 :                         if ((sqlite3_column_int64(stmt, column)) >= INT_MAX || sqlite3_column_int64(stmt, column) <= INT_MIN) {
     588           1 :                                 ZVAL_STRINGL(data, (char *)sqlite3_column_text(stmt, column), sqlite3_column_bytes(stmt, column), 1);
     589             :                         } else {
     590          27 :                                 ZVAL_LONG(data, sqlite3_column_int64(stmt, column));
     591             :                         }
     592          28 :                         break;
     593             : 
     594             :                 case SQLITE_FLOAT:
     595           0 :                         ZVAL_DOUBLE(data, sqlite3_column_double(stmt, column));
     596           0 :                         break;
     597             : 
     598             :                 case SQLITE_NULL:
     599           0 :                         ZVAL_NULL(data);
     600           0 :                         break;
     601             : 
     602             :                 case SQLITE3_TEXT:
     603          42 :                         ZVAL_STRING(data, (char*)sqlite3_column_text(stmt, column), 1);
     604          42 :                         break;
     605             : 
     606             :                 case SQLITE_BLOB:
     607             :                 default:
     608           0 :                         ZVAL_STRINGL(data, (char*)sqlite3_column_blob(stmt, column), sqlite3_column_bytes(stmt, column), 1);
     609             :         }
     610          70 :         return data;
     611             : }
     612             : /* }}} */
     613             : 
     614             : /* {{{ proto SQLite3Result SQLite3::querySingle(String Query [, bool entire_row = false])
     615             :    Returns a string of the first column, or an array of the entire row. */
     616           9 : PHP_METHOD(sqlite3, querySingle)
     617             : {
     618             :         php_sqlite3_db_object *db_obj;
     619           9 :         zval *object = getThis();
     620           9 :         char *sql, *errtext = NULL;
     621             :         int sql_len, return_code;
     622           9 :         zend_bool entire_row = 0;
     623             :         sqlite3_stmt *stmt;
     624           9 :         db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC);
     625             : 
     626           9 :         SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)
     627             : 
     628           9 :         if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &sql, &sql_len, &entire_row)) {
     629           2 :                 return;
     630             :         }
     631             : 
     632           7 :         if (!sql_len) {
     633           1 :                 RETURN_FALSE;
     634             :         }
     635             : 
     636             :         /* If there was no return value then just execute the query */
     637           6 :         if (!return_value_used) {
     638           0 :                 if (sqlite3_exec(db_obj->db, sql, NULL, NULL, &errtext) != SQLITE_OK) {
     639           0 :                         php_sqlite3_error(db_obj, "%s", errtext);
     640           0 :                         sqlite3_free(errtext);
     641             :                 }
     642           0 :                 return;
     643             :         }
     644             : 
     645           6 :         return_code = sqlite3_prepare_v2(db_obj->db, sql, sql_len, &stmt, NULL);
     646           6 :         if (return_code != SQLITE_OK) {
     647           0 :                 php_sqlite3_error(db_obj, "Unable to prepare statement: %d, %s", return_code, sqlite3_errmsg(db_obj->db));
     648           0 :                 RETURN_FALSE;
     649             :         }
     650             : 
     651           6 :         return_code = sqlite3_step(stmt);
     652             : 
     653           6 :         switch (return_code) {
     654             :                 case SQLITE_ROW: /* Valid Row */
     655             :                 {
     656           6 :                         if (!entire_row) {
     657             :                                 zval *data;
     658           4 :                                 data = sqlite_value_to_zval(stmt, 0);
     659           4 :                                 *return_value = *data;
     660             :                                 zval_copy_ctor(return_value);
     661             :                                 zval_dtor(data);
     662           4 :                                 FREE_ZVAL(data);
     663             :                         } else {
     664           2 :                                 int i = 0;
     665           2 :                                 array_init(return_value);
     666           6 :                                 for (i = 0; i < sqlite3_data_count(stmt); i++) {
     667             :                                         zval *data;
     668           4 :                                         data = sqlite_value_to_zval(stmt, i);
     669           4 :                                         add_assoc_zval(return_value, (char*)sqlite3_column_name(stmt, i), data);
     670             :                                 }
     671             :                         }
     672           6 :                         break;
     673             :                 }
     674             :                 case SQLITE_DONE: /* Valid but no results */
     675             :                 {
     676           0 :                         if (!entire_row) {
     677           0 :                                 RETVAL_NULL();
     678             :                         } else {
     679           0 :                                 array_init(return_value);
     680             :                         }
     681           0 :                         break;
     682             :                 }
     683             :                 default:
     684           0 :                         php_sqlite3_error(db_obj, "Unable to execute statement: %s", sqlite3_errmsg(db_obj->db));
     685           0 :                         RETVAL_FALSE;
     686             :         }
     687           6 :         sqlite3_finalize(stmt);
     688             : }
     689             : /* }}} */
     690             : 
     691          19 : static int sqlite3_do_callback(struct php_sqlite3_fci *fc, zval *cb, int argc, sqlite3_value **argv, sqlite3_context *context, int is_agg TSRMLS_DC) /* {{{ */
     692             : {
     693          19 :         zval ***zargs = NULL;
     694          19 :         zval *retval = NULL;
     695             :         int i;
     696             :         int ret;
     697             :         int fake_argc;
     698          19 :         php_sqlite3_agg_context *agg_context = NULL;
     699             : 
     700          19 :         if (is_agg) {
     701          12 :                 is_agg = 2;
     702             :         }
     703             : 
     704          19 :         fake_argc = argc + is_agg;
     705             : 
     706          19 :         fc->fci.size = sizeof(fc->fci);
     707          19 :         fc->fci.function_table = EG(function_table);
     708          19 :         fc->fci.function_name = cb;
     709          19 :         fc->fci.symbol_table = NULL;
     710          19 :         fc->fci.object_ptr = NULL;
     711          19 :         fc->fci.retval_ptr_ptr = &retval;
     712          19 :         fc->fci.param_count = fake_argc;
     713             : 
     714             :         /* build up the params */
     715             : 
     716          19 :         if (fake_argc) {
     717          19 :                 zargs = (zval ***)safe_emalloc(fake_argc, sizeof(zval **), 0);
     718             :         }
     719             : 
     720          19 :         if (is_agg) {
     721             :                 /* summon the aggregation context */
     722          12 :                 agg_context = (php_sqlite3_agg_context *)sqlite3_aggregate_context(context, sizeof(php_sqlite3_agg_context));
     723             : 
     724          12 :                 if (!agg_context->zval_context) {
     725           2 :                         MAKE_STD_ZVAL(agg_context->zval_context);
     726           2 :                         ZVAL_NULL(agg_context->zval_context);
     727             :                 }
     728          12 :                 zargs[0] = &agg_context->zval_context;
     729             : 
     730          12 :                 zargs[1] = emalloc(sizeof(zval*));
     731          12 :                 MAKE_STD_ZVAL(*zargs[1]);
     732          12 :                 ZVAL_LONG(*zargs[1], agg_context->row_count);
     733             :         }
     734             : 
     735          36 :         for (i = 0; i < argc; i++) {
     736          17 :                 zargs[i + is_agg] = emalloc(sizeof(zval *));
     737          17 :                 MAKE_STD_ZVAL(*zargs[i + is_agg]);
     738             : 
     739          17 :                 switch (sqlite3_value_type(argv[i])) {
     740             :                         case SQLITE_INTEGER:
     741             : #if LONG_MAX > 2147483647
     742          10 :                                 ZVAL_LONG(*zargs[i + is_agg], sqlite3_value_int64(argv[i]));
     743             : #else
     744             :                                 ZVAL_LONG(*zargs[i + is_agg], sqlite3_value_int(argv[i]));
     745             : #endif
     746          10 :                                 break;
     747             : 
     748             :                         case SQLITE_FLOAT:
     749           0 :                                 ZVAL_DOUBLE(*zargs[i + is_agg], sqlite3_value_double(argv[i]));
     750           0 :                                 break;
     751             : 
     752             :                         case SQLITE_NULL:
     753           0 :                                 ZVAL_NULL(*zargs[i + is_agg]);
     754           0 :                                 break;
     755             : 
     756             :                         case SQLITE_BLOB:
     757             :                         case SQLITE3_TEXT:
     758             :                         default:
     759           7 :                                 ZVAL_STRINGL(*zargs[i + is_agg], (char*)sqlite3_value_text(argv[i]), sqlite3_value_bytes(argv[i]), 1);
     760             :                                 break;
     761             :                 }
     762             :         }
     763             : 
     764          19 :         fc->fci.params = zargs;
     765             : 
     766          19 :         if ((ret = zend_call_function(&fc->fci, &fc->fcc TSRMLS_CC)) == FAILURE) {
     767           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred while invoking the callback");
     768             :         }
     769             : 
     770             :         /* clean up the params */
     771          19 :         if (fake_argc) {
     772          36 :                 for (i = is_agg; i < argc + is_agg; i++) {
     773          17 :                         zval_ptr_dtor(zargs[i]);
     774          17 :                         efree(zargs[i]);
     775             :                 }
     776          19 :                 if (is_agg) {
     777          12 :                         zval_ptr_dtor(zargs[1]);
     778          12 :                         efree(zargs[1]);
     779             :                 }
     780          19 :                 efree(zargs);
     781             :         }
     782             : 
     783          28 :         if (!is_agg || !argv) {
     784             :                 /* only set the sqlite return value if we are a scalar function,
     785             :                  * or if we are finalizing an aggregate */
     786           9 :                 if (retval) {
     787           9 :                         switch (Z_TYPE_P(retval)) {
     788             :                                 case IS_LONG:
     789             : #if LONG_MAX > 2147483647
     790           0 :                                         sqlite3_result_int64(context, Z_LVAL_P(retval));
     791             : #else
     792             :                                         sqlite3_result_int(context, Z_LVAL_P(retval));
     793             : #endif
     794           0 :                                         break;
     795             : 
     796             :                                 case IS_NULL:
     797           0 :                                         sqlite3_result_null(context);
     798           0 :                                         break;
     799             : 
     800             :                                 case IS_DOUBLE:
     801           0 :                                         sqlite3_result_double(context, Z_DVAL_P(retval));
     802           0 :                                         break;
     803             : 
     804             :                                 default:
     805           9 :                                         convert_to_string_ex(&retval);
     806           9 :                                         sqlite3_result_text(context, Z_STRVAL_P(retval), Z_STRLEN_P(retval), SQLITE_TRANSIENT);
     807             :                                         break;
     808             :                         }
     809             :                 } else {
     810           0 :                         sqlite3_result_error(context, "failed to invoke callback", 0);
     811             :                 }
     812             : 
     813           9 :                 if (agg_context && agg_context->zval_context) {
     814           2 :                         zval_ptr_dtor(&agg_context->zval_context);
     815             :                 }
     816             :         } else {
     817             :                 /* we're stepping in an aggregate; the return value goes into
     818             :                  * the context */
     819          10 :                 if (agg_context && agg_context->zval_context) {
     820          10 :                         zval_ptr_dtor(&agg_context->zval_context);
     821             :                 }
     822          10 :                 if (retval) {
     823          10 :                         agg_context->zval_context = retval;
     824          10 :                         retval = NULL;
     825             :                 } else {
     826           0 :                         agg_context->zval_context = NULL;
     827             :                 }
     828             :         }
     829             : 
     830          19 :         if (retval) {
     831           9 :                 zval_ptr_dtor(&retval);
     832             :         }
     833          19 :         return ret;
     834             : }
     835             : /* }}}*/
     836             : 
     837           7 : static void php_sqlite3_callback_func(sqlite3_context *context, int argc, sqlite3_value **argv) /* {{{ */
     838             : {
     839           7 :         php_sqlite3_func *func = (php_sqlite3_func *)sqlite3_user_data(context);
     840             :         TSRMLS_FETCH();
     841             : 
     842           7 :         sqlite3_do_callback(&func->afunc, func->func, argc, argv, context, 0 TSRMLS_CC);
     843           7 : }
     844             : /* }}}*/
     845             : 
     846          10 : static void php_sqlite3_callback_step(sqlite3_context *context, int argc, sqlite3_value **argv) /* {{{ */
     847             : {
     848          10 :         php_sqlite3_func *func = (php_sqlite3_func *)sqlite3_user_data(context);
     849          10 :         php_sqlite3_agg_context *agg_context = (php_sqlite3_agg_context *)sqlite3_aggregate_context(context, sizeof(php_sqlite3_agg_context));
     850             : 
     851             :         TSRMLS_FETCH();
     852          10 :         agg_context->row_count++;
     853             : 
     854          10 :         sqlite3_do_callback(&func->astep, func->step, argc, argv, context, 1 TSRMLS_CC);
     855          10 : }
     856             : /* }}} */
     857             : 
     858           2 : static void php_sqlite3_callback_final(sqlite3_context *context) /* {{{ */
     859             : {
     860           2 :         php_sqlite3_func *func = (php_sqlite3_func *)sqlite3_user_data(context);
     861           2 :         php_sqlite3_agg_context *agg_context = (php_sqlite3_agg_context *)sqlite3_aggregate_context(context, sizeof(php_sqlite3_agg_context));
     862             : 
     863             :         TSRMLS_FETCH();
     864           2 :         agg_context->row_count = 0;
     865             : 
     866           2 :         sqlite3_do_callback(&func->afini, func->fini, 0, NULL, context, 1 TSRMLS_CC);
     867           2 : }
     868             : /* }}} */
     869             : 
     870           4 : static int php_sqlite3_callback_compare(void *coll, int a_len, const void *a, int b_len, const void* b) /* {{{ */
     871             : {
     872           4 :         php_sqlite3_collation *collation = (php_sqlite3_collation*)coll;
     873           4 :         zval ***zargs = NULL;
     874           4 :         zval *retval = NULL;
     875             :         int ret;
     876             : 
     877             :         TSRMLS_FETCH();
     878             : 
     879           4 :         collation->fci.fci.size = (sizeof(collation->fci.fci));
     880           4 :         collation->fci.fci.function_table = EG(function_table);
     881           4 :         collation->fci.fci.function_name = collation->cmp_func;
     882           4 :         collation->fci.fci.symbol_table = NULL;
     883           4 :         collation->fci.fci.object_ptr = NULL;
     884           4 :         collation->fci.fci.retval_ptr_ptr = &retval;
     885           4 :         collation->fci.fci.param_count = 2;
     886             : 
     887           4 :         zargs = (zval***)safe_emalloc(2, sizeof(zval**), 0);
     888           4 :         zargs[0] = emalloc(sizeof(zval*));
     889           4 :         zargs[1] = emalloc(sizeof(zval*));
     890             : 
     891           4 :         MAKE_STD_ZVAL(*zargs[0]);
     892           4 :         ZVAL_STRINGL(*zargs[0], a, a_len, 1);
     893             : 
     894           4 :         MAKE_STD_ZVAL(*zargs[1]);
     895           4 :         ZVAL_STRINGL(*zargs[1], b, b_len, 1);
     896             :  
     897           4 :         collation->fci.fci.params = zargs;
     898             : 
     899           4 :         if ((ret = zend_call_function(&collation->fci.fci, &collation->fci.fcc TSRMLS_CC)) == FAILURE) {
     900           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred while invoking the compare callback");
     901             :         }
     902             : 
     903           4 :         zval_ptr_dtor(zargs[0]);
     904           4 :         zval_ptr_dtor(zargs[1]);
     905           4 :         efree(zargs[0]);
     906           4 :         efree(zargs[1]);
     907           4 :         efree(zargs);
     908             : 
     909             :         //retval ought to contain a ZVAL_LONG by now
     910             :         // (the result of a comparison, i.e. most likely -1, 0, or 1)
     911             :         //I suppose we could accept any scalar return type, though.
     912           4 :         if (Z_TYPE_P(retval) != IS_LONG){
     913           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred while invoking the compare callback (invalid return type).  Collation behaviour is undefined.");
     914             :         }else{
     915           4 :                 ret = Z_LVAL_P(retval);
     916             :         }
     917             : 
     918           4 :         zval_ptr_dtor(&retval);
     919             : 
     920           4 :         return ret;
     921             : }
     922             : /* }}} */
     923             : 
     924             : /* {{{ proto bool SQLite3::createFunction(string name, mixed callback [, int argcount])
     925             :    Allows registration of a PHP function as a SQLite UDF that can be called within SQL statements. */
     926           4 : PHP_METHOD(sqlite3, createFunction)
     927             : {
     928             :         php_sqlite3_db_object *db_obj;
     929           4 :         zval *object = getThis();
     930             :         php_sqlite3_func *func;
     931             :         char *sql_func, *callback_name;
     932             :         int sql_func_len;
     933             :         zval *callback_func;
     934           4 :         long sql_func_num_args = -1;
     935           4 :         db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC);
     936             : 
     937           4 :         SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)
     938             : 
     939           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|l", &sql_func, &sql_func_len, &callback_func, &sql_func_num_args) == FAILURE) {
     940           0 :                 return;
     941             :         }
     942             : 
     943           4 :         if (!sql_func_len) {
     944           0 :                 RETURN_FALSE;
     945             :         }
     946             : 
     947           4 :         if (!zend_is_callable(callback_func, 0, &callback_name TSRMLS_CC)) {
     948           0 :                 php_sqlite3_error(db_obj, "Not a valid callback function %s", callback_name);
     949           0 :                 efree(callback_name);
     950           0 :                 RETURN_FALSE;
     951             :         }
     952           4 :         efree(callback_name);
     953             : 
     954           4 :         func = (php_sqlite3_func *)ecalloc(1, sizeof(*func));
     955             : 
     956           4 :         if (sqlite3_create_function(db_obj->db, sql_func, sql_func_num_args, SQLITE_UTF8, func, php_sqlite3_callback_func, NULL, NULL) == SQLITE_OK) {
     957           4 :                 func->func_name = estrdup(sql_func);
     958             : 
     959           4 :                 MAKE_STD_ZVAL(func->func);
     960          12 :                 MAKE_COPY_ZVAL(&callback_func, func->func);
     961             : 
     962           4 :                 func->argc = sql_func_num_args;
     963           4 :                 func->next = db_obj->funcs;
     964           4 :                 db_obj->funcs = func;
     965             : 
     966           4 :                 RETURN_TRUE;
     967             :         }
     968           0 :         efree(func);
     969             : 
     970           0 :         RETURN_FALSE;
     971             : }
     972             : /* }}} */
     973             : 
     974             : /* {{{ proto bool SQLite3::createAggregate(string name, mixed step, mixed final [, int argcount])
     975             :    Allows registration of a PHP function for use as an aggregate. */
     976           5 : PHP_METHOD(sqlite3, createAggregate)
     977             : {
     978             :         php_sqlite3_db_object *db_obj;
     979           5 :         zval *object = getThis();
     980             :         php_sqlite3_func *func;
     981             :         char *sql_func, *callback_name;
     982             :         int sql_func_len;
     983             :         zval *step_callback, *fini_callback;
     984           5 :         long sql_func_num_args = -1;
     985           5 :         db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC);
     986             : 
     987           5 :         SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)
     988             : 
     989           5 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "szz|l", &sql_func, &sql_func_len, &step_callback, &fini_callback, &sql_func_num_args) == FAILURE) {
     990           1 :                 return;
     991             :         }
     992             : 
     993           4 :         if (!sql_func_len) {
     994           0 :                 RETURN_FALSE;
     995             :         }
     996             : 
     997           4 :         if (!zend_is_callable(step_callback, 0, &callback_name TSRMLS_CC)) {
     998           1 :                 php_sqlite3_error(db_obj, "Not a valid callback function %s", callback_name);
     999           1 :                 efree(callback_name);
    1000           1 :                 RETURN_FALSE;
    1001             :         }
    1002           3 :         efree(callback_name);
    1003             : 
    1004           3 :         if (!zend_is_callable(fini_callback, 0, &callback_name TSRMLS_CC)) {
    1005           1 :                 php_sqlite3_error(db_obj, "Not a valid callback function %s", callback_name);
    1006           1 :                 efree(callback_name);
    1007           1 :                 RETURN_FALSE;
    1008             :         }
    1009           2 :         efree(callback_name);
    1010             : 
    1011           2 :         func = (php_sqlite3_func *)ecalloc(1, sizeof(*func));
    1012             : 
    1013           2 :         if (sqlite3_create_function(db_obj->db, sql_func, sql_func_num_args, SQLITE_UTF8, func, NULL, php_sqlite3_callback_step, php_sqlite3_callback_final) == SQLITE_OK) {
    1014           2 :                 func->func_name = estrdup(sql_func);
    1015             : 
    1016           2 :                 MAKE_STD_ZVAL(func->step);
    1017           6 :                 MAKE_COPY_ZVAL(&step_callback, func->step);
    1018             : 
    1019           2 :                 MAKE_STD_ZVAL(func->fini);
    1020           6 :                 MAKE_COPY_ZVAL(&fini_callback, func->fini);
    1021             : 
    1022           2 :                 func->argc = sql_func_num_args;
    1023           2 :                 func->next = db_obj->funcs;
    1024           2 :                 db_obj->funcs = func;
    1025             : 
    1026           2 :                 RETURN_TRUE;
    1027             :         }
    1028           0 :         efree(func);
    1029             : 
    1030           0 :         RETURN_FALSE;
    1031             : }
    1032             : /* }}} */
    1033             : 
    1034             : /* {{{ proto bool SQLite3::createCollation(string name, mixed callback)
    1035             :    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()). */
    1036           1 : PHP_METHOD(sqlite3, createCollation)
    1037             : {
    1038             :         php_sqlite3_db_object *db_obj;
    1039           1 :         zval *object = getThis();
    1040             :         php_sqlite3_collation *collation;
    1041             :         char *collation_name, *callback_name;
    1042             :         int collation_name_len;
    1043             :         zval *callback_func;
    1044           1 :         db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC);
    1045             : 
    1046           1 :         SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)
    1047             : 
    1048           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &collation_name, &collation_name_len, &callback_func) == FAILURE) {
    1049           0 :                 RETURN_FALSE;
    1050             :         }
    1051             : 
    1052           1 :         if (!collation_name_len) {
    1053           0 :                 RETURN_FALSE;
    1054             :         }
    1055             : 
    1056           1 :         if (!zend_is_callable(callback_func, 0, &callback_name TSRMLS_CC)) {
    1057           0 :                 php_sqlite3_error(db_obj, "Not a valid callback function %s", callback_name);
    1058           0 :                 efree(callback_name);
    1059           0 :                 RETURN_FALSE;
    1060             :         }
    1061           1 :         efree(callback_name);
    1062             : 
    1063           1 :         collation = (php_sqlite3_collation *)ecalloc(1, sizeof(*collation));
    1064           1 :         if (sqlite3_create_collation(db_obj->db, collation_name, SQLITE_UTF8, collation, php_sqlite3_callback_compare) == SQLITE_OK) {
    1065           1 :                 collation->collation_name = estrdup(collation_name);
    1066             : 
    1067           1 :                 MAKE_STD_ZVAL(collation->cmp_func);
    1068           3 :                 MAKE_COPY_ZVAL(&callback_func, collation->cmp_func);
    1069             : 
    1070           1 :                 collation->next = db_obj->collations;
    1071           1 :                 db_obj->collations = collation;
    1072             : 
    1073           1 :                 RETURN_TRUE;
    1074             :         }
    1075           0 :         efree(collation);
    1076             : 
    1077           0 :         RETURN_FALSE;
    1078             : }
    1079             : /* }}} */
    1080             : 
    1081             : typedef struct {
    1082             :         sqlite3_blob *blob;
    1083             :         size_t           position;
    1084             :         size_t       size;
    1085             : } php_stream_sqlite3_data;
    1086             : 
    1087           0 : static size_t php_sqlite3_stream_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC)
    1088             : {
    1089             : /*      php_stream_sqlite3_data *sqlite3_stream = (php_stream_sqlite3_data *) stream->abstract; */
    1090             :         
    1091           0 :         return 0;
    1092             : }
    1093             : 
    1094           2 : static size_t php_sqlite3_stream_read(php_stream *stream, char *buf, size_t count TSRMLS_DC)
    1095             : {
    1096           2 :         php_stream_sqlite3_data *sqlite3_stream = (php_stream_sqlite3_data *) stream->abstract;
    1097             : 
    1098           2 :         if (sqlite3_stream->position + count >= sqlite3_stream->size) {
    1099           2 :                 count = sqlite3_stream->size - sqlite3_stream->position;
    1100           2 :                 stream->eof = 1;
    1101             :         }
    1102           2 :         if (count) {
    1103           1 :                 if (sqlite3_blob_read(sqlite3_stream->blob, buf, count, sqlite3_stream->position) != SQLITE_OK) {
    1104           0 :                         return 0;
    1105             :                 }
    1106           1 :                 sqlite3_stream->position += count;
    1107             :         }
    1108           2 :         return count;
    1109             : }
    1110             : 
    1111           1 : static int php_sqlite3_stream_close(php_stream *stream, int close_handle TSRMLS_DC)
    1112             : {
    1113           1 :         php_stream_sqlite3_data *sqlite3_stream = (php_stream_sqlite3_data *) stream->abstract;
    1114             :         
    1115           1 :         if (sqlite3_blob_close(sqlite3_stream->blob) != SQLITE_OK) {
    1116             :                 /* Error occurred, but it still closed */
    1117             :         }
    1118             : 
    1119           1 :         efree(sqlite3_stream);
    1120             :         
    1121           1 :         return 0;
    1122             : }
    1123             : 
    1124           1 : static int php_sqlite3_stream_flush(php_stream *stream TSRMLS_DC)
    1125             : {
    1126             :         /* do nothing */
    1127           1 :         return 0;
    1128             : }
    1129             : 
    1130             : /* {{{ */
    1131           0 : static int php_sqlite3_stream_seek(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC)
    1132             : {
    1133           0 :         php_stream_sqlite3_data *sqlite3_stream = (php_stream_sqlite3_data *) stream->abstract;
    1134             : 
    1135           0 :         switch(whence) {
    1136             :                 case SEEK_CUR:
    1137           0 :                         if (offset < 0) {
    1138           0 :                                 if (sqlite3_stream->position < (size_t)(-offset)) {
    1139           0 :                                         sqlite3_stream->position = 0;
    1140           0 :                                         *newoffs = -1;
    1141           0 :                                         return -1;
    1142             :                                 } else {
    1143           0 :                                         sqlite3_stream->position = sqlite3_stream->position + offset;
    1144           0 :                                         *newoffs = sqlite3_stream->position;
    1145           0 :                                         stream->eof = 0;
    1146           0 :                                         return 0;
    1147             :                                 }
    1148             :                         } else {
    1149           0 :                                 if (sqlite3_stream->position + (size_t)(offset) > sqlite3_stream->size) {
    1150           0 :                                         sqlite3_stream->position = sqlite3_stream->size;
    1151           0 :                                         *newoffs = -1;
    1152           0 :                                         return -1;
    1153             :                                 } else {
    1154           0 :                                         sqlite3_stream->position = sqlite3_stream->position + offset;
    1155           0 :                                         *newoffs = sqlite3_stream->position;
    1156           0 :                                         stream->eof = 0;
    1157           0 :                                         return 0;
    1158             :                                 }
    1159             :                         }
    1160             :                 case SEEK_SET:
    1161           0 :                         if (sqlite3_stream->size < (size_t)(offset)) {
    1162           0 :                                 sqlite3_stream->position = sqlite3_stream->size;
    1163           0 :                                 *newoffs = -1;
    1164           0 :                                 return -1;
    1165             :                         } else {
    1166           0 :                                 sqlite3_stream->position = offset;
    1167           0 :                                 *newoffs = sqlite3_stream->position;
    1168           0 :                                 stream->eof = 0;
    1169           0 :                                 return 0;
    1170             :                         }
    1171             :                 case SEEK_END:
    1172           0 :                         if (offset > 0) {
    1173           0 :                                 sqlite3_stream->position = sqlite3_stream->size;
    1174           0 :                                 *newoffs = -1;
    1175           0 :                                 return -1;
    1176           0 :                         } else if (sqlite3_stream->size < (size_t)(-offset)) {
    1177           0 :                                 sqlite3_stream->position = 0;
    1178           0 :                                 *newoffs = -1;
    1179           0 :                                 return -1;
    1180             :                         } else {
    1181           0 :                                 sqlite3_stream->position = sqlite3_stream->size + offset;
    1182           0 :                                 *newoffs = sqlite3_stream->position;
    1183           0 :                                 stream->eof = 0;
    1184           0 :                                 return 0;
    1185             :                         }
    1186             :                 default:
    1187           0 :                         *newoffs = sqlite3_stream->position;
    1188           0 :                         return -1;
    1189             :         }
    1190             : }
    1191             : /* }}} */
    1192             : 
    1193             : 
    1194           0 : static int php_sqlite3_stream_cast(php_stream *stream, int castas, void **ret TSRMLS_DC)
    1195             : {
    1196           0 :         return FAILURE;
    1197             : }
    1198             : 
    1199           1 : static int php_sqlite3_stream_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC)
    1200             : {
    1201           1 :         php_stream_sqlite3_data *sqlite3_stream = (php_stream_sqlite3_data *) stream->abstract;
    1202           1 :         ssb->sb.st_size = sqlite3_stream->size;
    1203           1 :         return 0;
    1204             : }
    1205             : 
    1206             : static php_stream_ops php_stream_sqlite3_ops = {
    1207             :         php_sqlite3_stream_write,
    1208             :         php_sqlite3_stream_read,
    1209             :         php_sqlite3_stream_close,
    1210             :         php_sqlite3_stream_flush,
    1211             :         "SQLite3",
    1212             :         php_sqlite3_stream_seek,
    1213             :         php_sqlite3_stream_cast,
    1214             :         php_sqlite3_stream_stat
    1215             : };
    1216             : 
    1217             : /* {{{ proto resource SQLite3::openBlob(string table, string column, int rowid [, string dbname])
    1218             :    Open a blob as a stream which we can read / write to. */
    1219           2 : PHP_METHOD(sqlite3, openBlob)
    1220             : {
    1221             :         php_sqlite3_db_object *db_obj;
    1222           2 :         zval *object = getThis();
    1223           2 :         char *table, *column, *dbname = "main";
    1224             :         int table_len, column_len, dbname_len;
    1225           2 :         long rowid, flags = 0;
    1226           2 :         sqlite3_blob *blob = NULL;
    1227             :         php_stream_sqlite3_data *sqlite3_stream;
    1228             :         php_stream *stream;
    1229             : 
    1230           2 :         db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC);
    1231             : 
    1232           2 :         SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)
    1233             : 
    1234           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssl|s", &table, &table_len, &column, &column_len, &rowid, &dbname, &dbname_len) == FAILURE) {
    1235           1 :                 return;
    1236             :         }
    1237             : 
    1238           1 :         if (sqlite3_blob_open(db_obj->db, dbname, table, column, rowid, flags, &blob) != SQLITE_OK) {
    1239           0 :                 php_sqlite3_error(db_obj, "Unable to open blob: %s", sqlite3_errmsg(db_obj->db));
    1240           0 :                 RETURN_FALSE;
    1241             :         }
    1242             : 
    1243           1 :         sqlite3_stream = emalloc(sizeof(php_stream_sqlite3_data));
    1244           1 :         sqlite3_stream->blob = blob;
    1245           1 :         sqlite3_stream->position = 0;
    1246           1 :         sqlite3_stream->size = sqlite3_blob_bytes(blob);
    1247             :         
    1248           1 :         stream = php_stream_alloc(&php_stream_sqlite3_ops, sqlite3_stream, 0, "rb");
    1249             : 
    1250           1 :         if (stream) {
    1251           1 :                 php_stream_to_zval(stream, return_value);
    1252             :         } else {
    1253           0 :                 RETURN_FALSE;
    1254             :         }
    1255             : }
    1256             : /* }}} */
    1257             : 
    1258             : /* {{{ proto bool SQLite3::enableExceptions([bool enableExceptions = false])
    1259             :    Enables an exception error mode. */
    1260           3 : PHP_METHOD(sqlite3, enableExceptions)
    1261             : {
    1262             :         php_sqlite3_db_object *db_obj;
    1263           3 :         zval *object = getThis();
    1264           3 :         zend_bool enableExceptions = 0;
    1265             : 
    1266           3 :         db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC);
    1267             : 
    1268           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &enableExceptions) == FAILURE) {
    1269           1 :                 return;
    1270             :         }
    1271             : 
    1272           2 :         RETVAL_BOOL(db_obj->exception);
    1273             : 
    1274           2 :         db_obj->exception = enableExceptions;
    1275             : }
    1276             : /* }}} */
    1277             : 
    1278             : /* {{{ proto int SQLite3Stmt::paramCount()
    1279             :    Returns the number of parameters within the prepared statement. */
    1280           5 : PHP_METHOD(sqlite3stmt, paramCount)
    1281             : {
    1282             :         php_sqlite3_stmt *stmt_obj;
    1283           5 :         zval *object = getThis();
    1284           5 :         stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
    1285             : 
    1286           5 :         if (zend_parse_parameters_none() == FAILURE) {
    1287           1 :                 return;
    1288             :         }
    1289             : 
    1290           4 :         SQLITE3_CHECK_INITIALIZED_STMT(stmt_obj->stmt, SQLite3Stmt);
    1291             : 
    1292           4 :         RETURN_LONG(sqlite3_bind_parameter_count(stmt_obj->stmt));
    1293             : }
    1294             : /* }}} */
    1295             : 
    1296             : /* {{{ proto bool SQLite3Stmt::close()
    1297             :    Closes the prepared statement. */
    1298           4 : PHP_METHOD(sqlite3stmt, close)
    1299             : {
    1300             :         php_sqlite3_stmt *stmt_obj;
    1301           4 :         zval *object = getThis();
    1302           4 :         stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
    1303             : 
    1304           4 :         if (zend_parse_parameters_none() == FAILURE) {
    1305           0 :                 return;
    1306             :         }
    1307             : 
    1308           4 :         if(stmt_obj->db_obj) {
    1309           4 :                 zend_llist_del_element(&(stmt_obj->db_obj->free_list), object, (int (*)(void *, void *)) php_sqlite3_compare_stmt_zval_free);
    1310             :         }
    1311             : 
    1312           4 :         RETURN_TRUE;
    1313             : }
    1314             : /* }}} */
    1315             : 
    1316             : /* {{{ proto bool SQLite3Stmt::reset()
    1317             :    Reset the prepared statement to the state before it was executed, bindings still remain. */
    1318           5 : PHP_METHOD(sqlite3stmt, reset)
    1319             : {
    1320             :         php_sqlite3_stmt *stmt_obj;
    1321           5 :         zval *object = getThis();
    1322           5 :         stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
    1323             : 
    1324           5 :         if (zend_parse_parameters_none() == FAILURE) {
    1325           2 :                 return;
    1326             :         }
    1327             : 
    1328           3 :         SQLITE3_CHECK_INITIALIZED_STMT(stmt_obj->stmt, SQLite3Stmt);
    1329             : 
    1330           3 :         if (sqlite3_reset(stmt_obj->stmt) != SQLITE_OK) {
    1331           0 :                 php_sqlite3_error(stmt_obj->db_obj, "Unable to reset statement: %s", sqlite3_errmsg(sqlite3_db_handle(stmt_obj->stmt)));
    1332           0 :                 RETURN_FALSE;
    1333             :         }
    1334           3 :         RETURN_TRUE;
    1335             : }
    1336             : /* }}} */
    1337             : 
    1338             : /* {{{ proto bool SQLite3Stmt::clear()
    1339             :    Clear all current bound parameters. */
    1340           2 : PHP_METHOD(sqlite3stmt, clear)
    1341             : {
    1342             :         php_sqlite3_stmt *stmt_obj;
    1343           2 :         zval *object = getThis();
    1344           2 :         stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
    1345             : 
    1346           2 :         if (zend_parse_parameters_none() == FAILURE) {
    1347           1 :                 return;
    1348             :         }
    1349             : 
    1350           1 :         SQLITE3_CHECK_INITIALIZED_STMT(stmt_obj->stmt, SQLite3Stmt);
    1351             : 
    1352           1 :         if (sqlite3_clear_bindings(stmt_obj->stmt) != SQLITE_OK) {
    1353           0 :                 php_sqlite3_error(stmt_obj->db_obj, "Unable to clear statement: %s", sqlite3_errmsg(sqlite3_db_handle(stmt_obj->stmt)));
    1354           0 :                 RETURN_FALSE;
    1355             :         }
    1356             : 
    1357           1 :         RETURN_TRUE;
    1358             : }
    1359             : /* }}} */
    1360             : 
    1361             : /* {{{ proto bool SQLite3Stmt::readOnly()
    1362             :    Returns true if a statement is definitely read only */
    1363           3 : PHP_METHOD(sqlite3stmt, readOnly)
    1364             : {
    1365             :         php_sqlite3_stmt *stmt_obj;
    1366           3 :         zval *object = getThis();
    1367           3 :         stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
    1368             : 
    1369           3 :         if (zend_parse_parameters_none() == FAILURE) {
    1370           0 :                 return;
    1371             :         }
    1372             : 
    1373           3 :         SQLITE3_CHECK_INITIALIZED_STMT(stmt_obj->stmt, SQLite3Stmt);
    1374             : 
    1375             : #if SQLITE_VERSION_NUMBER >= 3007004
    1376           3 :         if (sqlite3_stmt_readonly(stmt_obj->stmt)) {
    1377           1 :                 RETURN_TRUE;
    1378             :         }
    1379             : #endif
    1380           2 :         RETURN_FALSE;
    1381             : }
    1382             : /* }}} */
    1383             : 
    1384          21 : static int register_bound_parameter_to_sqlite(struct php_sqlite3_bound_param *param, php_sqlite3_stmt *stmt TSRMLS_DC) /* {{{ */
    1385             : {
    1386             :         HashTable *hash;
    1387          21 :         hash = stmt->bound_params;
    1388             : 
    1389          21 :         if (!hash) {
    1390          13 :                 ALLOC_HASHTABLE(hash);
    1391          13 :                 zend_hash_init(hash, 13, NULL, sqlite3_param_dtor, 0);
    1392          13 :                 stmt->bound_params = hash;
    1393             :         }
    1394             : 
    1395             :         /* We need a : prefix to resolve a name to a parameter number */
    1396          21 :         if (param->name) {
    1397           5 :                 if (param->name[0] != ':') {
    1398             :                         /* pre-increment for character + 1 for null */
    1399           1 :                         char *temp = emalloc(++param->name_len + 1);
    1400           1 :                         temp[0] = ':';
    1401           1 :                         memmove(temp+1, param->name, param->name_len);
    1402           1 :                         param->name = temp;
    1403             :                 } else {
    1404           4 :                         param->name = estrndup(param->name, param->name_len);
    1405             :                 }
    1406             :                 /* do lookup*/
    1407           5 :                 param->param_number = sqlite3_bind_parameter_index(stmt->stmt, param->name);
    1408             :         }
    1409             : 
    1410          21 :         if (param->param_number < 1) {
    1411           0 :                 efree(param->name);
    1412           0 :                 return 0;
    1413             :         }
    1414             : 
    1415          21 :         if (param->param_number >= 1) {
    1416          21 :                 zend_hash_index_del(hash, param->param_number);
    1417             :         }
    1418             : 
    1419          21 :         if (param->name) {
    1420           5 :                 zend_hash_update(hash, param->name, param->name_len, param, sizeof(*param), NULL);
    1421             :         } else {
    1422          16 :                 zend_hash_index_update(hash, param->param_number, param, sizeof(*param), NULL);
    1423             :         }
    1424             : 
    1425          21 :         return 1;
    1426             : }
    1427             : /* }}} */
    1428             : 
    1429             : /* {{{ proto bool SQLite3Stmt::bindParam(int parameter_number, mixed parameter [, int type])
    1430             :    Bind Parameter to a stmt variable. */
    1431           9 : PHP_METHOD(sqlite3stmt, bindParam)
    1432             : {
    1433             :         php_sqlite3_stmt *stmt_obj;
    1434           9 :         zval *object = getThis();
    1435           9 :         struct php_sqlite3_bound_param param = {0};
    1436           9 :         stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
    1437             : 
    1438           9 :         param.param_number = -1;
    1439           9 :         param.type = SQLITE3_TEXT;
    1440             : 
    1441           9 :         if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "lz|l", &param.param_number, &param.parameter, &param.type) == FAILURE) {
    1442           0 :                 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|l", &param.name, &param.name_len, &param.parameter, &param.type) == FAILURE) {
    1443           0 :                         return;
    1444             :                 }
    1445             :         }
    1446             : 
    1447           9 :         SQLITE3_CHECK_INITIALIZED_STMT(stmt_obj->stmt, SQLite3Stmt);
    1448             : 
    1449           9 :         Z_ADDREF_P(param.parameter);
    1450             : 
    1451           9 :         if (!register_bound_parameter_to_sqlite(&param, stmt_obj TSRMLS_CC)) {
    1452           0 :                 if (param.parameter) {
    1453           0 :                         zval_ptr_dtor(&(param.parameter));
    1454           0 :                         param.parameter = NULL;
    1455             :                 }
    1456           0 :                 RETURN_FALSE;
    1457             :         }
    1458           9 :         RETURN_TRUE;
    1459             : }
    1460             : /* }}} */
    1461             : 
    1462             : /* {{{ proto bool SQLite3Stmt::bindValue(int parameter_number, mixed parameter [, int type])
    1463             :    Bind Value of a parameter to a stmt variable. */
    1464          12 : PHP_METHOD(sqlite3stmt, bindValue)
    1465             : {
    1466             :         php_sqlite3_stmt *stmt_obj;
    1467          12 :         zval *object = getThis();
    1468          12 :         struct php_sqlite3_bound_param param = {0};
    1469          12 :         stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
    1470             : 
    1471          12 :         param.param_number = -1;
    1472          12 :         param.type = SQLITE3_TEXT;
    1473             : 
    1474          12 :         if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "lz/|l", &param.param_number, &param.parameter, &param.type) == FAILURE) {
    1475           5 :                 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz/|l", &param.name, &param.name_len, &param.parameter, &param.type) == FAILURE) {
    1476           0 :                         return;
    1477             :                 }
    1478             :         }
    1479             : 
    1480          12 :         SQLITE3_CHECK_INITIALIZED_STMT(stmt_obj->stmt, SQLite3Stmt);
    1481             : 
    1482          12 :         Z_ADDREF_P(param.parameter);
    1483             : 
    1484          12 :         if (!register_bound_parameter_to_sqlite(&param, stmt_obj TSRMLS_CC)) {
    1485           0 :                 if (param.parameter) {
    1486           0 :                         zval_ptr_dtor(&(param.parameter));
    1487           0 :                         param.parameter = NULL;
    1488             :                 }
    1489           0 :                 RETURN_FALSE;
    1490             :         }
    1491          12 :         RETURN_TRUE;
    1492             : }
    1493             : /* }}} */
    1494             : 
    1495             : /* {{{ proto SQLite3Result SQLite3Stmt::execute()
    1496             :    Executes a prepared statement and returns a result set object. */
    1497          20 : PHP_METHOD(sqlite3stmt, execute)
    1498             : {
    1499             :         php_sqlite3_stmt *stmt_obj;
    1500             :         php_sqlite3_result *result;
    1501          20 :         zval *object = getThis();
    1502          20 :         int return_code = 0;
    1503             :         struct php_sqlite3_bound_param *param;
    1504             : 
    1505          20 :         stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
    1506             : 
    1507          20 :         if (zend_parse_parameters_none() == FAILURE) {
    1508           0 :                 return;
    1509             :         }
    1510             : 
    1511          20 :         SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3)
    1512             : 
    1513          20 :         if (stmt_obj->bound_params) {
    1514          15 :                 zend_hash_internal_pointer_reset(stmt_obj->bound_params);
    1515          49 :                 while (zend_hash_get_current_data(stmt_obj->bound_params, (void **)&param) == SUCCESS) {
    1516             :                         /* If the ZVAL is null then it should be bound as that */
    1517          19 :                         if (Z_TYPE_P(param->parameter) == IS_NULL) {
    1518           1 :                                 sqlite3_bind_null(stmt_obj->stmt, param->param_number);
    1519           1 :                                 zend_hash_move_forward(stmt_obj->bound_params);
    1520           1 :                                 continue;
    1521             :                         }
    1522             : 
    1523          18 :                         switch (param->type) {
    1524             :                                 case SQLITE_INTEGER:
    1525           2 :                                         convert_to_long(param->parameter);
    1526             : #if LONG_MAX > 2147483647
    1527           2 :                                         sqlite3_bind_int64(stmt_obj->stmt, param->param_number, Z_LVAL_P(param->parameter));
    1528             : #else
    1529             :                                         sqlite3_bind_int(stmt_obj->stmt, param->param_number, Z_LVAL_P(param->parameter));
    1530             : #endif
    1531           2 :                                         break;
    1532             : 
    1533             :                                 case SQLITE_FLOAT:
    1534             :                                         /* convert_to_double(param->parameter);*/
    1535           0 :                                         sqlite3_bind_double(stmt_obj->stmt, param->param_number, Z_DVAL_P(param->parameter));
    1536           0 :                                         break;
    1537             : 
    1538             :                                 case SQLITE_BLOB:
    1539             :                                 {
    1540           3 :                                         php_stream *stream = NULL;
    1541             :                                         int blength;
    1542           3 :                                         char *buffer = NULL;
    1543           3 :                                         if (Z_TYPE_P(param->parameter) == IS_RESOURCE) {
    1544           1 :                                                 php_stream_from_zval_no_verify(stream, &param->parameter);
    1545           1 :                                                 if (stream == NULL) {
    1546           0 :                                                         php_sqlite3_error(stmt_obj->db_obj, "Unable to read stream for parameter %ld", param->param_number);
    1547           0 :                                                         RETURN_FALSE;
    1548             :                                                 }
    1549           1 :                                                 blength = php_stream_copy_to_mem(stream, (void *)&buffer, PHP_STREAM_COPY_ALL, 0);
    1550             :                                         } else {
    1551           2 :                                                 convert_to_string(param->parameter);
    1552           2 :                                                 blength =  Z_STRLEN_P(param->parameter);
    1553           2 :                                                 buffer = Z_STRVAL_P(param->parameter);
    1554             :                                         }
    1555             : 
    1556           3 :                                         sqlite3_bind_blob(stmt_obj->stmt, param->param_number, buffer, blength, SQLITE_TRANSIENT);
    1557             : 
    1558           3 :                                         if (stream) {
    1559           1 :                                                 pefree(buffer, 0);
    1560             :                                         }
    1561           3 :                                         break;
    1562             :                                 }
    1563             : 
    1564             :                                 case SQLITE3_TEXT:
    1565          13 :                                         convert_to_string(param->parameter);
    1566          13 :                                         sqlite3_bind_text(stmt_obj->stmt, param->param_number, Z_STRVAL_P(param->parameter), Z_STRLEN_P(param->parameter), SQLITE_STATIC);
    1567          13 :                                         break;
    1568             : 
    1569             :                                 case SQLITE_NULL:
    1570           0 :                                         sqlite3_bind_null(stmt_obj->stmt, param->param_number);
    1571           0 :                                         break;
    1572             : 
    1573             :                                 default:
    1574           0 :                                         php_sqlite3_error(stmt_obj->db_obj, "Unknown parameter type: %ld for parameter %ld", param->type, param->param_number);
    1575           0 :                                         RETURN_FALSE;
    1576             :                         }
    1577          18 :                         zend_hash_move_forward(stmt_obj->bound_params);
    1578             :                 }
    1579             :         }
    1580             : 
    1581          20 :         return_code = sqlite3_step(stmt_obj->stmt);
    1582             : 
    1583          20 :         switch (return_code) {
    1584             :                 case SQLITE_ROW: /* Valid Row */
    1585             :                 case SQLITE_DONE: /* Valid but no results */
    1586             :                 {
    1587          20 :                         sqlite3_reset(stmt_obj->stmt);
    1588          20 :                         object_init_ex(return_value, php_sqlite3_result_entry);
    1589          20 :                         result = (php_sqlite3_result *)zend_object_store_get_object(return_value TSRMLS_CC);
    1590             : 
    1591             :                         Z_ADDREF_P(object);
    1592             :         
    1593          20 :                         result->is_prepared_statement = 1;
    1594          20 :                         result->db_obj = stmt_obj->db_obj;
    1595          20 :                         result->stmt_obj = stmt_obj;
    1596          20 :                         result->stmt_obj_zval = getThis();
    1597             : 
    1598          20 :                         break;
    1599             :                 }
    1600             :                 case SQLITE_ERROR:
    1601           0 :                         sqlite3_reset(stmt_obj->stmt);
    1602             : 
    1603             :                 default:
    1604           0 :                         php_sqlite3_error(stmt_obj->db_obj, "Unable to execute statement: %s", sqlite3_errmsg(sqlite3_db_handle(stmt_obj->stmt)));
    1605             :                         zval_dtor(return_value);
    1606           0 :                         RETURN_FALSE;
    1607             :         }
    1608             : 
    1609          20 :         return;
    1610             : }
    1611             : /* }}} */
    1612             : 
    1613             : /* {{{ proto int SQLite3Stmt::__construct(SQLite3 dbobject, String Statement)
    1614             :    __constructor for SQLite3Stmt. */
    1615           0 : PHP_METHOD(sqlite3stmt, __construct)
    1616             : {
    1617             :         php_sqlite3_stmt *stmt_obj;
    1618             :         php_sqlite3_db_object *db_obj;
    1619           0 :         zval *object = getThis();
    1620             :         zval *db_zval;
    1621             :         char *sql;
    1622             :         int sql_len, errcode;
    1623             :         zend_error_handling error_handling;
    1624             :         php_sqlite3_free_list *free_item;
    1625             : 
    1626           0 :         stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
    1627           0 :         zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC);
    1628             : 
    1629           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os", &db_zval, php_sqlite3_sc_entry, &sql, &sql_len) == FAILURE) {
    1630           0 :                 zend_restore_error_handling(&error_handling TSRMLS_CC);
    1631           0 :                 return;
    1632             :         }
    1633             : 
    1634           0 :         db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(db_zval TSRMLS_CC);
    1635             : 
    1636           0 :         SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)
    1637             : 
    1638           0 :         zend_restore_error_handling(&error_handling TSRMLS_CC);
    1639             : 
    1640           0 :         if (!sql_len) {
    1641           0 :                 RETURN_FALSE;
    1642             :         }
    1643             : 
    1644           0 :         stmt_obj->db_obj = db_obj;
    1645           0 :         stmt_obj->db_obj_zval = db_zval;
    1646             : 
    1647           0 :         Z_ADDREF_P(db_zval);
    1648             :         
    1649           0 :         errcode = sqlite3_prepare_v2(db_obj->db, sql, sql_len, &(stmt_obj->stmt), NULL);
    1650           0 :         if (errcode != SQLITE_OK) {
    1651           0 :                 php_sqlite3_error(db_obj, "Unable to prepare statement: %d, %s", errcode, sqlite3_errmsg(db_obj->db));
    1652             :                 zval_dtor(return_value);
    1653           0 :                 RETURN_FALSE;
    1654             :         }
    1655           0 :         stmt_obj->initialised = 1;
    1656             : 
    1657           0 :         free_item = emalloc(sizeof(php_sqlite3_free_list));
    1658           0 :         free_item->stmt_obj = stmt_obj;
    1659           0 :         free_item->stmt_obj_zval = getThis();
    1660             : 
    1661           0 :         zend_llist_add_element(&(db_obj->free_list), &free_item);
    1662             : }
    1663             : /* }}} */
    1664             : 
    1665             : /* {{{ proto int SQLite3Result::numColumns()
    1666             :    Number of columns in the result set. */
    1667           4 : PHP_METHOD(sqlite3result, numColumns)
    1668             : {
    1669             :         php_sqlite3_result *result_obj;
    1670           4 :         zval *object = getThis();
    1671           4 :         result_obj = (php_sqlite3_result *)zend_object_store_get_object(object TSRMLS_CC);
    1672             : 
    1673           4 :         SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result)
    1674             : 
    1675           3 :         if (zend_parse_parameters_none() == FAILURE) {
    1676           1 :                 return;
    1677             :         }
    1678             : 
    1679           2 :         RETURN_LONG(sqlite3_column_count(result_obj->stmt_obj->stmt));
    1680             : }
    1681             : /* }}} */
    1682             : 
    1683             : /* {{{ proto string SQLite3Result::columnName(int column)
    1684             :    Returns the name of the nth column. */
    1685           6 : PHP_METHOD(sqlite3result, columnName)
    1686             : {
    1687             :         php_sqlite3_result *result_obj;
    1688           6 :         zval *object = getThis();
    1689           6 :         long column = 0;
    1690             :         char *column_name;
    1691           6 :         result_obj = (php_sqlite3_result *)zend_object_store_get_object(object TSRMLS_CC);
    1692             : 
    1693           6 :         SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result)
    1694             : 
    1695           6 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &column) == FAILURE) {
    1696           0 :                 return;
    1697             :         }
    1698           6 :         column_name = (char*) sqlite3_column_name(result_obj->stmt_obj->stmt, column);
    1699             : 
    1700           6 :         if (column_name == NULL) {
    1701           1 :                 RETURN_FALSE;
    1702             :         }
    1703             :                 
    1704           5 :         RETVAL_STRING(column_name, 1);
    1705             : }
    1706             : /* }}} */
    1707             : 
    1708             : /* {{{ proto int SQLite3Result::columnType(int column)
    1709             :    Returns the type of the nth column. */
    1710           4 : PHP_METHOD(sqlite3result, columnType)
    1711             : {
    1712             :         php_sqlite3_result *result_obj;
    1713           4 :         zval *object = getThis();
    1714           4 :         long column = 0;
    1715           4 :         result_obj = (php_sqlite3_result *)zend_object_store_get_object(object TSRMLS_CC);
    1716             : 
    1717           4 :         SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result)
    1718             : 
    1719           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &column) == FAILURE) {
    1720           0 :                 return;
    1721             :         }
    1722             : 
    1723           4 :         if (result_obj->complete) {
    1724           0 :                 RETURN_FALSE;
    1725             :         }
    1726             : 
    1727           4 :         RETURN_LONG(sqlite3_column_type(result_obj->stmt_obj->stmt, column));
    1728             : }
    1729             : /* }}} */
    1730             : 
    1731             : /* {{{ proto array SQLite3Result::fetchArray([int mode])
    1732             :    Fetch a result row as both an associative or numerically indexed array or both. */
    1733          61 : PHP_METHOD(sqlite3result, fetchArray)
    1734             : {
    1735             :         php_sqlite3_result *result_obj;
    1736          61 :         zval *object = getThis();
    1737             :         int i, ret;
    1738          61 :         long mode = PHP_SQLITE3_BOTH;
    1739          61 :         result_obj = (php_sqlite3_result *)zend_object_store_get_object(object TSRMLS_CC);
    1740             : 
    1741          61 :         SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result)
    1742             : 
    1743          61 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &mode) == FAILURE) {
    1744           1 :                 return;
    1745             :         }
    1746             : 
    1747          60 :         ret = sqlite3_step(result_obj->stmt_obj->stmt);
    1748          60 :         switch (ret) {
    1749             :                 case SQLITE_ROW:
    1750             :                         /* If there was no return value then just skip fetching */
    1751          36 :                         if (!return_value_used) {
    1752           0 :                                 return;
    1753             :                         }
    1754             : 
    1755          36 :                         array_init(return_value);
    1756             : 
    1757          98 :                         for (i = 0; i < sqlite3_data_count(result_obj->stmt_obj->stmt); i++) {
    1758             :                                 zval *data;
    1759             : 
    1760          62 :                                 data = sqlite_value_to_zval(result_obj->stmt_obj->stmt, i);
    1761             : 
    1762          62 :                                 if (mode & PHP_SQLITE3_NUM) {
    1763          62 :                                         add_index_zval(return_value, i, data);
    1764             :                                 }
    1765             : 
    1766          62 :                                 if (mode & PHP_SQLITE3_ASSOC) {
    1767           7 :                                         if (mode & PHP_SQLITE3_NUM) {
    1768             :                                                 Z_ADDREF_P(data);
    1769             :                                         }
    1770           7 :                                         add_assoc_zval(return_value, (char*)sqlite3_column_name(result_obj->stmt_obj->stmt, i), data);
    1771             :                                 }
    1772             :                         }
    1773          36 :                         break;
    1774             : 
    1775             :                 case SQLITE_DONE:
    1776          24 :                         result_obj->complete = 1;
    1777          24 :                         RETURN_FALSE;
    1778             :                         break;
    1779             : 
    1780             :                 default:
    1781           0 :                         php_sqlite3_error(result_obj->db_obj, "Unable to execute statement: %s", sqlite3_errmsg(sqlite3_db_handle(result_obj->stmt_obj->stmt)));
    1782             :         }
    1783             : }
    1784             : /* }}} */
    1785             : 
    1786             : /* {{{ proto bool SQLite3Result::reset()
    1787             :    Resets the result set back to the first row. */
    1788           2 : PHP_METHOD(sqlite3result, reset)
    1789             : {
    1790             :         php_sqlite3_result *result_obj;
    1791           2 :         zval *object = getThis();
    1792           2 :         result_obj = (php_sqlite3_result *)zend_object_store_get_object(object TSRMLS_CC);
    1793             : 
    1794           2 :         SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result)
    1795             : 
    1796           2 :         if (zend_parse_parameters_none() == FAILURE) {
    1797           1 :                 return;
    1798             :         }
    1799             : 
    1800           1 :         if (sqlite3_reset(result_obj->stmt_obj->stmt) != SQLITE_OK) {
    1801           0 :                 RETURN_FALSE;
    1802             :         }
    1803             : 
    1804           1 :         result_obj->complete = 0;
    1805             : 
    1806           1 :         RETURN_TRUE;
    1807             : }
    1808             : /* }}} */
    1809             : 
    1810             : /* {{{ proto bool SQLite3Result::finalize()
    1811             :    Closes the result set. */
    1812          18 : PHP_METHOD(sqlite3result, finalize)
    1813             : {
    1814             :         php_sqlite3_result *result_obj;
    1815          18 :         zval *object = getThis();
    1816          18 :         result_obj = (php_sqlite3_result *)zend_object_store_get_object(object TSRMLS_CC);
    1817             : 
    1818          18 :         SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result)
    1819             : 
    1820          18 :         if (zend_parse_parameters_none() == FAILURE) {
    1821           0 :                 return;
    1822             :         }
    1823             : 
    1824             :         /* We need to finalize an internal statement */
    1825          18 :         if (result_obj->is_prepared_statement == 0) {
    1826          11 :                 zend_llist_del_element(&(result_obj->db_obj->free_list), result_obj->stmt_obj_zval,
    1827             :                         (int (*)(void *, void *)) php_sqlite3_compare_stmt_zval_free);
    1828             :         } else {
    1829           7 :                 sqlite3_reset(result_obj->stmt_obj->stmt);
    1830             :         }
    1831             : 
    1832          18 :         RETURN_TRUE;
    1833             : }
    1834             : /* }}} */
    1835             : 
    1836             : /* {{{ proto int SQLite3Result::__construct()
    1837             :    __constructor for SQLite3Result. */
    1838           0 : PHP_METHOD(sqlite3result, __construct)
    1839             : {
    1840           0 :         zend_throw_exception(zend_exception_get_default(TSRMLS_C), "SQLite3Result cannot be directly instantiated", 0 TSRMLS_CC);
    1841           0 : }
    1842             : /* }}} */
    1843             : 
    1844             : /* {{{ arginfo */
    1845             : ZEND_BEGIN_ARG_INFO(arginfo_sqlite3_open, 0)
    1846             :         ZEND_ARG_INFO(0, filename)
    1847             :         ZEND_ARG_INFO(0, flags)
    1848             :         ZEND_ARG_INFO(0, encryption_key)
    1849             : ZEND_END_ARG_INFO()
    1850             : 
    1851             : ZEND_BEGIN_ARG_INFO(arginfo_sqlite3_busytimeout, 0)
    1852             :         ZEND_ARG_INFO(0, ms)
    1853             : ZEND_END_ARG_INFO()
    1854             : 
    1855             : #ifndef SQLITE_OMIT_LOAD_EXTENSION
    1856             : ZEND_BEGIN_ARG_INFO(arginfo_sqlite3_loadextension, 0)
    1857             :         ZEND_ARG_INFO(0, shared_library)
    1858             : ZEND_END_ARG_INFO()
    1859             : #endif
    1860             : 
    1861             : ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3_escapestring, 0, 0, 1)
    1862             :         ZEND_ARG_INFO(0, value)
    1863             : ZEND_END_ARG_INFO()
    1864             : 
    1865             : ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3_query, 0, 0, 1)
    1866             :         ZEND_ARG_INFO(0, query)
    1867             : ZEND_END_ARG_INFO()
    1868             : 
    1869             : ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3_querysingle, 0, 0, 1)
    1870             :         ZEND_ARG_INFO(0, query)
    1871             :         ZEND_ARG_INFO(0, entire_row)
    1872             : ZEND_END_ARG_INFO()
    1873             : 
    1874             : ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3_createfunction, 0, 0, 2)
    1875             :         ZEND_ARG_INFO(0, name)
    1876             :         ZEND_ARG_INFO(0, callback)
    1877             :         ZEND_ARG_INFO(0, argument_count)
    1878             : ZEND_END_ARG_INFO()
    1879             : 
    1880             : ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3_createaggregate, 0, 0, 3)
    1881             :         ZEND_ARG_INFO(0, name)
    1882             :         ZEND_ARG_INFO(0, step_callback)
    1883             :         ZEND_ARG_INFO(0, final_callback)
    1884             :         ZEND_ARG_INFO(0, argument_count)
    1885             : ZEND_END_ARG_INFO()
    1886             : 
    1887             : ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3_createcollation, 0, 0, 2)
    1888             :         ZEND_ARG_INFO(0, name)
    1889             :         ZEND_ARG_INFO(0, callback)
    1890             : ZEND_END_ARG_INFO()
    1891             : 
    1892             : ZEND_BEGIN_ARG_INFO_EX(argingo_sqlite3_openblob, 0, 0, 3)
    1893             :         ZEND_ARG_INFO(0, table)
    1894             :         ZEND_ARG_INFO(0, column)
    1895             :         ZEND_ARG_INFO(0, rowid)
    1896             :         ZEND_ARG_INFO(0, dbname)
    1897             : ZEND_END_ARG_INFO()
    1898             : 
    1899             : ZEND_BEGIN_ARG_INFO_EX(argingo_sqlite3_enableexceptions, 0, 0, 1)
    1900             :         ZEND_ARG_INFO(0, enableExceptions)
    1901             : ZEND_END_ARG_INFO()
    1902             : 
    1903             : ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3stmt_bindparam, 0, 0, 2)
    1904             :         ZEND_ARG_INFO(0, param_number)
    1905             :         ZEND_ARG_INFO(1, param)
    1906             :         ZEND_ARG_INFO(0, type)
    1907             : ZEND_END_ARG_INFO()
    1908             : 
    1909             : ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3stmt_bindvalue, 0, 0, 2)
    1910             :         ZEND_ARG_INFO(0, param_number)
    1911             :         ZEND_ARG_INFO(0, param)
    1912             :         ZEND_ARG_INFO(0, type)
    1913             : ZEND_END_ARG_INFO()
    1914             : 
    1915             : ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3stmt_construct, 0, 0, 1)
    1916             :         ZEND_ARG_INFO(0, sqlite3)
    1917             : ZEND_END_ARG_INFO()
    1918             : 
    1919             : ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3result_columnname, 0, 0, 1)
    1920             :         ZEND_ARG_INFO(0, column_number)
    1921             : ZEND_END_ARG_INFO()
    1922             : 
    1923             : ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3result_columntype, 0, 0, 1)
    1924             :         ZEND_ARG_INFO(0, column_number)
    1925             : ZEND_END_ARG_INFO()
    1926             : 
    1927             : ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3result_fetcharray, 0, 0, 1)
    1928             :         ZEND_ARG_INFO(0, mode)
    1929             : ZEND_END_ARG_INFO()
    1930             : 
    1931             : ZEND_BEGIN_ARG_INFO(arginfo_sqlite3_void, 0)
    1932             : ZEND_END_ARG_INFO()
    1933             : /* }}} */
    1934             : 
    1935             : /* {{{ php_sqlite3_class_methods */
    1936             : static zend_function_entry php_sqlite3_class_methods[] = {
    1937             :         PHP_ME(sqlite3,         open,                           arginfo_sqlite3_open, ZEND_ACC_PUBLIC)
    1938             :         PHP_ME(sqlite3,         close,                          arginfo_sqlite3_void, ZEND_ACC_PUBLIC)
    1939             :         PHP_ME(sqlite3,         exec,                           arginfo_sqlite3_query, ZEND_ACC_PUBLIC)
    1940             :         PHP_ME(sqlite3,         version,                        arginfo_sqlite3_void, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
    1941             :         PHP_ME(sqlite3,         lastInsertRowID,        arginfo_sqlite3_void, ZEND_ACC_PUBLIC)
    1942             :         PHP_ME(sqlite3,         lastErrorCode,          arginfo_sqlite3_void, ZEND_ACC_PUBLIC)
    1943             :         PHP_ME(sqlite3,         lastErrorMsg,           arginfo_sqlite3_void, ZEND_ACC_PUBLIC)
    1944             :         PHP_ME(sqlite3,         busyTimeout,            arginfo_sqlite3_busytimeout, ZEND_ACC_PUBLIC)
    1945             : #ifndef SQLITE_OMIT_LOAD_EXTENSION
    1946             :         PHP_ME(sqlite3,         loadExtension,          arginfo_sqlite3_loadextension, ZEND_ACC_PUBLIC)
    1947             : #endif
    1948             :         PHP_ME(sqlite3,         changes,                        arginfo_sqlite3_void, ZEND_ACC_PUBLIC)
    1949             :         PHP_ME(sqlite3,         escapeString,           arginfo_sqlite3_escapestring, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
    1950             :         PHP_ME(sqlite3,         prepare,                        arginfo_sqlite3_query, ZEND_ACC_PUBLIC)
    1951             :         PHP_ME(sqlite3,         query,                          arginfo_sqlite3_query, ZEND_ACC_PUBLIC)
    1952             :         PHP_ME(sqlite3,         querySingle,            arginfo_sqlite3_querysingle, ZEND_ACC_PUBLIC)
    1953             :         PHP_ME(sqlite3,         createFunction,         arginfo_sqlite3_createfunction, ZEND_ACC_PUBLIC)
    1954             :         PHP_ME(sqlite3,         createAggregate,        arginfo_sqlite3_createaggregate, ZEND_ACC_PUBLIC)
    1955             :         PHP_ME(sqlite3,         createCollation,        arginfo_sqlite3_createcollation, ZEND_ACC_PUBLIC)
    1956             :         PHP_ME(sqlite3,         openBlob,                       argingo_sqlite3_openblob, ZEND_ACC_PUBLIC)
    1957             :         PHP_ME(sqlite3,         enableExceptions,       argingo_sqlite3_enableexceptions, ZEND_ACC_PUBLIC)
    1958             :         /* Aliases */
    1959             :         PHP_MALIAS(sqlite3,     __construct, open, arginfo_sqlite3_open, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
    1960             :         PHP_FE_END
    1961             : };
    1962             : /* }}} */
    1963             : 
    1964             : /* {{{ php_sqlite3_stmt_class_methods */
    1965             : static zend_function_entry php_sqlite3_stmt_class_methods[] = {
    1966             :         PHP_ME(sqlite3stmt, paramCount, arginfo_sqlite3_void, ZEND_ACC_PUBLIC)
    1967             :         PHP_ME(sqlite3stmt, close,              arginfo_sqlite3_void, ZEND_ACC_PUBLIC)
    1968             :         PHP_ME(sqlite3stmt, reset,              arginfo_sqlite3_void, ZEND_ACC_PUBLIC)
    1969             :         PHP_ME(sqlite3stmt, clear,              arginfo_sqlite3_void, ZEND_ACC_PUBLIC)
    1970             :         PHP_ME(sqlite3stmt, execute,    arginfo_sqlite3_void, ZEND_ACC_PUBLIC)
    1971             :         PHP_ME(sqlite3stmt, bindParam,  arginfo_sqlite3stmt_bindparam, ZEND_ACC_PUBLIC)
    1972             :         PHP_ME(sqlite3stmt, bindValue,  arginfo_sqlite3stmt_bindvalue, ZEND_ACC_PUBLIC)
    1973             :         PHP_ME(sqlite3stmt, readOnly,   arginfo_sqlite3_void, ZEND_ACC_PUBLIC)
    1974             :         PHP_ME(sqlite3stmt, __construct, arginfo_sqlite3stmt_construct, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR)
    1975             :         PHP_FE_END
    1976             : };
    1977             : /* }}} */
    1978             : 
    1979             : /* {{{ php_sqlite3_result_class_methods */
    1980             : static zend_function_entry php_sqlite3_result_class_methods[] = {
    1981             :         PHP_ME(sqlite3result, numColumns,               arginfo_sqlite3_void, ZEND_ACC_PUBLIC)
    1982             :         PHP_ME(sqlite3result, columnName,               arginfo_sqlite3result_columnname, ZEND_ACC_PUBLIC)
    1983             :         PHP_ME(sqlite3result, columnType,               arginfo_sqlite3result_columntype, ZEND_ACC_PUBLIC)
    1984             :         PHP_ME(sqlite3result, fetchArray,               arginfo_sqlite3result_fetcharray, ZEND_ACC_PUBLIC)
    1985             :         PHP_ME(sqlite3result, reset,                    arginfo_sqlite3_void, ZEND_ACC_PUBLIC)
    1986             :         PHP_ME(sqlite3result, finalize,                 arginfo_sqlite3_void, ZEND_ACC_PUBLIC)
    1987             :         PHP_ME(sqlite3result, __construct,              arginfo_sqlite3_void, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR)
    1988             :         PHP_FE_END
    1989             : };
    1990             : /* }}} */
    1991             : 
    1992             : /* {{{ Authorization Callback 
    1993             : */
    1994           0 : static int php_sqlite3_authorizer(void *autharg, int access_type, const char *arg3, const char *arg4, const char *arg5, const char *arg6)
    1995             : {
    1996           0 :         switch (access_type) {
    1997             :                 case SQLITE_ATTACH:
    1998             :                 {
    1999           0 :                         if (memcmp(arg3, ":memory:", sizeof(":memory:")) && *arg3) {
    2000             :                                 TSRMLS_FETCH();
    2001             : 
    2002             : #if PHP_API_VERSION < 20100412
    2003             :                                 if (PG(safe_mode) && (!php_checkuid(arg3, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
    2004             :                                         return SQLITE_DENY;
    2005             :                                 }
    2006             : #endif
    2007             : 
    2008           0 :                                 if (php_check_open_basedir(arg3 TSRMLS_CC)) {
    2009           0 :                                         return SQLITE_DENY;
    2010             :                                 }
    2011             :                         }
    2012           0 :                         return SQLITE_OK;
    2013             :                 }
    2014             : 
    2015             :                 default:
    2016             :                         /* access allowed */
    2017           0 :                         return SQLITE_OK;
    2018             :         }
    2019             : }
    2020             : /* }}} */
    2021             : 
    2022             : /* {{{ php_sqlite3_free_list_dtor
    2023             : */
    2024          44 : static void php_sqlite3_free_list_dtor(void **item)
    2025             : {
    2026          44 :         php_sqlite3_free_list *free_item = (php_sqlite3_free_list *)*item;
    2027             : 
    2028          44 :         if (free_item->stmt_obj && free_item->stmt_obj->initialised) {
    2029          44 :                 sqlite3_finalize(free_item->stmt_obj->stmt);
    2030          44 :                 free_item->stmt_obj->initialised = 0;
    2031             :         }
    2032          44 :         efree(*item);
    2033          44 : }
    2034             : /* }}} */
    2035             : 
    2036          15 : static int php_sqlite3_compare_stmt_zval_free( php_sqlite3_free_list **free_list, zval *statement ) /* {{{ */
    2037             : {
    2038          15 :         return ((*free_list)->stmt_obj->initialised && statement == (*free_list)->stmt_obj_zval);
    2039             : }
    2040             : /* }}} */
    2041             : 
    2042          16 : static int php_sqlite3_compare_stmt_free( php_sqlite3_free_list **free_list, sqlite3_stmt *statement ) /* {{{ */
    2043             : {
    2044          16 :         return ((*free_list)->stmt_obj->initialised && statement == (*free_list)->stmt_obj->stmt);
    2045             : }
    2046             : /* }}} */
    2047             : 
    2048          67 : static void php_sqlite3_object_free_storage(void *object TSRMLS_DC) /* {{{ */
    2049             : {
    2050          67 :         php_sqlite3_db_object *intern = (php_sqlite3_db_object *)object;
    2051             :         php_sqlite3_func *func;
    2052             :         php_sqlite3_collation *collation;
    2053             : 
    2054          67 :         if (!intern) {
    2055           0 :                 return;
    2056             :         }
    2057             : 
    2058         140 :         while (intern->funcs) {
    2059           6 :                 func = intern->funcs;
    2060           6 :                 intern->funcs = func->next;
    2061           6 :                 if (intern->initialised && intern->db) {
    2062           3 :                         sqlite3_create_function(intern->db, func->func_name, func->argc, SQLITE_UTF8, func, NULL, NULL, NULL);
    2063             :                 }
    2064             : 
    2065           6 :                 efree((char*)func->func_name);
    2066             : 
    2067           6 :                 if (func->func) {
    2068           4 :                         zval_ptr_dtor(&func->func);
    2069             :                 }
    2070           6 :                 if (func->step) {
    2071           2 :                         zval_ptr_dtor(&func->step);
    2072             :                 }
    2073           6 :                 if (func->fini) {
    2074           2 :                         zval_ptr_dtor(&func->fini);
    2075             :                 }
    2076           6 :                 efree(func);
    2077             :         }
    2078             : 
    2079         135 :         while (intern->collations){
    2080           1 :                 collation = intern->collations;
    2081           1 :                 intern->collations = collation->next;
    2082           1 :                 if (intern->initialised && intern->db){
    2083           0 :                         sqlite3_create_collation(intern->db, collation->collation_name, SQLITE_UTF8, NULL, NULL);
    2084             :                 }
    2085           1 :                 efree((char*)collation->collation_name);
    2086           1 :                 if (collation->cmp_func){
    2087           1 :                         zval_ptr_dtor(&collation->cmp_func);
    2088             :                 }
    2089           1 :                 efree(collation);
    2090             :         }
    2091             : 
    2092          67 :         if (intern->initialised && intern->db) {
    2093          26 :                 sqlite3_close(intern->db);
    2094          26 :                 intern->initialised = 0;
    2095             :         }
    2096             : 
    2097          67 :         zend_object_std_dtor(&intern->zo TSRMLS_CC);
    2098          67 :         efree(intern);
    2099             : }
    2100             : /* }}} */
    2101             : 
    2102          46 : static void php_sqlite3_stmt_object_free_storage(void *object TSRMLS_DC) /* {{{ */
    2103             : {
    2104          46 :         php_sqlite3_stmt *intern = (php_sqlite3_stmt *)object;
    2105             : 
    2106          46 :         if (!intern) {
    2107           0 :                 return;
    2108             :         }
    2109             : 
    2110          46 :         if (intern->bound_params) {
    2111          13 :                 zend_hash_destroy(intern->bound_params);
    2112          13 :                 FREE_HASHTABLE(intern->bound_params);
    2113          13 :                 intern->bound_params = NULL;
    2114             :         }
    2115             : 
    2116          46 :         if (intern->initialised) {
    2117          16 :                 zend_llist_del_element(&(intern->db_obj->free_list), intern->stmt,
    2118             :                         (int (*)(void *, void *)) php_sqlite3_compare_stmt_free);
    2119             :         }
    2120             : 
    2121          46 :         if (intern->db_obj_zval) {
    2122          46 :                 zval_ptr_dtor(&intern->db_obj_zval);
    2123             :         }
    2124             : 
    2125          46 :         zend_object_std_dtor(&intern->zo TSRMLS_CC);
    2126          46 :         efree(intern);
    2127             : }
    2128             : /* }}} */
    2129             : 
    2130          39 : static void php_sqlite3_result_object_free_storage(void *object TSRMLS_DC) /* {{{ */
    2131             : {
    2132          39 :         php_sqlite3_result *intern = (php_sqlite3_result *)object;
    2133             : 
    2134          39 :         if (!intern) {
    2135           0 :                 return;
    2136             :         }
    2137             : 
    2138          39 :         if (intern->stmt_obj_zval) {
    2139          39 :                 if (intern->stmt_obj->initialised) {
    2140          18 :                         sqlite3_reset(intern->stmt_obj->stmt);
    2141             :                 }
    2142             : 
    2143          39 :                 if (intern->is_prepared_statement == 0) {
    2144          19 :                         zval_dtor(intern->stmt_obj_zval);
    2145          19 :                         FREE_ZVAL(intern->stmt_obj_zval);
    2146             :                 } else {
    2147          20 :                         zval_ptr_dtor(&intern->stmt_obj_zval);
    2148             :                 }
    2149             :         }
    2150             : 
    2151          39 :         zend_object_std_dtor(&intern->zo TSRMLS_CC);
    2152          39 :         efree(intern);
    2153             : }
    2154             : /* }}} */
    2155             : 
    2156          67 : static zend_object_value php_sqlite3_object_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
    2157             : {
    2158             :         zend_object_value retval;
    2159             :         php_sqlite3_db_object *intern;
    2160             : 
    2161             :         /* Allocate memory for it */
    2162          67 :         intern = emalloc(sizeof(php_sqlite3_db_object));
    2163          67 :         memset(intern, 0, sizeof(php_sqlite3_db_object));
    2164          67 :         intern->exception = 0;
    2165             : 
    2166             :         /* Need to keep track of things to free */
    2167          67 :         zend_llist_init(&(intern->free_list),   sizeof(php_sqlite3_free_list *), (llist_dtor_func_t)php_sqlite3_free_list_dtor, 0);
    2168             : 
    2169          67 :         zend_object_std_init(&intern->zo, class_type TSRMLS_CC);
    2170          67 :         object_properties_init(&intern->zo, class_type);
    2171             : 
    2172          67 :         retval.handle = zend_objects_store_put(intern, NULL, (zend_objects_free_object_storage_t) php_sqlite3_object_free_storage, NULL TSRMLS_CC);
    2173          67 :         retval.handlers = (zend_object_handlers *) &sqlite3_object_handlers;
    2174             : 
    2175          67 :         return retval;
    2176             : }
    2177             : /* }}} */
    2178             : 
    2179          46 : static zend_object_value php_sqlite3_stmt_object_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
    2180             : {
    2181             :         zend_object_value retval;
    2182             :         php_sqlite3_stmt *intern;
    2183             : 
    2184             :         /* Allocate memory for it */
    2185          46 :         intern = emalloc(sizeof(php_sqlite3_stmt));
    2186          46 :         memset(intern, 0, sizeof(php_sqlite3_stmt));
    2187             : 
    2188          46 :         intern->db_obj_zval = NULL;
    2189             : 
    2190          46 :         zend_object_std_init(&intern->zo, class_type TSRMLS_CC);
    2191          46 :         object_properties_init(&intern->zo, class_type);
    2192             : 
    2193          46 :         retval.handle = zend_objects_store_put(intern, NULL, (zend_objects_free_object_storage_t) php_sqlite3_stmt_object_free_storage, NULL TSRMLS_CC);
    2194          46 :         retval.handlers = (zend_object_handlers *) &sqlite3_stmt_object_handlers;
    2195             : 
    2196          46 :         return retval;
    2197             : }
    2198             : /* }}} */
    2199             : 
    2200          39 : static zend_object_value php_sqlite3_result_object_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
    2201             : {
    2202             :         zend_object_value retval;
    2203             :         php_sqlite3_result *intern;
    2204             : 
    2205             :         /* Allocate memory for it */
    2206          39 :         intern = emalloc(sizeof(php_sqlite3_result));
    2207          39 :         memset(intern, 0, sizeof(php_sqlite3_result));
    2208             : 
    2209          39 :         intern->complete = 0;
    2210          39 :         intern->is_prepared_statement = 0;
    2211          39 :         intern->stmt_obj_zval = NULL;
    2212             : 
    2213          39 :         zend_object_std_init(&intern->zo, class_type TSRMLS_CC);
    2214          39 :         object_properties_init(&intern->zo, class_type);
    2215             : 
    2216          39 :         retval.handle = zend_objects_store_put(intern, NULL, (zend_objects_free_object_storage_t) php_sqlite3_result_object_free_storage, NULL TSRMLS_CC);
    2217          39 :         retval.handlers = (zend_object_handlers *) &sqlite3_result_object_handlers;
    2218             : 
    2219          39 :         return retval;
    2220             : }
    2221             : /* }}} */
    2222             : 
    2223          21 : static void sqlite3_param_dtor(void *data) /* {{{ */
    2224             : {
    2225          21 :         struct php_sqlite3_bound_param *param = (struct php_sqlite3_bound_param*)data;
    2226             : 
    2227          21 :         if (param->name) {
    2228           5 :                 efree(param->name);
    2229             :         }
    2230             : 
    2231          21 :         if (param->parameter) {
    2232          21 :                 zval_ptr_dtor(&(param->parameter));
    2233          21 :                 param->parameter = NULL;
    2234             :         }
    2235          21 : }
    2236             : /* }}} */
    2237             : 
    2238             : /* {{{ PHP_MINIT_FUNCTION
    2239             : */
    2240       21265 : PHP_MINIT_FUNCTION(sqlite3)
    2241             : {
    2242             :         zend_class_entry ce;
    2243             : 
    2244             : #if defined(ZTS)
    2245             :         /* Refuse to load if this wasn't a threasafe library loaded */
    2246             :         if (!sqlite3_threadsafe()) {
    2247             :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "A thread safe version of SQLite is required when using a thread safe version of PHP.");
    2248             :                 return FAILURE;
    2249             :         }
    2250             : #endif
    2251             : 
    2252       21265 :         memcpy(&sqlite3_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
    2253       21265 :         memcpy(&sqlite3_stmt_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
    2254       21265 :         memcpy(&sqlite3_result_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
    2255             : 
    2256             :         /* Register SQLite 3 Class */
    2257       21265 :         INIT_CLASS_ENTRY(ce, "SQLite3", php_sqlite3_class_methods);
    2258       21265 :         ce.create_object = php_sqlite3_object_new;
    2259       21265 :         sqlite3_object_handlers.clone_obj = NULL;
    2260       21265 :         php_sqlite3_sc_entry = zend_register_internal_class(&ce TSRMLS_CC);
    2261             : 
    2262             :         /* Register SQLite 3 Prepared Statement Class */
    2263       21265 :         INIT_CLASS_ENTRY(ce, "SQLite3Stmt", php_sqlite3_stmt_class_methods);
    2264       21265 :         ce.create_object = php_sqlite3_stmt_object_new;
    2265       21265 :         sqlite3_stmt_object_handlers.clone_obj = NULL;
    2266       21265 :         php_sqlite3_stmt_entry = zend_register_internal_class(&ce TSRMLS_CC);
    2267             : 
    2268             :         /* Register SQLite 3 Result Class */
    2269       21265 :         INIT_CLASS_ENTRY(ce, "SQLite3Result", php_sqlite3_result_class_methods);
    2270       21265 :         ce.create_object = php_sqlite3_result_object_new;
    2271       21265 :         sqlite3_result_object_handlers.clone_obj = NULL;
    2272       21265 :         php_sqlite3_result_entry = zend_register_internal_class(&ce TSRMLS_CC);
    2273             : 
    2274       21265 :         REGISTER_INI_ENTRIES();
    2275             : 
    2276       21265 :         REGISTER_LONG_CONSTANT("SQLITE3_ASSOC", PHP_SQLITE3_ASSOC, CONST_CS | CONST_PERSISTENT);
    2277       21265 :         REGISTER_LONG_CONSTANT("SQLITE3_NUM", PHP_SQLITE3_NUM, CONST_CS | CONST_PERSISTENT);
    2278       21265 :         REGISTER_LONG_CONSTANT("SQLITE3_BOTH", PHP_SQLITE3_BOTH, CONST_CS | CONST_PERSISTENT);
    2279             : 
    2280       21265 :         REGISTER_LONG_CONSTANT("SQLITE3_INTEGER", SQLITE_INTEGER, CONST_CS | CONST_PERSISTENT);
    2281       21265 :         REGISTER_LONG_CONSTANT("SQLITE3_FLOAT", SQLITE_FLOAT, CONST_CS | CONST_PERSISTENT);
    2282       21265 :         REGISTER_LONG_CONSTANT("SQLITE3_TEXT", SQLITE3_TEXT, CONST_CS | CONST_PERSISTENT);
    2283       21265 :         REGISTER_LONG_CONSTANT("SQLITE3_BLOB", SQLITE_BLOB, CONST_CS | CONST_PERSISTENT);
    2284       21265 :         REGISTER_LONG_CONSTANT("SQLITE3_NULL", SQLITE_NULL, CONST_CS | CONST_PERSISTENT);
    2285             : 
    2286       21265 :         REGISTER_LONG_CONSTANT("SQLITE3_OPEN_READONLY", SQLITE_OPEN_READONLY, CONST_CS | CONST_PERSISTENT);
    2287       21265 :         REGISTER_LONG_CONSTANT("SQLITE3_OPEN_READWRITE", SQLITE_OPEN_READWRITE, CONST_CS | CONST_PERSISTENT);
    2288       21265 :         REGISTER_LONG_CONSTANT("SQLITE3_OPEN_CREATE", SQLITE_OPEN_CREATE, CONST_CS | CONST_PERSISTENT);
    2289             : 
    2290       21265 :         return SUCCESS;
    2291             : }
    2292             : /* }}} */
    2293             : 
    2294             : /* {{{ PHP_MSHUTDOWN_FUNCTION
    2295             : */
    2296       21298 : PHP_MSHUTDOWN_FUNCTION(sqlite3)
    2297             : {
    2298       21298 :         UNREGISTER_INI_ENTRIES();
    2299             : 
    2300       21298 :         return SUCCESS;
    2301             : }
    2302             : /* }}} */
    2303             : 
    2304             : /* {{{ PHP_MINFO_FUNCTION
    2305             : */
    2306         150 : PHP_MINFO_FUNCTION(sqlite3)
    2307             : {
    2308         150 :         php_info_print_table_start();
    2309         150 :         php_info_print_table_header(2, "SQLite3 support", "enabled");
    2310         150 :         php_info_print_table_row(2, "SQLite3 module version", PHP_SQLITE3_VERSION);
    2311         150 :         php_info_print_table_row(2, "SQLite Library", sqlite3_libversion());
    2312         150 :         php_info_print_table_end();
    2313             : 
    2314         150 :         DISPLAY_INI_ENTRIES();
    2315         150 : }
    2316             : /* }}} */
    2317             : 
    2318             : /* {{{ PHP_GINIT_FUNCTION
    2319             : */
    2320       21265 : static PHP_GINIT_FUNCTION(sqlite3)
    2321             : {
    2322       21265 :         memset(sqlite3_globals, 0, sizeof(*sqlite3_globals));
    2323       21265 : }
    2324             : /* }}} */
    2325             : 
    2326             : /* {{{ sqlite3_module_entry
    2327             : */
    2328             : zend_module_entry sqlite3_module_entry = {
    2329             :         STANDARD_MODULE_HEADER,
    2330             :         "sqlite3",
    2331             :         NULL,
    2332             :         PHP_MINIT(sqlite3),
    2333             :         PHP_MSHUTDOWN(sqlite3),
    2334             :         NULL,
    2335             :         NULL,
    2336             :         PHP_MINFO(sqlite3),
    2337             :         PHP_SQLITE3_VERSION,
    2338             :         PHP_MODULE_GLOBALS(sqlite3),
    2339             :         PHP_GINIT(sqlite3),
    2340             :         NULL,
    2341             :         NULL,
    2342             :         STANDARD_MODULE_PROPERTIES_EX
    2343             : };
    2344             : /* }}} */
    2345             : 
    2346             : #ifdef COMPILE_DL_SQLITE3
    2347             : ZEND_GET_MODULE(sqlite3)
    2348             : #endif
    2349             : 
    2350             : /*
    2351             :  * Local variables:
    2352             :  * tab-width: 4
    2353             :  * c-basic-offset: 4
    2354             :  * End:
    2355             :  * vim600: sw=4 ts=4 fdm=marker
    2356             :  * vim<600: sw=4 ts=4
    2357             :  */

Generated by: LCOV version 1.10

Generated at Mon, 04 Aug 2014 15:49:13 +0000 (16 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.