1
0
mirror of https://github.com/php/php-src.git synced 2026-04-29 03:03:26 +02:00

SQLite3 extension, still has 2 failing tests that will be sorted tomorrow. Will merge to head tomorrow as well.

This commit is contained in:
Scott MacVicar
2008-07-25 02:44:59 +00:00
parent 14ce4a1d0a
commit d584ed4a01
40 changed files with 96560 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
SQLite3
Scott MacVicar
+81
View File
@@ -0,0 +1,81 @@
PHP_ARG_WITH(sqlite3, whether to enable the SQLite3 extension,
[ --with-sqlite3[=DIR] Enables the SQLite3 extension. DIR is the prefix to SQLite3 installation directory.], no)
if test $PHP_SQLITE3 != "no"; then
sqlite3_extra_sources=""
PHP_SQLITE3_CFLAGS=""
dnl when running phpize enable_maintainer_zts is not available
if test -z "$enable_maintainer_zts"; then
if test -f "$phpincludedir/main/php_config.h"; then
ZTS=`grep '#define ZTS' $phpincludedir/main/php_config.h|$SED 's/#define ZTS//'`
if test "$ZTS" -eq "1"; then
enable_maintainer_zts="yes"
fi
fi
fi
if test $PHP_SQLITE3 != "yes"; then
AC_MSG_CHECKING([for sqlite3 files in default path])
for i in $PHP_SQLITE3 /usr/local /usr; do
if test -r $i/include/sqlite3.h; then
SQLITE3_DIR=$i
AC_MSG_RESULT(found in $i)
break
fi
done
if test -z "$SQLITE3_DIR"; then
AC_MSG_RESULT([not found])
AC_MSG_ERROR([Please reinstall the sqlite distribution from http://www.sqlite.org])
fi
AC_MSG_CHECKING([for SQLite 3.3.9+])
PHP_CHECK_LIBRARY(sqlite3, sqlite3_prepare_v2, [
AC_MSG_RESULT(found)
PHP_ADD_LIBRARY_WITH_PATH(sqlite3, $SQLITE3_DIR/$PHP_LIBDIR, SQLITE3_SHARED_LIBADD)
PHP_ADD_INCLUDE($SQLITE3_DIR/include)
],[
AC_MSG_RESULT([not found])
AC_MSG_ERROR([Please install SQLite 3.3.9 first or check libsqlite3 is present])
],[
-L$SQLITE3_DIR/$PHP_LIBDIR -lm
])
PHP_CHECK_LIBRARY(sqlite3,sqlite3_key,[
AC_DEFINE(HAVE_SQLITE3_KEY, 1, [have commercial sqlite3 with crypto support])
])
else
AC_MSG_CHECKING([built in sqlite3 library])
AC_MSG_RESULT([yes])
sqlite3_extra_sources="libsqlite/sqlite3.c"
if test "$enable_maintainer_zts" = "yes"; then
threadsafe_flags="-DSQLITE_THREADSAFE=1"
else
threadsafe_flags="-DSQLITE_THREADSAFE=0"
fi
if test "$ZEND_DEBUG" = "yes"; then
debug_flags="-DSQLITE_DEBUG=1"
fi
other_flags="-DSQLITE_ENABLE_FTS3=1 -DSQLITE_CORE=1"
dnl if test "$PHP_MAJOR_VERSION" -ge "6"; then
dnl other_flags="$other_flags -DSQLITE_ENABLE_ICU=1"
dnl fi
PHP_SQLITE3_CFLAGS="-I@ext_srcdir@/libsqlite -I@ext_builddir@/libsqlite $other_flags $threadsafe_flags $debug_flags"
fi
AC_DEFINE(HAVE_SQLITE3,1,[ ])
sqlite3_sources="sqlite3.c $sqlite3_extra_sources"
PHP_NEW_EXTENSION(sqlite3, $sqlite3_sources, $ext_shared, ,$PHP_SQLITE3_CFLAGS)
PHP_SUBST(SQLITE3_SHARED_LIBADD)
fi
+17
View File
@@ -0,0 +1,17 @@
// $Id$
// vim:ft=javascript
ARG_WITH("sqlite3", "SQLite 3 support", "no");
if (PHP_SQLITE3 != "no") {
ADD_FLAG("CFLAGS_SQLITE3", "/D SQLITE_THREADSAFE=1 /D SQLITE_ENABLE_FTS3=1 /D SQLITE_CORE=1 ");
EXTENSION("sqlite3", "sqlite3.c", null, "/I" + configure_module_dirname + "/libsqlite /I" + configure_module_dirname);
ADD_SOURCES(configure_module_dirname + "/libsqlite", "sqlite3.c", "sqlite3");
AC_DEFINE("HAVE_SQLITE3", 1, "SQLite support");
if (!PHP_SQLITE3_SHARED) {
ADD_DEF_FILE(configure_module_dirname + "\\php_sqlite3.def");
}
}
+81
View File
@@ -0,0 +1,81 @@
PHP_ARG_WITH(sqlite3, whether to enable the SQLite3 extension,
[ --with-sqlite3[=DIR] Enables the SQLite3 extension. DIR is the prefix to SQLite3 installation directory.], no)
if test $PHP_SQLITE3 != "no"; then
sqlite3_extra_sources=""
PHP_SQLITE3_CFLAGS=""
dnl when running phpize enable_maintainer_zts is not available
if test -z "$enable_maintainer_zts"; then
if test -f "$phpincludedir/main/php_config.h"; then
ZTS=`grep '#define ZTS' $phpincludedir/main/php_config.h|$SED 's/#define ZTS//'`
if test "$ZTS" -eq "1"; then
enable_maintainer_zts="yes"
fi
fi
fi
if test $PHP_SQLITE3 != "yes"; then
AC_MSG_CHECKING([for sqlite3 files in default path])
for i in $PHP_SQLITE3 /usr/local /usr; do
if test -r $i/include/sqlite3.h; then
SQLITE3_DIR=$i
AC_MSG_RESULT(found in $i)
break
fi
done
if test -z "$SQLITE3_DIR"; then
AC_MSG_RESULT([not found])
AC_MSG_ERROR([Please reinstall the sqlite distribution from http://www.sqlite.org])
fi
AC_MSG_CHECKING([for SQLite 3.3.9+])
PHP_CHECK_LIBRARY(sqlite3, sqlite3_prepare_v2, [
AC_MSG_RESULT(found)
PHP_ADD_LIBRARY_WITH_PATH(sqlite3, $SQLITE3_DIR/$PHP_LIBDIR, SQLITE3_SHARED_LIBADD)
PHP_ADD_INCLUDE($SQLITE3_DIR/include)
],[
AC_MSG_RESULT([not found])
AC_MSG_ERROR([Please install SQLite 3.3.9 first or check libsqlite3 is present])
],[
-L$SQLITE3_DIR/$PHP_LIBDIR -lm
])
PHP_CHECK_LIBRARY(sqlite3,sqlite3_key,[
AC_DEFINE(HAVE_SQLITE3_KEY, 1, [have commercial sqlite3 with crypto support])
])
else
AC_MSG_CHECKING([built in sqlite3 library])
AC_MSG_RESULT([yes])
sqlite3_extra_sources="libsqlite/sqlite3.c"
if test "$enable_maintainer_zts" = "yes"; then
threadsafe_flags="-DSQLITE_THREADSAFE=1"
else
threadsafe_flags="-DSQLITE_THREADSAFE=0"
fi
if test "$ZEND_DEBUG" = "yes"; then
debug_flags="-DSQLITE_DEBUG=1"
fi
other_flags="-DSQLITE_ENABLE_FTS3=1 -DSQLITE_CORE=1"
dnl if test "$PHP_MAJOR_VERSION" -ge "6"; then
dnl other_flags="$other_flags -DSQLITE_ENABLE_ICU=1"
dnl fi
PHP_SQLITE3_CFLAGS="-I@ext_srcdir@/libsqlite -I@ext_builddir@/libsqlite $other_flags $threadsafe_flags $debug_flags"
fi
AC_DEFINE(HAVE_SQLITE3,1,[ ])
sqlite3_sources="sqlite3.c $sqlite3_extra_sources"
PHP_NEW_EXTENSION(sqlite3, $sqlite3_sources, $ext_shared, ,$PHP_SQLITE3_CFLAGS)
PHP_SUBST(SQLITE3_SHARED_LIBADD)
fi
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+362
View File
@@ -0,0 +1,362 @@
/*
** 2006 June 7
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the SQLite interface for use by
** shared libraries that want to be imported as extensions into
** an SQLite instance. Shared libraries that intend to be loaded
** as extensions by SQLite should #include this file instead of
** sqlite3.h.
**
** @(#) $Id$
*/
#ifndef _SQLITE3EXT_H_
#define _SQLITE3EXT_H_
#include "sqlite3.h"
typedef struct sqlite3_api_routines sqlite3_api_routines;
/*
** The following structure holds pointers to all of the SQLite API
** routines.
**
** WARNING: In order to maintain backwards compatibility, add new
** interfaces to the end of this structure only. If you insert new
** interfaces in the middle of this structure, then older different
** versions of SQLite will not be able to load each others' shared
** libraries!
*/
struct sqlite3_api_routines {
void * (*aggregate_context)(sqlite3_context*,int nBytes);
int (*aggregate_count)(sqlite3_context*);
int (*bind_blob)(sqlite3_stmt*,int,const void*,int n,void(*)(void*));
int (*bind_double)(sqlite3_stmt*,int,double);
int (*bind_int)(sqlite3_stmt*,int,int);
int (*bind_int64)(sqlite3_stmt*,int,sqlite_int64);
int (*bind_null)(sqlite3_stmt*,int);
int (*bind_parameter_count)(sqlite3_stmt*);
int (*bind_parameter_index)(sqlite3_stmt*,const char*zName);
const char * (*bind_parameter_name)(sqlite3_stmt*,int);
int (*bind_text)(sqlite3_stmt*,int,const char*,int n,void(*)(void*));
int (*bind_text16)(sqlite3_stmt*,int,const void*,int,void(*)(void*));
int (*bind_value)(sqlite3_stmt*,int,const sqlite3_value*);
int (*busy_handler)(sqlite3*,int(*)(void*,int),void*);
int (*busy_timeout)(sqlite3*,int ms);
int (*changes)(sqlite3*);
int (*close)(sqlite3*);
int (*collation_needed)(sqlite3*,void*,void(*)(void*,sqlite3*,int eTextRep,const char*));
int (*collation_needed16)(sqlite3*,void*,void(*)(void*,sqlite3*,int eTextRep,const void*));
const void * (*column_blob)(sqlite3_stmt*,int iCol);
int (*column_bytes)(sqlite3_stmt*,int iCol);
int (*column_bytes16)(sqlite3_stmt*,int iCol);
int (*column_count)(sqlite3_stmt*pStmt);
const char * (*column_database_name)(sqlite3_stmt*,int);
const void * (*column_database_name16)(sqlite3_stmt*,int);
const char * (*column_decltype)(sqlite3_stmt*,int i);
const void * (*column_decltype16)(sqlite3_stmt*,int);
double (*column_double)(sqlite3_stmt*,int iCol);
int (*column_int)(sqlite3_stmt*,int iCol);
sqlite_int64 (*column_int64)(sqlite3_stmt*,int iCol);
const char * (*column_name)(sqlite3_stmt*,int);
const void * (*column_name16)(sqlite3_stmt*,int);
const char * (*column_origin_name)(sqlite3_stmt*,int);
const void * (*column_origin_name16)(sqlite3_stmt*,int);
const char * (*column_table_name)(sqlite3_stmt*,int);
const void * (*column_table_name16)(sqlite3_stmt*,int);
const unsigned char * (*column_text)(sqlite3_stmt*,int iCol);
const void * (*column_text16)(sqlite3_stmt*,int iCol);
int (*column_type)(sqlite3_stmt*,int iCol);
sqlite3_value* (*column_value)(sqlite3_stmt*,int iCol);
void * (*commit_hook)(sqlite3*,int(*)(void*),void*);
int (*complete)(const char*sql);
int (*complete16)(const void*sql);
int (*create_collation)(sqlite3*,const char*,int,void*,int(*)(void*,int,const void*,int,const void*));
int (*create_collation16)(sqlite3*,const char*,int,void*,int(*)(void*,int,const void*,int,const void*));
int (*create_function)(sqlite3*,const char*,int,int,void*,void (*xFunc)(sqlite3_context*,int,sqlite3_value**),void (*xStep)(sqlite3_context*,int,sqlite3_value**),void (*xFinal)(sqlite3_context*));
int (*create_function16)(sqlite3*,const void*,int,int,void*,void (*xFunc)(sqlite3_context*,int,sqlite3_value**),void (*xStep)(sqlite3_context*,int,sqlite3_value**),void (*xFinal)(sqlite3_context*));
int (*create_module)(sqlite3*,const char*,const sqlite3_module*,void*);
int (*data_count)(sqlite3_stmt*pStmt);
sqlite3 * (*db_handle)(sqlite3_stmt*);
int (*declare_vtab)(sqlite3*,const char*);
int (*enable_shared_cache)(int);
int (*errcode)(sqlite3*db);
const char * (*errmsg)(sqlite3*);
const void * (*errmsg16)(sqlite3*);
int (*exec)(sqlite3*,const char*,sqlite3_callback,void*,char**);
int (*expired)(sqlite3_stmt*);
int (*finalize)(sqlite3_stmt*pStmt);
void (*free)(void*);
void (*free_table)(char**result);
int (*get_autocommit)(sqlite3*);
void * (*get_auxdata)(sqlite3_context*,int);
int (*get_table)(sqlite3*,const char*,char***,int*,int*,char**);
int (*global_recover)(void);
void (*interruptx)(sqlite3*);
sqlite_int64 (*last_insert_rowid)(sqlite3*);
const char * (*libversion)(void);
int (*libversion_number)(void);
void *(*malloc)(int);
char * (*mprintf)(const char*,...);
int (*open)(const char*,sqlite3**);
int (*open16)(const void*,sqlite3**);
int (*prepare)(sqlite3*,const char*,int,sqlite3_stmt**,const char**);
int (*prepare16)(sqlite3*,const void*,int,sqlite3_stmt**,const void**);
void * (*profile)(sqlite3*,void(*)(void*,const char*,sqlite_uint64),void*);
void (*progress_handler)(sqlite3*,int,int(*)(void*),void*);
void *(*realloc)(void*,int);
int (*reset)(sqlite3_stmt*pStmt);
void (*result_blob)(sqlite3_context*,const void*,int,void(*)(void*));
void (*result_double)(sqlite3_context*,double);
void (*result_error)(sqlite3_context*,const char*,int);
void (*result_error16)(sqlite3_context*,const void*,int);
void (*result_int)(sqlite3_context*,int);
void (*result_int64)(sqlite3_context*,sqlite_int64);
void (*result_null)(sqlite3_context*);
void (*result_text)(sqlite3_context*,const char*,int,void(*)(void*));
void (*result_text16)(sqlite3_context*,const void*,int,void(*)(void*));
void (*result_text16be)(sqlite3_context*,const void*,int,void(*)(void*));
void (*result_text16le)(sqlite3_context*,const void*,int,void(*)(void*));
void (*result_value)(sqlite3_context*,sqlite3_value*);
void * (*rollback_hook)(sqlite3*,void(*)(void*),void*);
int (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*,const char*,const char*),void*);
void (*set_auxdata)(sqlite3_context*,int,void*,void (*)(void*));
char * (*snprintf)(int,char*,const char*,...);
int (*step)(sqlite3_stmt*);
int (*table_column_metadata)(sqlite3*,const char*,const char*,const char*,char const**,char const**,int*,int*,int*);
void (*thread_cleanup)(void);
int (*total_changes)(sqlite3*);
void * (*trace)(sqlite3*,void(*xTrace)(void*,const char*),void*);
int (*transfer_bindings)(sqlite3_stmt*,sqlite3_stmt*);
void * (*update_hook)(sqlite3*,void(*)(void*,int ,char const*,char const*,sqlite_int64),void*);
void * (*user_data)(sqlite3_context*);
const void * (*value_blob)(sqlite3_value*);
int (*value_bytes)(sqlite3_value*);
int (*value_bytes16)(sqlite3_value*);
double (*value_double)(sqlite3_value*);
int (*value_int)(sqlite3_value*);
sqlite_int64 (*value_int64)(sqlite3_value*);
int (*value_numeric_type)(sqlite3_value*);
const unsigned char * (*value_text)(sqlite3_value*);
const void * (*value_text16)(sqlite3_value*);
const void * (*value_text16be)(sqlite3_value*);
const void * (*value_text16le)(sqlite3_value*);
int (*value_type)(sqlite3_value*);
char *(*vmprintf)(const char*,va_list);
/* Added ??? */
int (*overload_function)(sqlite3*, const char *zFuncName, int nArg);
/* Added by 3.3.13 */
int (*prepare_v2)(sqlite3*,const char*,int,sqlite3_stmt**,const char**);
int (*prepare16_v2)(sqlite3*,const void*,int,sqlite3_stmt**,const void**);
int (*clear_bindings)(sqlite3_stmt*);
/* Added by 3.4.1 */
int (*create_module_v2)(sqlite3*,const char*,const sqlite3_module*,void*,void (*xDestroy)(void *));
/* Added by 3.5.0 */
int (*bind_zeroblob)(sqlite3_stmt*,int,int);
int (*blob_bytes)(sqlite3_blob*);
int (*blob_close)(sqlite3_blob*);
int (*blob_open)(sqlite3*,const char*,const char*,const char*,sqlite3_int64,int,sqlite3_blob**);
int (*blob_read)(sqlite3_blob*,void*,int,int);
int (*blob_write)(sqlite3_blob*,const void*,int,int);
int (*create_collation_v2)(sqlite3*,const char*,int,void*,int(*)(void*,int,const void*,int,const void*),void(*)(void*));
int (*file_control)(sqlite3*,const char*,int,void*);
sqlite3_int64 (*memory_highwater)(int);
sqlite3_int64 (*memory_used)(void);
sqlite3_mutex *(*mutex_alloc)(int);
void (*mutex_enter)(sqlite3_mutex*);
void (*mutex_free)(sqlite3_mutex*);
void (*mutex_leave)(sqlite3_mutex*);
int (*mutex_try)(sqlite3_mutex*);
int (*open_v2)(const char*,sqlite3**,int,const char*);
int (*release_memory)(int);
void (*result_error_nomem)(sqlite3_context*);
void (*result_error_toobig)(sqlite3_context*);
int (*sleep)(int);
void (*soft_heap_limit)(int);
sqlite3_vfs *(*vfs_find)(const char*);
int (*vfs_register)(sqlite3_vfs*,int);
int (*vfs_unregister)(sqlite3_vfs*);
int (*xthreadsafe)(void);
void (*result_zeroblob)(sqlite3_context*,int);
void (*result_error_code)(sqlite3_context*,int);
int (*test_control)(int, ...);
void (*randomness)(int,void*);
sqlite3 *(*context_db_handle)(sqlite3_context*);
};
/*
** The following macros redefine the API routines so that they are
** redirected throught the global sqlite3_api structure.
**
** This header file is also used by the loadext.c source file
** (part of the main SQLite library - not an extension) so that
** it can get access to the sqlite3_api_routines structure
** definition. But the main library does not want to redefine
** the API. So the redefinition macros are only valid if the
** SQLITE_CORE macros is undefined.
*/
#ifndef SQLITE_CORE
#define sqlite3_aggregate_context sqlite3_api->aggregate_context
#define sqlite3_aggregate_count sqlite3_api->aggregate_count
#define sqlite3_bind_blob sqlite3_api->bind_blob
#define sqlite3_bind_double sqlite3_api->bind_double
#define sqlite3_bind_int sqlite3_api->bind_int
#define sqlite3_bind_int64 sqlite3_api->bind_int64
#define sqlite3_bind_null sqlite3_api->bind_null
#define sqlite3_bind_parameter_count sqlite3_api->bind_parameter_count
#define sqlite3_bind_parameter_index sqlite3_api->bind_parameter_index
#define sqlite3_bind_parameter_name sqlite3_api->bind_parameter_name
#define sqlite3_bind_text sqlite3_api->bind_text
#define sqlite3_bind_text16 sqlite3_api->bind_text16
#define sqlite3_bind_value sqlite3_api->bind_value
#define sqlite3_busy_handler sqlite3_api->busy_handler
#define sqlite3_busy_timeout sqlite3_api->busy_timeout
#define sqlite3_changes sqlite3_api->changes
#define sqlite3_close sqlite3_api->close
#define sqlite3_collation_needed sqlite3_api->collation_needed
#define sqlite3_collation_needed16 sqlite3_api->collation_needed16
#define sqlite3_column_blob sqlite3_api->column_blob
#define sqlite3_column_bytes sqlite3_api->column_bytes
#define sqlite3_column_bytes16 sqlite3_api->column_bytes16
#define sqlite3_column_count sqlite3_api->column_count
#define sqlite3_column_database_name sqlite3_api->column_database_name
#define sqlite3_column_database_name16 sqlite3_api->column_database_name16
#define sqlite3_column_decltype sqlite3_api->column_decltype
#define sqlite3_column_decltype16 sqlite3_api->column_decltype16
#define sqlite3_column_double sqlite3_api->column_double
#define sqlite3_column_int sqlite3_api->column_int
#define sqlite3_column_int64 sqlite3_api->column_int64
#define sqlite3_column_name sqlite3_api->column_name
#define sqlite3_column_name16 sqlite3_api->column_name16
#define sqlite3_column_origin_name sqlite3_api->column_origin_name
#define sqlite3_column_origin_name16 sqlite3_api->column_origin_name16
#define sqlite3_column_table_name sqlite3_api->column_table_name
#define sqlite3_column_table_name16 sqlite3_api->column_table_name16
#define sqlite3_column_text sqlite3_api->column_text
#define sqlite3_column_text16 sqlite3_api->column_text16
#define sqlite3_column_type sqlite3_api->column_type
#define sqlite3_column_value sqlite3_api->column_value
#define sqlite3_commit_hook sqlite3_api->commit_hook
#define sqlite3_complete sqlite3_api->complete
#define sqlite3_complete16 sqlite3_api->complete16
#define sqlite3_create_collation sqlite3_api->create_collation
#define sqlite3_create_collation16 sqlite3_api->create_collation16
#define sqlite3_create_function sqlite3_api->create_function
#define sqlite3_create_function16 sqlite3_api->create_function16
#define sqlite3_create_module sqlite3_api->create_module
#define sqlite3_create_module_v2 sqlite3_api->create_module_v2
#define sqlite3_data_count sqlite3_api->data_count
#define sqlite3_db_handle sqlite3_api->db_handle
#define sqlite3_declare_vtab sqlite3_api->declare_vtab
#define sqlite3_enable_shared_cache sqlite3_api->enable_shared_cache
#define sqlite3_errcode sqlite3_api->errcode
#define sqlite3_errmsg sqlite3_api->errmsg
#define sqlite3_errmsg16 sqlite3_api->errmsg16
#define sqlite3_exec sqlite3_api->exec
#define sqlite3_expired sqlite3_api->expired
#define sqlite3_finalize sqlite3_api->finalize
#define sqlite3_free sqlite3_api->free
#define sqlite3_free_table sqlite3_api->free_table
#define sqlite3_get_autocommit sqlite3_api->get_autocommit
#define sqlite3_get_auxdata sqlite3_api->get_auxdata
#define sqlite3_get_table sqlite3_api->get_table
#define sqlite3_global_recover sqlite3_api->global_recover
#define sqlite3_interrupt sqlite3_api->interruptx
#define sqlite3_last_insert_rowid sqlite3_api->last_insert_rowid
#define sqlite3_libversion sqlite3_api->libversion
#define sqlite3_libversion_number sqlite3_api->libversion_number
#define sqlite3_malloc sqlite3_api->malloc
#define sqlite3_mprintf sqlite3_api->mprintf
#define sqlite3_open sqlite3_api->open
#define sqlite3_open16 sqlite3_api->open16
#define sqlite3_prepare sqlite3_api->prepare
#define sqlite3_prepare16 sqlite3_api->prepare16
#define sqlite3_prepare_v2 sqlite3_api->prepare_v2
#define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2
#define sqlite3_profile sqlite3_api->profile
#define sqlite3_progress_handler sqlite3_api->progress_handler
#define sqlite3_realloc sqlite3_api->realloc
#define sqlite3_reset sqlite3_api->reset
#define sqlite3_result_blob sqlite3_api->result_blob
#define sqlite3_result_double sqlite3_api->result_double
#define sqlite3_result_error sqlite3_api->result_error
#define sqlite3_result_error16 sqlite3_api->result_error16
#define sqlite3_result_int sqlite3_api->result_int
#define sqlite3_result_int64 sqlite3_api->result_int64
#define sqlite3_result_null sqlite3_api->result_null
#define sqlite3_result_text sqlite3_api->result_text
#define sqlite3_result_text16 sqlite3_api->result_text16
#define sqlite3_result_text16be sqlite3_api->result_text16be
#define sqlite3_result_text16le sqlite3_api->result_text16le
#define sqlite3_result_value sqlite3_api->result_value
#define sqlite3_rollback_hook sqlite3_api->rollback_hook
#define sqlite3_set_authorizer sqlite3_api->set_authorizer
#define sqlite3_set_auxdata sqlite3_api->set_auxdata
#define sqlite3_snprintf sqlite3_api->snprintf
#define sqlite3_step sqlite3_api->step
#define sqlite3_table_column_metadata sqlite3_api->table_column_metadata
#define sqlite3_thread_cleanup sqlite3_api->thread_cleanup
#define sqlite3_total_changes sqlite3_api->total_changes
#define sqlite3_trace sqlite3_api->trace
#define sqlite3_transfer_bindings sqlite3_api->transfer_bindings
#define sqlite3_update_hook sqlite3_api->update_hook
#define sqlite3_user_data sqlite3_api->user_data
#define sqlite3_value_blob sqlite3_api->value_blob
#define sqlite3_value_bytes sqlite3_api->value_bytes
#define sqlite3_value_bytes16 sqlite3_api->value_bytes16
#define sqlite3_value_double sqlite3_api->value_double
#define sqlite3_value_int sqlite3_api->value_int
#define sqlite3_value_int64 sqlite3_api->value_int64
#define sqlite3_value_numeric_type sqlite3_api->value_numeric_type
#define sqlite3_value_text sqlite3_api->value_text
#define sqlite3_value_text16 sqlite3_api->value_text16
#define sqlite3_value_text16be sqlite3_api->value_text16be
#define sqlite3_value_text16le sqlite3_api->value_text16le
#define sqlite3_value_type sqlite3_api->value_type
#define sqlite3_vmprintf sqlite3_api->vmprintf
#define sqlite3_overload_function sqlite3_api->overload_function
#define sqlite3_prepare_v2 sqlite3_api->prepare_v2
#define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2
#define sqlite3_clear_bindings sqlite3_api->clear_bindings
#define sqlite3_bind_zeroblob sqlite3_api->bind_zeroblob
#define sqlite3_blob_bytes sqlite3_api->blob_bytes
#define sqlite3_blob_close sqlite3_api->blob_close
#define sqlite3_blob_open sqlite3_api->blob_open
#define sqlite3_blob_read sqlite3_api->blob_read
#define sqlite3_blob_write sqlite3_api->blob_write
#define sqlite3_create_collation_v2 sqlite3_api->create_collation_v2
#define sqlite3_file_control sqlite3_api->file_control
#define sqlite3_memory_highwater sqlite3_api->memory_highwater
#define sqlite3_memory_used sqlite3_api->memory_used
#define sqlite3_mutex_alloc sqlite3_api->mutex_alloc
#define sqlite3_mutex_enter sqlite3_api->mutex_enter
#define sqlite3_mutex_free sqlite3_api->mutex_free
#define sqlite3_mutex_leave sqlite3_api->mutex_leave
#define sqlite3_mutex_try sqlite3_api->mutex_try
#define sqlite3_open_v2 sqlite3_api->open_v2
#define sqlite3_release_memory sqlite3_api->release_memory
#define sqlite3_result_error_nomem sqlite3_api->result_error_nomem
#define sqlite3_result_error_toobig sqlite3_api->result_error_toobig
#define sqlite3_sleep sqlite3_api->sleep
#define sqlite3_soft_heap_limit sqlite3_api->soft_heap_limit
#define sqlite3_vfs_find sqlite3_api->vfs_find
#define sqlite3_vfs_register sqlite3_api->vfs_register
#define sqlite3_vfs_unregister sqlite3_api->vfs_unregister
#define sqlite3_threadsafe sqlite3_api->xthreadsafe
#define sqlite3_result_zeroblob sqlite3_api->result_zeroblob
#define sqlite3_result_error_code sqlite3_api->result_error_code
#define sqlite3_test_control sqlite3_api->test_control
#define sqlite3_randomness sqlite3_api->randomness
#define sqlite3_context_db_handle sqlite3_api->context_db_handle
#endif /* SQLITE_CORE */
#define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api;
#define SQLITE_EXTENSION_INIT2(v) sqlite3_api = v;
#endif /* _SQLITE3EXT_H_ */
+155
View File
@@ -0,0 +1,155 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2008 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Scott MacVicar <scottmac@php.net> |
+----------------------------------------------------------------------+
$Id$
*/
#ifndef PHP_SQLITE_H
#define PHP_SQLITE_H
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef ZTS
#include "TSRM.h"
#endif
/* Include PHP Standard Header */
#include "php.h"
/* Include headers */
#include <sqlite3.h>
#define PHP_SQLITE3_VERSION "0.7-dev"
extern zend_module_entry sqlite3_module_entry;
#define phpext_sqlite3_ptr &sqlite3_module_entry
ZEND_BEGIN_MODULE_GLOBALS(sqlite3)
char *extension_dir;
ZEND_END_MODULE_GLOBALS(sqlite3)
#ifdef ZTS
# define SQLITE3G(v) TSRMG(sqlite3_globals_id, zend_sqlite3_globals *, v)
#else
# define SQLITE3G(v) (sqlite3_globals.v)
#endif
#define PHP_SQLITE3_ASSOC 1<<0
#define PHP_SQLITE3_NUM 1<<1
#define PHP_SQLITE3_BOTH (PHP_SQLITE3_ASSOC|PHP_SQLITE3_NUM)
/* for backwards compatability reasons */
#ifndef SQLITE_OPEN_READONLY
#define SQLITE_OPEN_READONLY 0x00000001
#endif
#ifndef SQLITE_OPEN_READWRITE
#define SQLITE_OPEN_READWRITE 0x00000002
#endif
#ifndef SQLITE_OPEN_CREATE
#define SQLITE_OPEN_CREATE 0x00000004
#endif
/* Structure for SQLite Statement Parameter. */
struct php_sqlite3_bound_param {
long param_number;
char *name;
int name_len;
int type;
zval *parameter;
};
struct php_sqlite3_fci {
zend_fcall_info fci;
zend_fcall_info_cache fcc;
};
/* Structure for SQLite function. */
typedef struct _php_sqlite3_func {
struct _php_sqlite3_func *next;
const char *func_name;
int argc;
zval *func, *step, *fini;
struct php_sqlite3_fci afunc, astep, afini;
} php_sqlite3_func;
/* Structure for SQLite Database object. */
typedef struct _php_sqlite3_db_object {
zend_object zo;
int initialised;
sqlite3 *db;
php_sqlite3_func *funcs;
} php_sqlite3_db_object;
/*typedef struct _php_sqlite3_stmt {
sqlite3_stmt *stmt;
int initialised;
} php_sqlite3_stmt;*/
typedef struct _php_sqlite3_stmt_object php_sqlite3_stmt;
typedef struct _php_sqlite3_result_object php_sqlite3_result;
/* sqlite3 objects to be destroyed */
typedef struct _php_sqlite3_stmt_free_list {
sqlite3_stmt *stmt;
zval *statement_object;
zval *result_object;
} php_sqlite3_stmt_free_list;
/* Structure for SQLite Result object. */
struct _php_sqlite3_result_object {
zend_object zo;
php_sqlite3_db_object *db_obj;
php_sqlite3_stmt *stmt_obj;
zval *stmt_obj_zval;
int initialised;
int is_prepared_statement;
int complete;
};
/* Structure for SQLite Statement object. */
struct _php_sqlite3_stmt_object {
zend_object zo;
sqlite3_stmt *stmt;
php_sqlite3_db_object *db_obj;
zval *db_obj_zval;
int initialised;
/* Keep track of the zvals for bound parameters */
HashTable *bound_params;
};
#endif
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* indent-tabs-mode: t
* End:
*/
File diff suppressed because it is too large Load Diff
+5
View File
@@ -0,0 +1,5 @@
<?php
$db = new SQLite3(':memory:');
?>
+8
View File
@@ -0,0 +1,8 @@
<?php
if (!extension_loaded('sqlite3')) {
die("skip");
}
?>
+18
View File
@@ -0,0 +1,18 @@
--TEST--
SQLite3::open/close tests
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
var_dump($db);
var_dump($db->close());
echo "Done\n";
?>
--EXPECTF--
object(SQLite3)#%d (0) {
}
bool(true)
Done
+34
View File
@@ -0,0 +1,34 @@
--TEST--
SQLite3::query CREATE tests
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
echo "Creating Same Table Again\n";
var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
echo "Dropping database\n";
var_dump($db->exec('DROP TABLE test'));
echo "Closing database\n";
var_dump($db->close());
echo "Done\n";
?>
--EXPECTF--
Creating Table
bool(true)
Creating Same Table Again
Warning: SQLite3::exec(): table test already exists in %s on line %d
bool(false)
Dropping database
bool(true)
Closing database
bool(true)
Done
+51
View File
@@ -0,0 +1,51 @@
--TEST--
SQLite3::query INSERT tests
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
define('TIMENOW', time());
echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
echo "INSERT into table\n";
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')"));
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')"));
echo "SELECTING results\n";
$results = $db->query("SELECT * FROM test ORDER BY id ASC");
while ($result = $results->fetchArray(SQLITE3_NUM))
{
var_dump($result);
}
$results->finalize();
echo "Closing database\n";
var_dump($db->close());
echo "Done\n";
?>
--EXPECTF--
Creating Table
bool(true)
INSERT into table
bool(true)
bool(true)
SELECTING results
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "a"
}
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "b"
}
Closing database
bool(true)
Done
+77
View File
@@ -0,0 +1,77 @@
--TEST--
SQLite3::query UPDATE tests
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
define('TIMENOW', time());
echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
echo "INSERT into table\n";
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')"));
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')"));
echo "SELECTING results\n";
$results = $db->query("SELECT * FROM test ORDER BY id ASC");
while ($result = $results->fetchArray(SQLITE3_NUM))
{
var_dump($result);
}
$results->finalize();
echo "UPDATING results\n";
var_dump($db->exec("UPDATE test SET id = 'c' WHERE id = 'a'"));
echo "Checking results\n";
$results = $db->query("SELECT * FROM test ORDER BY id ASC");
while ($result = $results->fetchArray(SQLITE3_NUM))
{
var_dump($result);
}
$results->finalize();
echo "Closing database\n";
var_dump($db->close());
echo "Done\n";
?>
--EXPECTF--
Creating Table
bool(true)
INSERT into table
bool(true)
bool(true)
SELECTING results
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "a"
}
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "b"
}
UPDATING results
bool(true)
Checking results
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "b"
}
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "c"
}
Closing database
bool(true)
Done
+71
View File
@@ -0,0 +1,71 @@
--TEST--
SQLite3::query DELETE tests
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
define('TIMENOW', time());
echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
echo "INSERT into table\n";
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')"));
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')"));
echo "SELECTING results\n";
$results = $db->query("SELECT * FROM test ORDER BY id ASC");
while ($result = $results->fetchArray(SQLITE3_NUM))
{
var_dump($result);
}
$results->finalize();
echo "DELETING a row\n";
var_dump($db->exec("DELETE FROM test WHERE id = 'a'"));
echo "Checking results\n";
$results = $db->query("SELECT * FROM test ORDER BY id ASC");
while ($result = $results->fetchArray(SQLITE3_NUM))
{
var_dump($result);
}
$results->finalize();
echo "Closing database\n";
var_dump($db->close());
echo "Done\n";
?>
--EXPECTF--
Creating Table
bool(true)
INSERT into table
bool(true)
bool(true)
SELECTING results
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "a"
}
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "b"
}
DELETING a row
bool(true)
Checking results
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "b"
}
Closing database
bool(true)
Done
@@ -0,0 +1,52 @@
--TEST--
SQLite3::prepare Bound Variable test
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
define('TIMENOW', time());
echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
echo "INSERT into table\n";
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')"));
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')"));
echo "SELECTING results\n";
$stmt = $db->prepare("SELECT * FROM test WHERE id = ? ORDER BY id ASC");
$foo = 'c';
echo "BINDING Parameter\n";
var_dump($stmt->bindParam(1, $foo, SQLITE3_TEXT));
$foo = 'a';
$results = $stmt->execute();
while ($result = $results->fetchArray(SQLITE3_NUM))
{
var_dump($result);
}
$results->finalize();
echo "Closing database\n";
var_dump($db->close());
echo "Done\n";
?>
--EXPECTF--
Creating Table
bool(true)
INSERT into table
bool(true)
bool(true)
SELECTING results
BINDING Parameter
bool(true)
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "a"
}
Closing database
bool(true)
Done
@@ -0,0 +1,51 @@
--TEST--
SQLite3::prepare Bound Value test
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
define('TIMENOW', time());
echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
echo "INSERT into table\n";
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')"));
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')"));
echo "SELECTING results\n";
$stmt = $db->prepare("SELECT * FROM test WHERE id = ? ORDER BY id ASC");
$foo = 'a';
echo "BINDING Value\n";
var_dump($stmt->bindValue(1, $foo, SQLITE3_TEXT));
$results = $stmt->execute();
while ($result = $results->fetchArray(SQLITE3_NUM))
{
var_dump($result);
}
$results->finalize();
echo "Closing database\n";
var_dump($db->close());
echo "Done\n";
?>
--EXPECTF--
Creating Table
bool(true)
INSERT into table
bool(true)
bool(true)
SELECTING results
BINDING Value
bool(true)
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "a"
}
Closing database
bool(true)
Done
+57
View File
@@ -0,0 +1,57 @@
--TEST--
SQLite3::createFunction
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
function my_udf_md5($foo)
{
return md5($foo);
}
require_once(dirname(__FILE__) . '/new_db.inc');
define('TIMENOW', time());
echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
echo "INSERT into table\n";
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')"));
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')"));
echo "CREATING UDF\n";
var_dump($db->createFunction('my_udf_md5', 'my_udf_md5'));
echo "SELECTING results\n";
$results = $db->query("SELECT my_udf_md5(id) FROM test ORDER BY id ASC");
while ($result = $results->fetchArray(SQLITE3_NUM))
{
var_dump($result);
}
$results->finalize();
echo "Closing database\n";
var_dump($db->close());
echo "Done\n";
?>
--EXPECTF--
Creating Table
bool(true)
INSERT into table
bool(true)
bool(true)
CREATING UDF
bool(true)
SELECTING results
array(1) {
[0]=>
string(32) "0cc175b9c0f1b6a831c399e269772661"
}
array(1) {
[0]=>
string(32) "92eb5ffee6ae2fec3ad71c777531578f"
}
Closing database
bool(true)
Done
@@ -0,0 +1,61 @@
--TEST--
SQLite3::prepare Bound Variable Blob test
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
require_once(dirname(__FILE__) . '/stream_test.inc');
define('TIMENOW', time());
echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (id STRING, data BLOB)'));
echo "PREPARING insert\n";
$insert_stmt = $db->prepare("INSERT INTO test (id, data) VALUES (?, ?)");
echo "Opening blob stream\n";
$foo = fopen('sqliteBlobTest://fooo', 'r');
var_dump($foo);
echo "BINDING Parameter\n";
var_dump($insert_stmt->bindValue(1, 'a', SQLITE3_TEXT));
var_dump($insert_stmt->bindParam(2, $foo, SQLITE3_BLOB));
$insert_stmt->execute();
echo "Closing statement\n";
var_dump($insert_stmt->close());
echo "SELECTING results\n";
$results = $db->query("SELECT id, quote(data) AS data FROM test ORDER BY id ASC");
while ($result = $results->fetchArray(SQLITE3_NUM))
{
var_dump($result);
}
$results->finalize();
echo "Closing database\n";
var_dump($db->close());
echo "Done\n";
?>
--EXPECTF--
Creating Table
bool(true)
PREPARING insert
Opening blob stream
resource(%d) of type (stream)
BINDING Parameter
bool(true)
bool(true)
Closing statement
bool(true)
SELECTING results
array(2) {
[0]=>
string(1) "a"
[1]=>
string(23) "X'61626364656667006869'"
}
Closing database
bool(true)
Done
@@ -0,0 +1,55 @@
--TEST--
SQLite3::prepare Bound Value test
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
define('TIMENOW', time());
echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
echo "INSERT into table\n";
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')"));
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')"));
echo "SELECTING results\n";
$stmt = $db->prepare("SELECT * FROM test WHERE id = :id ORDER BY id ASC");
$foo = 'a';
echo "BINDING Value\n";
var_dump($stmt->bindValue(':id', $foo, SQLITE3_TEXT));
echo "BINDING Value Again\n";
var_dump($stmt->bindValue('id', $foo, SQLITE3_TEXT));
$results = $stmt->execute();
while ($result = $results->fetchArray(SQLITE3_NUM))
{
var_dump($result);
}
$results->finalize();
echo "Closing database\n";
var_dump($db->close());
echo "Done\n";
?>
--EXPECTF--
Creating Table
bool(true)
INSERT into table
bool(true)
bool(true)
SELECTING results
BINDING Value
bool(true)
BINDING Value Again
bool(true)
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "a"
}
Closing database
bool(true)
Done
+46
View File
@@ -0,0 +1,46 @@
--TEST--
SQLite3::prepare number of rows
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc');
// Create an instance of the ReflectionMethod class
try {
$method = new ReflectionMethod('sqlite3_result', 'numRows');
} catch (ReflectionException $e) {
die("skip");
}
?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
define('TIMENOW', time());
echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
echo "INSERT into table\n";
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')"));
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')"));
echo "SELECTING results\n";
$results = $db->query("SELECT * FROM test ORDER BY id ASC");
echo "Number of rows\n";
var_dump($results->numRows());
$results->finalize();
echo "Closing database\n";
var_dump($db->close());
echo "Done\n";
?>
--EXPECTF--
Creating Table
bool(true)
INSERT into table
bool(true)
bool(true)
SELECTING results
Number of rows
int(2)
Closing database
bool(true)
Done
@@ -0,0 +1,50 @@
--TEST--
SQLite3::query Unfinalized statement tests
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
define('TIMENOW', time());
echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
echo "INSERT into table\n";
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')"));
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')"));
echo "SELECTING results\n";
$results = $db->query("SELECT * FROM test ORDER BY id ASC");
while ($result = $results->fetchArray(SQLITE3_NUM))
{
var_dump($result);
/* Only read one row and break */
break;
}
echo "Closing database\n";
var_dump($db->close());
echo "Check result was freed\n";
var_dump($results);
echo "Done\n";
?>
--EXPECTF--
Creating Table
bool(true)
INSERT into table
bool(true)
bool(true)
SELECTING results
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "a"
}
Closing database
bool(true)
Check result was freed
NULL
Done
@@ -0,0 +1,45 @@
--TEST--
SQLite3::query Skip all cleanup
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
define('TIMENOW', time());
echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
echo "INSERT into table\n";
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')"));
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')"));
echo "SELECTING results\n";
$results = $db->query("SELECT * FROM test ORDER BY id ASC");
while ($result = $results->fetchArray(SQLITE3_NUM))
{
var_dump($result);
}
echo "Done\n";
?>
--EXPECTF--
Creating Table
bool(true)
INSERT into table
bool(true)
bool(true)
SELECTING results
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "a"
}
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "b"
}
Done
@@ -0,0 +1,38 @@
--TEST--
SQLite3::querySingle tests
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
define('TIMENOW', time());
echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
echo "INSERT into table\n";
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')"));
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')"));
echo "SELECTING results\n";
var_dump($db->querySingle("SELECT id FROM test WHERE id = 'a'"));
var_dump($db->querySingle("SELECT id, time FROM test WHERE id = 'a'", true));
echo "Done"
?>
--EXPECTF--
Creating Table
bool(true)
INSERT into table
bool(true)
bool(true)
SELECTING results
string(1) "a"
array(2) {
["id"]=>
string(1) "a"
["time"]=>
int(%d)
}
Done
@@ -0,0 +1,20 @@
--TEST--
SQLite3::open error test
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
$unreadable = dirname(__FILE__) . '/unreadable.db';
touch($unreadable);
chmod($unreadable, 0200);
$db = new SQLite3($unreadable);
var_dump($db);
echo "Done\n";
unlink($unreadable);
?>
--EXPECTF--
Notice: SQLite3::__construct(): Unable to open database: unable to open database file in %s/sqlite3_15_open_error.php on line %d
object(SQLite3)#%d (0) {
}
Done
@@ -0,0 +1,32 @@
--TEST--
SQLite3::query SELECT with no results
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
define('TIMENOW', time());
echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
echo "SELECTING results\n";
$results = $db->query("SELECT * FROM test ORDER BY id ASC");
while ($result = $results->fetchArray(SQLITE3_NUM))
{
var_dump($result);
}
$results->finalize();
echo "Closing database\n";
var_dump($db->close());
echo "Done\n";
?>
--EXPECTF--
Creating Table
bool(true)
SELECTING results
Closing database
bool(true)
Done
+16
View File
@@ -0,0 +1,16 @@
--TEST--
SQLite3::version()
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
print_r(SQLite3::version());
echo "Done\n";
?>
--EXPECTF--
Array
(
[versionString] => %d.%d.%d
[versionNumber] => %d
)
Done
+40
View File
@@ -0,0 +1,40 @@
--TEST--
SQLite3::changes() tests
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
define('TIMENOW', time());
echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
echo "INSERT into table\n";
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')"));
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')"));
echo "UPDATE query\n";
var_dump($db->exec("UPDATE test SET id = 'c'"));
echo "Rows Updated\n";
var_dump($db->changes());
echo "Closing database\n";
var_dump($db->close());
echo "Done\n";
?>
--EXPECTF--
Creating Table
bool(true)
INSERT into table
bool(true)
bool(true)
UPDATE query
bool(true)
Rows Updated
int(2)
Closing database
bool(true)
Done
@@ -0,0 +1,45 @@
--TEST--
SQLite3 columnType and columnName
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
define('TIMENOW', time());
echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
echo "INSERT into table\n";
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')"));
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')"));
echo "SELECTING results\n";
$result = $db->query("SELECT * FROM test ORDER BY id ASC");
while ($row = $result->fetchArray(SQLITE3_NUM)) {
$totalColumns = $result->numColumns();
for ($i = 0; $i < $totalColumns; $i++) {
echo "Name: " . $result->columnName($i) . " - Type: " . $result->columnType($i) . "\n";
}
}
$result->finalize();
echo "Closing database\n";
var_dump($db->close());
echo "Done\n";
?>
--EXPECTF--
Creating Table
bool(true)
INSERT into table
bool(true)
bool(true)
SELECTING results
Name: time - Type: 1
Name: id - Type: 3
Name: time - Type: 1
Name: id - Type: 3
Closing database
bool(true)
Done
+28
View File
@@ -0,0 +1,28 @@
--TEST--
SQLite3 error functions
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
echo "SELECTING from invalid table\n";
$result = $db->query("SELECT * FROM non_existent_table");
if (!$result) {
echo "Error Code: " . $db->lastErrorCode() . "\n";
echo "Error Msg: " . $db->lastErrorMsg() . "\n";
}
echo "Closing database\n";
var_dump($db->close());
echo "Done\n";
?>
--EXPECTF--
SELECTING from invalid table
Warning: SQLite3::query(): Unable to prepare statement: 1, no such table: non_existent_table in %s on line %d
Error Code: 1
Error Msg: no such table: non_existent_table
Closing database
bool(true)
Done
@@ -0,0 +1,34 @@
--TEST--
SQLite3 open_basedir / safe_mode checks
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--INI--
open_basedir=.
--FILE--
<?php
$directory = dirname(__FILE__) . '/';
$file = uniqid() . '.db';
echo "Within test directory\n";
$db = new SQLite3($directory . $file);
var_dump($db);
var_dump($db->close());
unlink($directory . $file);
echo "Above test directory\n";
$db = new SQLite3('../bad' . $file);
var_dump($db);
echo "Done\n";
?>
--EXPECTF--
Within test directory
object(SQLite3)#%d (0) {
}
bool(true)
Above test directory
Warning: SQLite3::__construct(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d
object(SQLite3)#%d (0) {
}
Done
@@ -0,0 +1,27 @@
--TEST--
SQLite3 load extension
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--INI--
open_basedir=.
sqlite3.extension_dir=.
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
$directory = dirname(__FILE__);
touch($directory . '/myext.txt');
var_dump($db->loadExtension('myext.txt'));
var_dump($db->close());
unlink($directory . '/myext.txt');
echo "Done\n";
?>
--EXPECTF--
Warning: SQLite3::loadExtension(): Unable to load extension at './myext.txt' in %s on line %d
bool(false)
bool(true)
Done
@@ -0,0 +1,51 @@
--TEST--
SQLite3::escapeString
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
define('TIMENOW', time());
echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
echo "INSERT into table\n";
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", '" . $db->escapeString("test''%") . "')"));
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')"));
echo "SELECTING results\n";
$results = $db->query("SELECT * FROM test ORDER BY id ASC");
while ($result = $results->fetchArray(SQLITE3_NUM))
{
var_dump($result);
}
$results->finalize();
echo "Closing database\n";
var_dump($db->close());
echo "Done\n";
?>
--EXPECTF--
Creating Table
bool(true)
INSERT into table
bool(true)
bool(true)
SELECTING results
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "b"
}
array(2) {
[0]=>
int(%d)
[1]=>
string(7) "test''%"
}
Closing database
bool(true)
Done
@@ -0,0 +1,34 @@
--TEST--
SQLite3::lastInsertRowID tests
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
define('TIMENOW', time());
echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
echo "INSERT into table\n";
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')"));
var_dump($db->lastInsertRowID());
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')"));
var_dump($db->lastInsertRowID());
echo "Closing database\n";
var_dump($db->close());
echo "Done\n";
?>
--EXPECTF--
Creating Table
bool(true)
INSERT into table
bool(true)
int(1)
bool(true)
int(2)
Closing database
bool(true)
Done
@@ -0,0 +1,56 @@
--TEST--
SQLite3::createAggregate() test
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
function sum_list_step(&$context, $string) {
if (empty($context))
{
$context = array('total' => 0, 'values' => array());
}
var_dump($context);
$context['total'] += intval($string);
$context['values'][] = $context['total'];
return true;
}
function sum_list_finalize(&$context) {
var_dump($context);
return implode(',', $context['values']);
}
echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (a INTEGER, b INTEGER)'));
echo "INSERT into table\n";
var_dump($db->exec("INSERT INTO test (a, b) VALUES (1, -1)"));
var_dump($db->exec("INSERT INTO test (a, b) VALUES (2, -2)"));
var_dump($db->exec("INSERT INTO test (a, b) VALUES (3, -3)"));
var_dump($db->exec("INSERT INTO test (a, b) VALUES (4, -4)"));
var_dump($db->exec("INSERT INTO test (a, b) VALUES (4, -4)"));
$db->createAggregate('S', 'sum_list_step', 'sum_list_finalize', 1);
print_r($db->querySingle("SELECT S(a), S(b) FROM test", true));
echo "Closing database\n";
var_dump($db->close());
echo "Done\n";
?>
--EXPECTF--
Creating Table
bool(true)
INSERT into table
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
Closing database
bool(true)
Done
@@ -0,0 +1,61 @@
--TEST--
SQLite3::reset prepared statement
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
define('TIMENOW', time());
echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
echo "INSERT into table\n";
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')"));
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')"));
echo "SELECTING results\n";
$stmt = $db->prepare("SELECT * FROM test WHERE id = ? ORDER BY id ASC");
$foo = 'c';
echo "BINDING Parameter\n";
var_dump($stmt->bindParam(1, $foo, SQLITE3_TEXT));
$foo = 'a';
$results = $stmt->execute();
while ($result = $results->fetchArray(SQLITE3_NUM)) {
var_dump($result);
}
$stmt->reset();
while ($result = $results->fetchArray(SQLITE3_NUM)) {
var_dump($result);
}
$results->finalize();
echo "Closing database\n";
var_dump($db->close());
echo "Done\n";
?>
--EXPECTF--
Creating Table
bool(true)
INSERT into table
bool(true)
bool(true)
SELECTING results
BINDING Parameter
bool(true)
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "a"
}
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "a"
}
Closing database
bool(true)
Done
@@ -0,0 +1,61 @@
--TEST--
SQLite3::reset prepared statement results
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
define('TIMENOW', time());
echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
echo "INSERT into table\n";
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')"));
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')"));
echo "SELECTING results\n";
$stmt = $db->prepare("SELECT * FROM test WHERE id = ? ORDER BY id ASC");
$foo = 'c';
echo "BINDING Parameter\n";
var_dump($stmt->bindParam(1, $foo, SQLITE3_TEXT));
$foo = 'a';
$results = $stmt->execute();
while ($result = $results->fetchArray(SQLITE3_NUM)) {
var_dump($result);
}
$results->reset();
while ($result = $results->fetchArray(SQLITE3_NUM)) {
var_dump($result);
}
$results->finalize();
echo "Closing database\n";
var_dump($db->close());
echo "Done\n";
?>
--EXPECTF--
Creating Table
bool(true)
INSERT into table
bool(true)
bool(true)
SELECTING results
BINDING Parameter
bool(true)
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "a"
}
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "a"
}
Closing database
bool(true)
Done
@@ -0,0 +1,65 @@
--TEST--
SQLite3_stmt::clear prepared statement results
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
require_once(dirname(__FILE__) . '/new_db.inc');
define('TIMENOW', time());
echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
echo "INSERT into table\n";
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')"));
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')"));
echo "SELECTING results\n";
$stmt = $db->prepare("SELECT * FROM test WHERE id = ? ORDER BY id ASC");
$foo = 'c';
echo "BINDING Parameter\n";
var_dump($stmt->bindParam(1, $foo, SQLITE3_TEXT));
$foo = 'a';
$results = $stmt->execute();
while ($result = $results->fetchArray(SQLITE3_NUM)) {
var_dump($result);
}
$stmt->reset();
$stmt->clear();
var_dump($stmt->bindValue(1, 'b', SQLITE3_TEXT));
$results = $stmt->execute();
while ($result = $results->fetchArray(SQLITE3_NUM)) {
var_dump($result);
}
$results->finalize();
echo "Closing database\n";
var_dump($db->close());
echo "Done\n";
?>
--EXPECTF--
Creating Table
bool(true)
INSERT into table
bool(true)
bool(true)
SELECTING results
BINDING Parameter
bool(true)
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "a"
}
bool(true)
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "b"
}
Closing database
bool(true)
Done
+45
View File
@@ -0,0 +1,45 @@
<?php
class SQLite3_Test_Stream
{
private $position;
public static $string_length = 10;
public static $string = "abcdefg\0hi";
public function stream_open($path, $mode, $options, &$opened_path)
{
$this->position = 0;
return true;
}
public function stream_read($count)
{
$ret = substr(self::$string, $this->position, $count);
$this->position += strlen($ret);
return $ret;
}
public function stream_write($data)
{
return 0;
}
public function stream_stat()
{
return array('size' => self::$string_length);
}
public function stream_tell()
{
return $this->position;
}
public function stream_eof()
{
return ($this->position >= self::$string_length);
}
}
stream_wrapper_register('sqliteBlobTest', "SQLite3_Test_Stream") or die("Unable to register sqliteBlobTest stream");
?>