php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #53713
Patch session_sqlite3 revision 2011-08-01 05:13 UTC by crrodriguez at opensuse dot org
Patch bugs-53713-sqlite3-session-win32-plus-test revision 2011-05-02 12:07 UTC by jinmoku at hotmail dot com
revision 2011-05-02 12:03 UTC by jinmoku at hotmail dot com
Patch bugs-53713-sqlite3-session.patch revision 2011-05-02 12:05 UTC by jinmoku at hotmail dot com
revision 2011-04-30 02:04 UTC by jinmoku at hotmail dot com

Patch bugs-53713-sqlite3-session.patch for SQLite related Bug #53713

Patch version 2011-04-30 02:04 UTC

Return to Bug #53713 | Download this patch
Patch Revisions: 2011-05-02 12:05 UTC | 2011-04-30 02:04 UTC

Developer: jinmoku@hotmail.com

Line 1 (now 1), was 166 lines, now 30 lines
 Index: ext/sqlite3/tests/sqlite3_session_002.phpt
 ===================================================================
 --- ext/sqlite3/tests/sqlite3_session_002.phpt	(revision 0)
 +++ ext/sqlite3/tests/sqlite3_session_002.phpt	(revision 0)
 @@ -0,0 +1,54 @@
 +--TEST--
 +sqlite3, session destroy test
 +--CREDITS--
 +Mats Lindh <mats at lindh.no>
 +#Testfest php.no
 +--INI--
 +session.save_handler = sqlite3
 +--SKIPIF--
 +if (!extension_loaded("session"))
 +{
 +	die("skip Session module not loaded");
 +}
 +if (!extension_loaded("sqlite3"))
 +{
 +	die("skip sqlite3 module not loaded");
 +}
 +--FILE--
 +<?php
 +/* Description: Tests that sqlite will destroy a session when used as a session handler
 +* Source code: ext/sqlite/sess_sqlite3.c
 +*/
 +ob_start();
 +session_save_path(__DIR__ . "/sessiondb.sdb");
 +
 +// start a session and save a value to it before commiting the session to the database
 +session_start();
 +$_SESSION["test"] = "foo_bar";
 +session_write_close();
 +
 +// remove the session value
 +unset($_SESSION["test"]);
 +var_dump(isset($_SESSION["test"]));
 +
 +// start the session again and destroy it
 +session_start();
 +var_dump($_SESSION["test"]);
 +session_destroy();
 +session_write_close();
 +
 +unset($_SESSION["test"]);
 +
 +// check that the session has been destroyed
 +session_start();
 +var_dump(isset($_SESSION["test"]));
 +ob_end_flush();
 +?>
 +--EXPECTF--
 +bool(false)
 +%unicode|string%(7) "foo_bar"
 +bool(false)
 +--CLEAN--
 +<?php
 +	unlink(__DIR__ . "/sessiondb.sdb")
 +?>
 Index: ext/sqlite3/tests/sqlite3_session_001.phpt
 ===================================================================
 --- ext/sqlite3/tests/sqlite3_session_001.phpt	(revision 0)
 +++ ext/sqlite3/tests/sqlite3_session_001.phpt	(revision 0)
 @@ -0,0 +1,46 @@
 +--TEST--
 +sqlite3, session storage test
 +--CREDITS--
 +Mats Lindh <mats at lindh.no>
 +#Testfest php.no
 +--INI--
 +session.save_handler = sqlite3
 +--SKIPIF--
 +if (!extension_loaded("session"))
 +{
 +	die("skip Session module not loaded");
 +}
 +if (!extension_loaded("sqlite3"))
 +{
 +	die("skip Session module not loaded");
 +}
 +--FILE--
 +<?php
 +/* Description: Tests that sqlite can be used as a session save handler
 +* Source code: ext/sqlite/sess_sqlite3.c
 +*/
 +
 +ob_start();
 +session_save_path(__DIR__ . "/sessiondb.sdb");
 +
 +// create the session and set a session value
 +session_start();
 +$_SESSION["test"] = "foo_bar";
 +
 +// close the session and unset the value
 +session_write_close();
 +unset($_SESSION["test"]);
 +var_dump(isset($_SESSION["test"]));
 +
 +// start the session again and check that we have the proper value
 +session_start();
 +var_dump($_SESSION["test"]);
 +ob_end_flush();
 +?>
 +--EXPECTF--
 +bool(false)
 +%unicode|string%(7) "foo_bar"
 +--CLEAN--
 +<?php
 +	unlink(__DIR__ . "/sessiondb.sdb")
 +?>
 Index: ext/sqlite3/config.w32
 ===================================================================
 --- ext/sqlite3/config.w32	(revision 310704)
 +++ ext/sqlite3/config.w32	(working copy)
 @@ -5,7 +5,7 @@
  
  if (PHP_SQLITE3 != "no") {
  	ADD_FLAG("CFLAGS_SQLITE3", "/D SQLITE_THREADSAFE=" + (PHP_ZTS == "yes" ? "1" : "0") + " /D SQLITE_ENABLE_FTS3=1 /D SQLITE_ENABLE_COLUMN_METADATA=1 /D SQLITE_CORE=1 ");
 -	EXTENSION("sqlite3", "sqlite3.c", null, "/I" + configure_module_dirname + "/libsqlite /I" + configure_module_dirname);
 +	EXTENSION("sqlite3", "sqlite3.c sess_sqlite3.c", null, "/I" + configure_module_dirname + "/libsqlite /I" + configure_module_dirname);
  
  	ADD_SOURCES(configure_module_dirname + "/libsqlite", "sqlite3.c", "sqlite3");
  
  Index: ext/sqlite3/sqlite3.c
  ===================================================================
 --- ext/sqlite3/sqlite3.c	(revision 310704)
 --- ext/sqlite3/sqlite3.c	(revision 310655)
  +++ ext/sqlite3/sqlite3.c	(working copy)
  @@ -25,6 +25,9 @@
   #include "php.h"
   #include "php_ini.h"
   #include "ext/standard/info.h"
 +#include "ext/standard/info.h"
 +#if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION)
 +#if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION)
  +#include "ext/session/php_session.h"
 +#endif
   #include "php_sqlite3.h"
   #include "php_sqlite3_structs.h"
   #include "main/SAPI.h"
 @@ -38,6 +41,12 @@
  ZEND_DECLARE_MODULE_GLOBALS(sqlite3)
  
  static PHP_GINIT_FUNCTION(sqlite3);
 +
 +#if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION)
 +extern ps_module ps_mod_sqlite3;
 +#define ps_sqlite3_ptr &ps_mod_sqlite3
 +#endif
 +
  static int php_sqlite3_authorizer(void *autharg, int access_type, const char *arg3, const char *arg4, const char *arg5, const char *arg6);
  static void sqlite3_param_dtor(void *data);
  static int php_sqlite3_compare_stmt_zval_free(php_sqlite3_free_list **free_list, zval *statement);
 @@ -2114,6 +2123,10 @@
  	php_sqlite3_result_entry = zend_register_internal_class(&ce TSRMLS_CC);
 @@ -2115,6 +2118,10 @@
   
   	REGISTER_INI_ENTRIES();
 +	
  
  +#if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION)
  +	php_session_register_module(ps_sqlite3_ptr);
  +#endif
  
 +
   	REGISTER_LONG_CONSTANT("SQLITE3_ASSOC", PHP_SQLITE3_ASSOC, CONST_CS | CONST_PERSISTENT);
   	REGISTER_LONG_CONSTANT("SQLITE3_NUM", PHP_SQLITE3_NUM, CONST_CS | CONST_PERSISTENT);
 @@ -2165,6 +2178,16 @@
  	REGISTER_LONG_CONSTANT("SQLITE3_BOTH", PHP_SQLITE3_BOTH, CONST_CS | CONST_PERSISTENT);
 @@ -2165,6 +2172,16 @@
   }
   /* }}} */
   
  +/* {{{ sqlite3_module_dep


  +#define PS_SQLITE_DATA sqlite3 *db = (sqlite3*)PS_GET_MOD_DATA()
  +
  +PS_FUNCS(sqlite3);
  +
 +extern ps_module ps_mod_sqlite3 = {
 +ps_module ps_mod_sqlite3 = {
  +	PS_MOD(sqlite3)
  +};
  +
  +PS_OPEN_FUNC(sqlite3) 


  +	return SUCCESS;
  +}
  +
  +PS_CLOSE_FUNC(sqlite3) 
 +{
 +	PS_SQLITE_DATA;
 +
 +	sqlite3_close(db);
 +{
 +	PS_SQLITE_DATA;
 +
 +	sqlite3_close(db);
  +
  +	return SUCCESS;
  +}
  +


  +	PS_SQLITE_DATA;
  +	char *query;
  +	const char *tail;
  +	sqlite3_stmt *stmt;
 +	int result;
 +	int bytes, result;
  +	const char *rowdata;
  +
  +	*val = NULL;
  +	


  +	PS_SQLITE_DATA;
  +
  +	query = sqlite3_mprintf("DELETE FROM session_data WHERE sess_id='%q'", key);
  +	rv = sqlite3_exec(db, query, NULL, NULL, NULL);
 +sqlite3_free(query);
 +	sqlite3_free(query);
  +	
  +	return SQLITE_RETVAL(rv);
  +}
  +


  + * End:
  + * vim600: sw=4 ts=4 fdm=marker
  + * vim<600: sw=4 ts=4
  + */
 \ No newline at end of file
 Index: ext/sqlite3/config0.m4
 ===================================================================
 --- ext/sqlite3/config0.m4	(revision 310655)
 +++ ext/sqlite3/config0.m4	(working copy)
 @@ -85,7 +85,7 @@
  
    AC_DEFINE(HAVE_SQLITE3,1,[ ])
  
 -  sqlite3_sources="sqlite3.c $sqlite3_extra_sources"
 +  sqlite3_sources="sqlite3.c sess_sqlite3.c $sqlite3_extra_sources"
  
    PHP_NEW_EXTENSION(sqlite3, $sqlite3_sources, $ext_shared,,$PHP_SQLITE3_CFLAGS)
    PHP_ADD_BUILD_DIR([$ext_builddir/libsqlite])
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Jan 29 21:01:24 2020 UTC