mirror of
https://github.com/php/php-src.git
synced 2024-09-22 10:27:25 +00:00
Move ext/interbase to pecl/database/interbase
https://wiki.php.net/rfc/deprecate-and-remove-ext-interbase
This commit is contained in:
parent
ec5f7df732
commit
b458fcb87f
@ -1,2 +0,0 @@
|
||||
InterBase
|
||||
Jouni Ahto, Andrew Avdeev, Ard Biesheuvel
|
@ -1,59 +0,0 @@
|
||||
PHP_ARG_WITH([interbase],
|
||||
[for Firebird support],
|
||||
[AS_HELP_STRING([[--with-interbase[=DIR]]],
|
||||
[Include Firebird support. DIR is the Firebird base install directory
|
||||
[/opt/firebird]])])
|
||||
|
||||
if test "$PHP_INTERBASE" != "no"; then
|
||||
|
||||
AC_PATH_PROG(FB_CONFIG, fb_config, no)
|
||||
|
||||
if test -x "$FB_CONFIG" && test "$PHP_INTERBASE" = "yes"; then
|
||||
AC_MSG_CHECKING(for libfbconfig)
|
||||
FB_CFLAGS=`$FB_CONFIG --cflags`
|
||||
FB_LIBDIR=`$FB_CONFIG --libs`
|
||||
FB_VERSION=`$FB_CONFIG --version`
|
||||
AC_MSG_RESULT(version $FB_VERSION)
|
||||
PHP_EVAL_LIBLINE($FB_LIBDIR, INTERBASE_SHARED_LIBADD)
|
||||
PHP_EVAL_INCLINE($FB_CFLAGS)
|
||||
|
||||
else
|
||||
if test "$PHP_INTERBASE" = "yes"; then
|
||||
IBASE_INCDIR=/opt/firebird/include
|
||||
IBASE_LIBDIR=/opt/firebird/lib
|
||||
else
|
||||
IBASE_INCDIR=$PHP_INTERBASE/include
|
||||
IBASE_LIBDIR=$PHP_INTERBASE/$PHP_LIBDIR
|
||||
fi
|
||||
|
||||
PHP_CHECK_LIBRARY(fbclient, isc_detach_database,
|
||||
[
|
||||
IBASE_LIBNAME=fbclient
|
||||
], [
|
||||
PHP_CHECK_LIBRARY(gds, isc_detach_database,
|
||||
[
|
||||
IBASE_LIBNAME=gds
|
||||
], [
|
||||
PHP_CHECK_LIBRARY(ib_util, isc_detach_database,
|
||||
[
|
||||
IBASE_LIBNAME=ib_util
|
||||
], [
|
||||
AC_MSG_ERROR([libfbclient, libgds or libib_util not found! Check config.log for more information.])
|
||||
], [
|
||||
-L$IBASE_LIBDIR
|
||||
])
|
||||
], [
|
||||
-L$IBASE_LIBDIR
|
||||
])
|
||||
], [
|
||||
-L$IBASE_LIBDIR
|
||||
])
|
||||
|
||||
PHP_ADD_LIBRARY_WITH_PATH($IBASE_LIBNAME, $IBASE_LIBDIR, INTERBASE_SHARED_LIBADD)
|
||||
PHP_ADD_INCLUDE($IBASE_INCDIR)
|
||||
fi
|
||||
|
||||
AC_DEFINE(HAVE_IBASE,1,[ ])
|
||||
PHP_NEW_EXTENSION(interbase, interbase.c ibase_query.c ibase_service.c ibase_events.c ibase_blobs.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
|
||||
PHP_SUBST(INTERBASE_SHARED_LIBADD)
|
||||
fi
|
@ -1,17 +0,0 @@
|
||||
// vim:ft=javascript
|
||||
|
||||
ARG_WITH("interbase", "InterBase support", "no");
|
||||
|
||||
if (PHP_INTERBASE != "no") {
|
||||
|
||||
if (CHECK_HEADER_ADD_INCLUDE("ibase.h", "CFLAGS_INTERBASE",
|
||||
PHP_PHP_BUILD + "\\include\\interbase;" + PHP_PHP_BUILD + "\\interbase\\include;" + PHP_INTERBASE) &&
|
||||
(CHECK_LIB("fbclient_ms.lib", "interbase", PHP_PHP_BUILD + "\\interbase\\lib_ms;" + PHP_INTERBASE) ||
|
||||
CHECK_LIB("gds32_ms.lib", "interbase", PHP_PHP_BUILD + "\\interbase\\lib_ms;" + PHP_INTERBASE))) {
|
||||
|
||||
EXTENSION("interbase", "interbase.c ibase_query.c ibase_service.c ibase_events.c ibase_blobs.c", PHP_INTERBASE_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
|
||||
AC_DEFINE('HAVE_IBASE', 1, 'Have interbase library');
|
||||
} else {
|
||||
WARNING("interbase not enabled; libraries and headers not found");
|
||||
}
|
||||
}
|
@ -1,555 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 7 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 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: Ard Biesheuvel <a.k.biesheuvel@its.tudelft.nl> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "php.h"
|
||||
|
||||
#if HAVE_IBASE
|
||||
|
||||
#include "php_interbase.h"
|
||||
#include "php_ibase_includes.h"
|
||||
|
||||
#define BLOB_CLOSE 1
|
||||
#define BLOB_CANCEL 2
|
||||
|
||||
#define PARSE_PARAMETERS \
|
||||
switch (ZEND_NUM_ARGS()) { \
|
||||
default: \
|
||||
WRONG_PARAM_COUNT; \
|
||||
case 1: \
|
||||
if (FAILURE == zend_parse_parameters(1, "s", &blob_id, &blob_id_len)) { \
|
||||
RETURN_FALSE; \
|
||||
} \
|
||||
break; \
|
||||
case 2: \
|
||||
if (FAILURE == zend_parse_parameters(2, "rs", &link, &blob_id, &blob_id_len)) { \
|
||||
RETURN_FALSE; \
|
||||
} \
|
||||
break; \
|
||||
} \
|
||||
|
||||
static int le_blob;
|
||||
|
||||
static void _php_ibase_free_blob(zend_resource *rsrc) /* {{{ */
|
||||
{
|
||||
ibase_blob *ib_blob = (ibase_blob *)rsrc->ptr;
|
||||
|
||||
if (ib_blob->bl_handle != 0) { /* blob open*/
|
||||
if (isc_cancel_blob(IB_STATUS, &ib_blob->bl_handle)) {
|
||||
_php_ibase_module_error("You can lose data. Close any blob after reading from or "
|
||||
"writing to it. Use ibase_blob_close() before calling ibase_close()");
|
||||
}
|
||||
}
|
||||
efree(ib_blob);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
void php_ibase_blobs_minit(INIT_FUNC_ARGS) /* {{{ */
|
||||
{
|
||||
le_blob = zend_register_list_destructors_ex(_php_ibase_free_blob, NULL,
|
||||
"interbase blob", module_number);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
int _php_ibase_string_to_quad(char const *id, ISC_QUAD *qd) /* {{{ */
|
||||
{
|
||||
/* shortcut for most common case */
|
||||
if (sizeof(ISC_QUAD) == sizeof(ISC_UINT64)) {
|
||||
return sscanf(id, BLOB_ID_MASK, (ISC_UINT64 *) qd);
|
||||
} else {
|
||||
ISC_UINT64 res;
|
||||
if (sscanf(id, BLOB_ID_MASK, &res)) {
|
||||
qd->gds_quad_high = (ISC_LONG) (res >> 0x20);
|
||||
qd->gds_quad_low = (ISC_LONG) (res & 0xFFFFFFFF);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
zend_string *_php_ibase_quad_to_string(ISC_QUAD const qd) /* {{{ */
|
||||
{
|
||||
/* shortcut for most common case */
|
||||
if (sizeof(ISC_QUAD) == sizeof(ISC_UINT64)) {
|
||||
return strpprintf(BLOB_ID_LEN+1, "0x%0*" LL_MASK "x", 16, *(ISC_UINT64*)(void *) &qd);
|
||||
} else {
|
||||
ISC_UINT64 res = ((ISC_UINT64) qd.gds_quad_high << 0x20) | qd.gds_quad_low;
|
||||
return strpprintf(BLOB_ID_LEN+1, "0x%0*" LL_MASK "x", 16, res);
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
typedef struct { /* {{{ */
|
||||
ISC_LONG max_segment; /* Length of longest segment */
|
||||
ISC_LONG num_segments; /* Total number of segments */
|
||||
ISC_LONG total_length; /* Total length of blob */
|
||||
int bl_stream; /* blob is stream ? */
|
||||
/* }}} */
|
||||
} IBASE_BLOBINFO;
|
||||
|
||||
int _php_ibase_blob_get(zval *return_value, ibase_blob *ib_blob, zend_ulong max_len) /* {{{ */
|
||||
{
|
||||
if (ib_blob->bl_qd.gds_quad_high || ib_blob->bl_qd.gds_quad_low) { /*not null ?*/
|
||||
|
||||
ISC_STATUS stat;
|
||||
zend_string *bl_data;
|
||||
zend_ulong cur_len;
|
||||
unsigned short seg_len;
|
||||
|
||||
bl_data = zend_string_safe_alloc(1, max_len, 0, 0);
|
||||
|
||||
for (cur_len = stat = 0; (stat == 0 || stat == isc_segment) && cur_len < max_len; cur_len += seg_len) {
|
||||
|
||||
unsigned short chunk_size = (max_len-cur_len) > USHRT_MAX ? USHRT_MAX
|
||||
: (unsigned short)(max_len-cur_len);
|
||||
|
||||
stat = isc_get_segment(IB_STATUS, &ib_blob->bl_handle, &seg_len, chunk_size, &ZSTR_VAL(bl_data)[cur_len]);
|
||||
}
|
||||
|
||||
if (IB_STATUS[0] == 1 && (stat != 0 && stat != isc_segstr_eof && stat != isc_segment)) {
|
||||
zend_string_free(bl_data);
|
||||
_php_ibase_error();
|
||||
return FAILURE;
|
||||
}
|
||||
ZSTR_VAL(bl_data)[cur_len] = '\0';
|
||||
ZSTR_LEN(bl_data) = cur_len;
|
||||
RETVAL_NEW_STR(bl_data);
|
||||
} else { /* null blob */
|
||||
RETVAL_EMPTY_STRING(); /* empty string */
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
int _php_ibase_blob_add(zval *string_arg, ibase_blob *ib_blob) /* {{{ */
|
||||
{
|
||||
zend_ulong put_cnt = 0, rem_cnt;
|
||||
unsigned short chunk_size;
|
||||
|
||||
convert_to_string_ex(string_arg);
|
||||
|
||||
for (rem_cnt = Z_STRLEN_P(string_arg); rem_cnt > 0; rem_cnt -= chunk_size) {
|
||||
|
||||
chunk_size = rem_cnt > USHRT_MAX ? USHRT_MAX : (unsigned short)rem_cnt;
|
||||
|
||||
if (isc_put_segment(IB_STATUS, &ib_blob->bl_handle, chunk_size, &Z_STRVAL_P(string_arg)[put_cnt] )) {
|
||||
_php_ibase_error();
|
||||
return FAILURE;
|
||||
}
|
||||
put_cnt += chunk_size;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static int _php_ibase_blob_info(isc_blob_handle bl_handle, IBASE_BLOBINFO *bl_info) /* {{{ */
|
||||
{
|
||||
static char bl_items[] = {
|
||||
isc_info_blob_num_segments,
|
||||
isc_info_blob_max_segment,
|
||||
isc_info_blob_total_length,
|
||||
isc_info_blob_type
|
||||
};
|
||||
|
||||
char bl_inf[sizeof(zend_long)*8], *p;
|
||||
|
||||
bl_info->max_segment = 0;
|
||||
bl_info->num_segments = 0;
|
||||
bl_info->total_length = 0;
|
||||
bl_info->bl_stream = 0;
|
||||
|
||||
if (isc_blob_info(IB_STATUS, &bl_handle, sizeof(bl_items), bl_items, sizeof(bl_inf), bl_inf)) {
|
||||
_php_ibase_error();
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
for (p = bl_inf; *p != isc_info_end && p < bl_inf + sizeof(bl_inf);) {
|
||||
unsigned short item_len;
|
||||
int item = *p++;
|
||||
|
||||
item_len = (short) isc_vax_integer(p, 2);
|
||||
p += 2;
|
||||
switch (item) {
|
||||
case isc_info_blob_num_segments:
|
||||
bl_info->num_segments = isc_vax_integer(p, item_len);
|
||||
break;
|
||||
case isc_info_blob_max_segment:
|
||||
bl_info->max_segment = isc_vax_integer(p, item_len);
|
||||
break;
|
||||
case isc_info_blob_total_length:
|
||||
bl_info->total_length = isc_vax_integer(p, item_len);
|
||||
break;
|
||||
case isc_info_blob_type:
|
||||
bl_info->bl_stream = isc_vax_integer(p, item_len);
|
||||
break;
|
||||
case isc_info_end:
|
||||
break;
|
||||
case isc_info_truncated:
|
||||
case isc_info_error: /* hmm. don't think so...*/
|
||||
_php_ibase_module_error("PHP module internal error");
|
||||
return FAILURE;
|
||||
} /* switch */
|
||||
p += item_len;
|
||||
} /* for */
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto resource ibase_blob_create([resource link_identifier])
|
||||
Create blob for adding data */
|
||||
PHP_FUNCTION(ibase_blob_create)
|
||||
{
|
||||
zval *link = NULL;
|
||||
ibase_db_link *ib_link;
|
||||
ibase_trans *trans = NULL;
|
||||
ibase_blob *ib_blob;
|
||||
|
||||
RESET_ERRMSG;
|
||||
|
||||
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &link)) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
PHP_IBASE_LINK_TRANS(link, ib_link, trans);
|
||||
|
||||
ib_blob = (ibase_blob *) emalloc(sizeof(ibase_blob));
|
||||
ib_blob->bl_handle = 0;
|
||||
ib_blob->type = BLOB_INPUT;
|
||||
|
||||
if (isc_create_blob(IB_STATUS, &ib_link->handle, &trans->handle, &ib_blob->bl_handle, &ib_blob->bl_qd)) {
|
||||
_php_ibase_error();
|
||||
efree(ib_blob);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
RETVAL_RES(zend_register_resource(ib_blob, le_blob));
|
||||
Z_TRY_ADDREF_P(return_value);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto resource ibase_blob_open([ resource link_identifier, ] string blob_id)
|
||||
Open blob for retrieving data parts */
|
||||
PHP_FUNCTION(ibase_blob_open)
|
||||
{
|
||||
char *blob_id;
|
||||
size_t blob_id_len;
|
||||
zval *link = NULL;
|
||||
ibase_db_link *ib_link;
|
||||
ibase_trans *trans = NULL;
|
||||
ibase_blob *ib_blob;
|
||||
|
||||
RESET_ERRMSG;
|
||||
PARSE_PARAMETERS;
|
||||
|
||||
PHP_IBASE_LINK_TRANS(link, ib_link, trans);
|
||||
|
||||
ib_blob = (ibase_blob *) emalloc(sizeof(ibase_blob));
|
||||
ib_blob->bl_handle = 0;
|
||||
ib_blob->type = BLOB_OUTPUT;
|
||||
|
||||
do {
|
||||
if (! _php_ibase_string_to_quad(blob_id, &ib_blob->bl_qd)) {
|
||||
_php_ibase_module_error("String is not a BLOB ID");
|
||||
break;
|
||||
}
|
||||
|
||||
if (isc_open_blob(IB_STATUS, &ib_link->handle, &trans->handle, &ib_blob->bl_handle,
|
||||
&ib_blob->bl_qd)) {
|
||||
_php_ibase_error();
|
||||
break;
|
||||
}
|
||||
|
||||
RETVAL_RES(zend_register_resource(ib_blob, le_blob));
|
||||
Z_TRY_ADDREF_P(return_value);
|
||||
return;
|
||||
|
||||
} while (0);
|
||||
|
||||
efree(ib_blob);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool ibase_blob_add(resource blob_handle, string data)
|
||||
Add data into created blob */
|
||||
PHP_FUNCTION(ibase_blob_add)
|
||||
{
|
||||
zval *blob_arg, *string_arg;
|
||||
ibase_blob *ib_blob;
|
||||
|
||||
RESET_ERRMSG;
|
||||
|
||||
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "rz", &blob_arg, &string_arg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ib_blob = (ibase_blob *)zend_fetch_resource_ex(blob_arg, "Interbase blob", le_blob);
|
||||
|
||||
if (ib_blob->type != BLOB_INPUT) {
|
||||
_php_ibase_module_error("BLOB is not open for input");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (_php_ibase_blob_add(string_arg, ib_blob) != SUCCESS) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string ibase_blob_get(resource blob_handle, int len)
|
||||
Get len bytes data from open blob */
|
||||
PHP_FUNCTION(ibase_blob_get)
|
||||
{
|
||||
zval *blob_arg;
|
||||
zend_ulong len_arg;
|
||||
ibase_blob *ib_blob;
|
||||
|
||||
RESET_ERRMSG;
|
||||
|
||||
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &blob_arg, &len_arg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ib_blob = (ibase_blob *)zend_fetch_resource_ex(blob_arg, "Interbase blob", le_blob);
|
||||
|
||||
if (ib_blob->type != BLOB_OUTPUT) {
|
||||
_php_ibase_module_error("BLOB is not open for output");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (_php_ibase_blob_get(return_value, ib_blob, len_arg) != SUCCESS) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static void _php_ibase_blob_end(INTERNAL_FUNCTION_PARAMETERS, int bl_end) /* {{{ */
|
||||
{
|
||||
zval *blob_arg;
|
||||
ibase_blob *ib_blob;
|
||||
|
||||
RESET_ERRMSG;
|
||||
|
||||
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "r", &blob_arg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ib_blob = (ibase_blob *)zend_fetch_resource_ex(blob_arg, "Interbase blob", le_blob);
|
||||
|
||||
if (bl_end == BLOB_CLOSE) { /* return id here */
|
||||
|
||||
if (ib_blob->bl_qd.gds_quad_high || ib_blob->bl_qd.gds_quad_low) { /*not null ?*/
|
||||
if (isc_close_blob(IB_STATUS, &ib_blob->bl_handle)) {
|
||||
_php_ibase_error();
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
ib_blob->bl_handle = 0;
|
||||
|
||||
RETVAL_NEW_STR(_php_ibase_quad_to_string(ib_blob->bl_qd));
|
||||
} else { /* discard created blob */
|
||||
if (isc_cancel_blob(IB_STATUS, &ib_blob->bl_handle)) {
|
||||
_php_ibase_error();
|
||||
RETURN_FALSE;
|
||||
}
|
||||
ib_blob->bl_handle = 0;
|
||||
RETVAL_TRUE;
|
||||
}
|
||||
zend_list_delete(Z_RES_P(blob_arg));
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string ibase_blob_close(resource blob_handle)
|
||||
Close blob */
|
||||
PHP_FUNCTION(ibase_blob_close)
|
||||
{
|
||||
_php_ibase_blob_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, BLOB_CLOSE);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool ibase_blob_cancel(resource blob_handle)
|
||||
Cancel creating blob */
|
||||
PHP_FUNCTION(ibase_blob_cancel)
|
||||
{
|
||||
_php_ibase_blob_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, BLOB_CANCEL);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto array ibase_blob_info([ resource link_identifier, ] string blob_id)
|
||||
Return blob length and other useful info */
|
||||
PHP_FUNCTION(ibase_blob_info)
|
||||
{
|
||||
char *blob_id;
|
||||
size_t blob_id_len;
|
||||
zval *link = NULL;
|
||||
ibase_db_link *ib_link;
|
||||
ibase_trans *trans = NULL;
|
||||
ibase_blob ib_blob = { 0, BLOB_INPUT };
|
||||
IBASE_BLOBINFO bl_info;
|
||||
|
||||
RESET_ERRMSG;
|
||||
PARSE_PARAMETERS;
|
||||
|
||||
PHP_IBASE_LINK_TRANS(link, ib_link, trans);
|
||||
|
||||
if (! _php_ibase_string_to_quad(blob_id, &ib_blob.bl_qd)) {
|
||||
_php_ibase_module_error("Unrecognized BLOB ID");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (ib_blob.bl_qd.gds_quad_high || ib_blob.bl_qd.gds_quad_low) { /* not null ? */
|
||||
if (isc_open_blob(IB_STATUS, &ib_link->handle, &trans->handle, &ib_blob.bl_handle,
|
||||
&ib_blob.bl_qd)) {
|
||||
_php_ibase_error();
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (_php_ibase_blob_info(ib_blob.bl_handle, &bl_info)) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
if (isc_close_blob(IB_STATUS, &ib_blob.bl_handle)) {
|
||||
_php_ibase_error();
|
||||
RETURN_FALSE;
|
||||
}
|
||||
} else { /* null blob, all values to zero */
|
||||
bl_info.max_segment = 0;
|
||||
bl_info.num_segments = 0;
|
||||
bl_info.total_length = 0;
|
||||
bl_info.bl_stream = 0;
|
||||
}
|
||||
|
||||
array_init(return_value);
|
||||
|
||||
add_index_long(return_value, 0, bl_info.total_length);
|
||||
add_assoc_long(return_value, "length", bl_info.total_length);
|
||||
|
||||
add_index_long(return_value, 1, bl_info.num_segments);
|
||||
add_assoc_long(return_value, "numseg", bl_info.num_segments);
|
||||
|
||||
add_index_long(return_value, 2, bl_info.max_segment);
|
||||
add_assoc_long(return_value, "maxseg", bl_info.max_segment);
|
||||
|
||||
add_index_bool(return_value, 3, bl_info.bl_stream);
|
||||
add_assoc_bool(return_value, "stream", bl_info.bl_stream);
|
||||
|
||||
add_index_bool(return_value, 4, (!ib_blob.bl_qd.gds_quad_high && !ib_blob.bl_qd.gds_quad_low));
|
||||
add_assoc_bool(return_value, "isnull", (!ib_blob.bl_qd.gds_quad_high && !ib_blob.bl_qd.gds_quad_low));
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool ibase_blob_echo([ resource link_identifier, ] string blob_id)
|
||||
Output blob contents to browser */
|
||||
PHP_FUNCTION(ibase_blob_echo)
|
||||
{
|
||||
char *blob_id;
|
||||
size_t blob_id_len;
|
||||
zval *link = NULL;
|
||||
ibase_db_link *ib_link;
|
||||
ibase_trans *trans = NULL;
|
||||
ibase_blob ib_blob_id = { 0, BLOB_OUTPUT };
|
||||
char bl_data[IBASE_BLOB_SEG];
|
||||
unsigned short seg_len;
|
||||
|
||||
RESET_ERRMSG;
|
||||
PARSE_PARAMETERS;
|
||||
|
||||
PHP_IBASE_LINK_TRANS(link, ib_link, trans);
|
||||
|
||||
if (! _php_ibase_string_to_quad(blob_id, &ib_blob_id.bl_qd)) {
|
||||
_php_ibase_module_error("Unrecognized BLOB ID");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
do {
|
||||
if (isc_open_blob(IB_STATUS, &ib_link->handle, &trans->handle, &ib_blob_id.bl_handle,
|
||||
&ib_blob_id.bl_qd)) {
|
||||
break;
|
||||
}
|
||||
|
||||
while (!isc_get_segment(IB_STATUS, &ib_blob_id.bl_handle, &seg_len, sizeof(bl_data), bl_data)
|
||||
|| IB_STATUS[1] == isc_segment) {
|
||||
PHPWRITE(bl_data, seg_len);
|
||||
}
|
||||
|
||||
if (IB_STATUS[0] && (IB_STATUS[1] != isc_segstr_eof)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (isc_close_blob(IB_STATUS, &ib_blob_id.bl_handle)) {
|
||||
break;
|
||||
}
|
||||
RETURN_TRUE;
|
||||
} while (0);
|
||||
|
||||
_php_ibase_error();
|
||||
RETURN_FALSE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string ibase_blob_import([ resource link_identifier, ] resource file)
|
||||
Create blob, copy file in it, and close it */
|
||||
PHP_FUNCTION(ibase_blob_import)
|
||||
{
|
||||
zval *link = NULL, *file;
|
||||
int size;
|
||||
unsigned short b;
|
||||
ibase_blob ib_blob = { 0, 0 };
|
||||
ibase_db_link *ib_link;
|
||||
ibase_trans *trans = NULL;
|
||||
char bl_data[IBASE_BLOB_SEG];
|
||||
php_stream *stream;
|
||||
|
||||
RESET_ERRMSG;
|
||||
|
||||
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "r|r",
|
||||
(ZEND_NUM_ARGS()-1) ? &link : &file, &file)) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
PHP_IBASE_LINK_TRANS(link, ib_link, trans);
|
||||
|
||||
php_stream_from_zval(stream, file);
|
||||
|
||||
do {
|
||||
if (isc_create_blob(IB_STATUS, &ib_link->handle, &trans->handle, &ib_blob.bl_handle,
|
||||
&ib_blob.bl_qd)) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (size = 0; (b = php_stream_read(stream, bl_data, sizeof(bl_data))); size += b) {
|
||||
if (isc_put_segment(IB_STATUS, &ib_blob.bl_handle, b, bl_data)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isc_close_blob(IB_STATUS, &ib_blob.bl_handle)) {
|
||||
break;
|
||||
}
|
||||
RETURN_NEW_STR(_php_ibase_quad_to_string(ib_blob.bl_qd));
|
||||
} while (0);
|
||||
|
||||
_php_ibase_error();
|
||||
RETURN_FALSE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#endif /* HAVE_IBASE */
|
@ -1,392 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 7 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 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: Ard Biesheuvel <a.k.biesheuvel@its.tudelft.nl> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "php.h"
|
||||
|
||||
#if HAVE_IBASE
|
||||
|
||||
#include "php_interbase.h"
|
||||
#include "php_ibase_includes.h"
|
||||
|
||||
static int le_event;
|
||||
|
||||
static void _php_ibase_event_free(char *event_buf, char *result_buf) /* {{{ */
|
||||
{
|
||||
isc_free(event_buf);
|
||||
isc_free(result_buf);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
void _php_ibase_free_event(ibase_event *event) /* {{{ */
|
||||
{
|
||||
unsigned short i;
|
||||
|
||||
event->state = DEAD;
|
||||
|
||||
if (event->link != NULL) {
|
||||
ibase_event **node;
|
||||
|
||||
zend_list_delete(event->link_res);
|
||||
if (event->link->handle != 0 &&
|
||||
isc_cancel_events(IB_STATUS, &event->link->handle, &event->event_id)) {
|
||||
_php_ibase_error();
|
||||
}
|
||||
|
||||
/* delete this event from the link struct */
|
||||
for (node = &event->link->event_head; *node != event; node = &(*node)->event_next);
|
||||
*node = event->event_next;
|
||||
}
|
||||
|
||||
if (Z_TYPE(event->callback) != IS_UNDEF) {
|
||||
zval_ptr_dtor(&event->callback);
|
||||
ZVAL_UNDEF(&event->callback);
|
||||
|
||||
_php_ibase_event_free(event->event_buffer,event->result_buffer);
|
||||
|
||||
for (i = 0; i < event->event_count; ++i) {
|
||||
if (event->events[i]) {
|
||||
efree(event->events[i]);
|
||||
}
|
||||
}
|
||||
efree(event->events);
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static void _php_ibase_free_event_rsrc(zend_resource *rsrc) /* {{{ */
|
||||
{
|
||||
ibase_event *e = (ibase_event *) rsrc->ptr;
|
||||
|
||||
_php_ibase_free_event(e);
|
||||
|
||||
efree(e);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
void php_ibase_events_minit(INIT_FUNC_ARGS) /* {{{ */
|
||||
{
|
||||
le_event = zend_register_list_destructors_ex(_php_ibase_free_event_rsrc, NULL,
|
||||
"interbase event", module_number);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static void _php_ibase_event_block(ibase_db_link *ib_link, unsigned short count, /* {{{ */
|
||||
char **events, unsigned short *l, char **event_buf, char **result_buf)
|
||||
{
|
||||
ISC_STATUS dummy_result[20];
|
||||
ISC_ULONG dummy_count[15];
|
||||
|
||||
/**
|
||||
* Unfortunately, there's no clean and portable way in C to pass arguments to
|
||||
* a variadic function if you don't know the number of arguments at compile time.
|
||||
* (And even if there were a way, the Interbase API doesn't provide a version of
|
||||
* this function that takes a va_list as an argument)
|
||||
*
|
||||
* In this case, the number of arguments is limited to 18 by the underlying API,
|
||||
* so we can work around it.
|
||||
*/
|
||||
|
||||
*l = (unsigned short) isc_event_block(event_buf, result_buf, count, events[0],
|
||||
events[1], events[2], events[3], events[4], events[5], events[6], events[7],
|
||||
events[8], events[9], events[10], events[11], events[12], events[13], events[14]);
|
||||
|
||||
/**
|
||||
* Currently, this is the only way to correctly initialize an event buffer.
|
||||
* This is clearly something that should be fixed, cause the semantics of
|
||||
* isc_wait_for_event() indicate that it blocks until an event occurs.
|
||||
* If the Firebird people ever fix this, these lines should be removed,
|
||||
* otherwise, events will have to fire twice before ibase_wait_event() returns.
|
||||
*/
|
||||
|
||||
isc_wait_for_event(dummy_result, &ib_link->handle, *l, *event_buf, *result_buf);
|
||||
isc_event_counts(dummy_count, *l, *event_buf, *result_buf);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string ibase_wait_event([resource link_identifier,] string event [, string event [, ...]])
|
||||
Waits for any one of the passed Interbase events to be posted by the database, and returns its name */
|
||||
PHP_FUNCTION(ibase_wait_event)
|
||||
{
|
||||
zval *args;
|
||||
ibase_db_link *ib_link;
|
||||
int num_args;
|
||||
char *event_buffer, *result_buffer, *events[15];
|
||||
unsigned short i = 0, event_count = 0, buffer_size;
|
||||
ISC_ULONG occurred_event[15];
|
||||
|
||||
RESET_ERRMSG;
|
||||
|
||||
/* no more than 15 events */
|
||||
if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 16) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &num_args) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Z_TYPE(args[0]) == IS_RESOURCE) {
|
||||
if ((ib_link = (ibase_db_link *)zend_fetch_resource2_ex(&args[0], "InterBase link", le_link, le_plink)) == NULL) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
i = 1;
|
||||
} else {
|
||||
if (ZEND_NUM_ARGS() > 15) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
if ((ib_link = (ibase_db_link *)zend_fetch_resource2(IBG(default_link), "InterBase link", le_link, le_plink)) == NULL) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
for (; i < ZEND_NUM_ARGS(); ++i) {
|
||||
convert_to_string_ex(&args[i]);
|
||||
events[event_count++] = Z_STRVAL(args[i]);
|
||||
}
|
||||
|
||||
/* fills the required data structure with information about the events */
|
||||
_php_ibase_event_block(ib_link, event_count, events, &buffer_size, &event_buffer, &result_buffer);
|
||||
|
||||
/* now block until an event occurs */
|
||||
if (isc_wait_for_event(IB_STATUS, &ib_link->handle, buffer_size, event_buffer, result_buffer)) {
|
||||
_php_ibase_error();
|
||||
_php_ibase_event_free(event_buffer,result_buffer);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
/* find out which event occurred */
|
||||
isc_event_counts(occurred_event, buffer_size, event_buffer, result_buffer);
|
||||
for (i = 0; i < event_count; ++i) {
|
||||
if (occurred_event[i]) {
|
||||
zend_string *result = zend_string_init(events[i], strlen(events[i]), 0);
|
||||
_php_ibase_event_free(event_buffer,result_buffer);
|
||||
RETURN_STR(result);
|
||||
}
|
||||
}
|
||||
|
||||
/* If we reach this line, isc_wait_for_event() did return, but we don't know
|
||||
which event fired. */
|
||||
_php_ibase_event_free(event_buffer,result_buffer);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#if FB_API_VER >= 20
|
||||
#define PHP_ISC_CALLBACK ISC_EVENT_CALLBACK
|
||||
static ISC_EVENT_CALLBACK _php_ibase_callback(ibase_event *event, /* {{{ */
|
||||
ISC_USHORT buffer_size, ISC_UCHAR *result_buf)
|
||||
#else
|
||||
#define PHP_ISC_CALLBACK isc_callback
|
||||
static isc_callback _php_ibase_callback(ibase_event *event, /* {{{ */
|
||||
unsigned short buffer_size, char *result_buf)
|
||||
#endif
|
||||
{
|
||||
/* this function is called asynchronously by the Interbase client library. */
|
||||
TSRMLS_FETCH_FROM_CTX(event->thread_ctx);
|
||||
|
||||
/**
|
||||
* The callback function is called when the event is first registered and when the event
|
||||
* is cancelled. I consider this is a bug. By clearing event->callback first and setting
|
||||
* it to -1 later, we make sure nothing happens if no event was actually posted.
|
||||
*/
|
||||
switch (event->state) {
|
||||
unsigned short i;
|
||||
ISC_ULONG occurred_event[15];
|
||||
zval return_value, args[2];
|
||||
|
||||
default: /* == DEAD */
|
||||
break;
|
||||
case ACTIVE:
|
||||
/* copy the updated results into the result buffer */
|
||||
memcpy(event->result_buffer, result_buf, buffer_size);
|
||||
|
||||
ZVAL_RES(&args[1], event->link_res);
|
||||
|
||||
/* find out which event occurred */
|
||||
isc_event_counts(occurred_event, buffer_size, event->event_buffer, event->result_buffer);
|
||||
for (i = 0; i < event->event_count; ++i) {
|
||||
if (occurred_event[i]) {
|
||||
ZVAL_STRING(&args[0], event->events[i]);
|
||||
//efree(event->events[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* call the callback provided by the user */
|
||||
if (SUCCESS != call_user_function(NULL, NULL,
|
||||
&event->callback, &return_value, 2, args)) {
|
||||
_php_ibase_module_error("Error calling callback %s", Z_STRVAL(event->callback));
|
||||
break;
|
||||
}
|
||||
|
||||
if (Z_TYPE(return_value) == IS_FALSE) {
|
||||
event->state = DEAD;
|
||||
break;
|
||||
}
|
||||
case NEW:
|
||||
/* re-register the event */
|
||||
if (isc_que_events(IB_STATUS, &event->link->handle, &event->event_id, buffer_size,
|
||||
event->event_buffer,(PHP_ISC_CALLBACK)_php_ibase_callback, (void *)event)) {
|
||||
|
||||
_php_ibase_error();
|
||||
}
|
||||
event->state = ACTIVE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto resource ibase_set_event_handler([resource link_identifier,] callback handler, string event [, string event [, ...]])
|
||||
Register the callback for handling each of the named events */
|
||||
PHP_FUNCTION(ibase_set_event_handler)
|
||||
{
|
||||
/**
|
||||
* The callback passed to this function should take an event name (string) and a
|
||||
* link resource id (int) as arguments. The value returned from the function is
|
||||
* used to determine if the event handler should remain set.
|
||||
*/
|
||||
zval *args, *cb_arg;
|
||||
ibase_db_link *ib_link;
|
||||
ibase_event *event;
|
||||
unsigned short i = 1, buffer_size;
|
||||
int num_args;
|
||||
zend_resource *link_res;
|
||||
|
||||
RESET_ERRMSG;
|
||||
|
||||
/* Minimum and maximum number of arguments allowed */
|
||||
if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 17) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &num_args) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* get a working link */
|
||||
if (Z_TYPE(args[0]) != IS_STRING) {
|
||||
/* resource, callback, event_1 [, ... event_15]
|
||||
* No more than 15 events
|
||||
*/
|
||||
if (ZEND_NUM_ARGS() < 3 || ZEND_NUM_ARGS() > 17) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
|
||||
cb_arg = &args[1];
|
||||
i = 2;
|
||||
|
||||
if ((ib_link = (ibase_db_link *)zend_fetch_resource2_ex(&args[0], "InterBase link", le_link, le_plink)) == NULL) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
link_res = Z_RES(args[0]);
|
||||
|
||||
} else {
|
||||
/* callback, event_1 [, ... event_15]
|
||||
* No more than 15 events
|
||||
*/
|
||||
if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 16) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
|
||||
cb_arg = &args[0];
|
||||
|
||||
if ((ib_link = (ibase_db_link *)zend_fetch_resource2(IBG(default_link), "InterBase link", le_link, le_plink)) == NULL) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
link_res = IBG(default_link);
|
||||
}
|
||||
|
||||
/* get the callback */
|
||||
if (!zend_is_callable(cb_arg, 0, NULL)) {
|
||||
zend_string *cb_name = zend_get_callable_name(cb_arg);
|
||||
_php_ibase_module_error("Callback argument %s is not a callable function", ZSTR_VAL(cb_name));
|
||||
zend_string_release_ex(cb_name, 0);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
/* allocate the event resource */
|
||||
event = (ibase_event *) safe_emalloc(sizeof(ibase_event), 1, 0);
|
||||
TSRMLS_SET_CTX(event->thread_ctx);
|
||||
event->link_res = link_res;
|
||||
GC_ADDREF(link_res);
|
||||
event->link = ib_link;
|
||||
event->event_count = 0;
|
||||
event->state = NEW;
|
||||
event->events = (char **) safe_emalloc(sizeof(char *), 15, 0);
|
||||
|
||||
ZVAL_DUP(&event->callback, cb_arg);
|
||||
|
||||
for (; i < 15; ++i) {
|
||||
if (i < ZEND_NUM_ARGS()) {
|
||||
convert_to_string_ex(&args[i]);
|
||||
event->events[event->event_count++] = estrdup(Z_STRVAL(args[i]));
|
||||
} else {
|
||||
event->events[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* fills the required data structure with information about the events */
|
||||
_php_ibase_event_block(ib_link, event->event_count, event->events,
|
||||
&buffer_size, &event->event_buffer, &event->result_buffer);
|
||||
|
||||
/* now register the events with the Interbase API */
|
||||
if (isc_que_events(IB_STATUS, &ib_link->handle, &event->event_id, buffer_size,
|
||||
event->event_buffer,(PHP_ISC_CALLBACK)_php_ibase_callback, (void *)event)) {
|
||||
|
||||
_php_ibase_error();
|
||||
efree(event);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
event->event_next = ib_link->event_head;
|
||||
ib_link->event_head = event;
|
||||
|
||||
RETVAL_RES(zend_register_resource(event, le_event));
|
||||
Z_TRY_ADDREF_P(return_value);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool ibase_free_event_handler(resource event)
|
||||
Frees the event handler set by ibase_set_event_handler() */
|
||||
PHP_FUNCTION(ibase_free_event_handler)
|
||||
{
|
||||
zval *event_arg;
|
||||
|
||||
RESET_ERRMSG;
|
||||
|
||||
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "r", &event_arg)) {
|
||||
ibase_event *event;
|
||||
|
||||
event = (ibase_event *)zend_fetch_resource_ex(event_arg, "Interbase event", le_event);
|
||||
|
||||
event->state = DEAD;
|
||||
|
||||
zend_list_delete(Z_RES_P(event_arg));
|
||||
RETURN_TRUE;
|
||||
} else {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#endif /* HAVE_IBASE */
|
File diff suppressed because it is too large
Load Diff
@ -1,620 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 7 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 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: Ard Biesheuvel <a.k.biesheuvel@its.tudelft.nl> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "php.h"
|
||||
|
||||
#if HAVE_IBASE
|
||||
|
||||
#include "php_interbase.h"
|
||||
#include "php_ibase_includes.h"
|
||||
|
||||
typedef struct {
|
||||
isc_svc_handle handle;
|
||||
char *hostname;
|
||||
char *username;
|
||||
zend_resource *res;
|
||||
} ibase_service;
|
||||
|
||||
static int le_service;
|
||||
|
||||
static void _php_ibase_free_service(zend_resource *rsrc) /* {{{ */
|
||||
{
|
||||
ibase_service *sv = (ibase_service *) rsrc->ptr;
|
||||
|
||||
if (isc_service_detach(IB_STATUS, &sv->handle)) {
|
||||
_php_ibase_error();
|
||||
}
|
||||
|
||||
if (sv->hostname) {
|
||||
efree(sv->hostname);
|
||||
}
|
||||
if (sv->username) {
|
||||
efree(sv->username);
|
||||
}
|
||||
|
||||
efree(sv);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* the svc api seems to get confused after an error has occurred,
|
||||
so invalidate the handle on errors */
|
||||
#define IBASE_SVC_ERROR(svm) \
|
||||
do { zend_list_delete(svm->res); _php_ibase_error(); } while (0)
|
||||
|
||||
|
||||
void php_ibase_service_minit(INIT_FUNC_ARGS) /* {{{ */
|
||||
{
|
||||
le_service = zend_register_list_destructors_ex(_php_ibase_free_service, NULL,
|
||||
"interbase service manager handle", module_number);
|
||||
|
||||
/* backup options */
|
||||
REGISTER_LONG_CONSTANT("IBASE_BKP_IGNORE_CHECKSUMS", isc_spb_bkp_ignore_checksums, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_BKP_IGNORE_LIMBO", isc_spb_bkp_ignore_limbo, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_BKP_METADATA_ONLY", isc_spb_bkp_metadata_only, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_BKP_NO_GARBAGE_COLLECT", isc_spb_bkp_no_garbage_collect, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_BKP_OLD_DESCRIPTIONS", isc_spb_bkp_old_descriptions, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_BKP_NON_TRANSPORTABLE", isc_spb_bkp_non_transportable, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_BKP_CONVERT", isc_spb_bkp_convert, CONST_PERSISTENT);
|
||||
|
||||
/* restore options */
|
||||
REGISTER_LONG_CONSTANT("IBASE_RES_DEACTIVATE_IDX", isc_spb_res_deactivate_idx, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_RES_NO_SHADOW", isc_spb_res_no_shadow, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_RES_NO_VALIDITY", isc_spb_res_no_validity, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_RES_ONE_AT_A_TIME", isc_spb_res_one_at_a_time, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_RES_REPLACE", isc_spb_res_replace, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_RES_CREATE", isc_spb_res_create, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_RES_USE_ALL_SPACE", isc_spb_res_use_all_space, CONST_PERSISTENT);
|
||||
|
||||
/* manage options */
|
||||
REGISTER_LONG_CONSTANT("IBASE_PRP_PAGE_BUFFERS", isc_spb_prp_page_buffers, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_PRP_SWEEP_INTERVAL", isc_spb_prp_sweep_interval, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_PRP_SHUTDOWN_DB", isc_spb_prp_shutdown_db, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_PRP_DENY_NEW_TRANSACTIONS", isc_spb_prp_deny_new_transactions, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_PRP_DENY_NEW_ATTACHMENTS", isc_spb_prp_deny_new_attachments, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_PRP_RESERVE_SPACE", isc_spb_prp_reserve_space, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_PRP_RES_USE_FULL", isc_spb_prp_res_use_full, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_PRP_RES", isc_spb_prp_res, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_PRP_WRITE_MODE", isc_spb_prp_write_mode, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_PRP_WM_ASYNC", isc_spb_prp_wm_async, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_PRP_WM_SYNC", isc_spb_prp_wm_sync, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_PRP_ACCESS_MODE", isc_spb_prp_access_mode, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_PRP_AM_READONLY", isc_spb_prp_am_readonly, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_PRP_AM_READWRITE", isc_spb_prp_am_readwrite, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_PRP_SET_SQL_DIALECT", isc_spb_prp_set_sql_dialect, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_PRP_ACTIVATE", isc_spb_prp_activate, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_PRP_DB_ONLINE", isc_spb_prp_db_online, CONST_PERSISTENT);
|
||||
|
||||
/* repair options */
|
||||
REGISTER_LONG_CONSTANT("IBASE_RPR_CHECK_DB", isc_spb_rpr_check_db, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_RPR_IGNORE_CHECKSUM", isc_spb_rpr_ignore_checksum, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_RPR_KILL_SHADOWS", isc_spb_rpr_kill_shadows, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_RPR_MEND_DB", isc_spb_rpr_mend_db, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_RPR_VALIDATE_DB", isc_spb_rpr_validate_db, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_RPR_FULL", isc_spb_rpr_full, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_RPR_SWEEP_DB", isc_spb_rpr_sweep_db, CONST_PERSISTENT);
|
||||
|
||||
/* db info arguments */
|
||||
REGISTER_LONG_CONSTANT("IBASE_STS_DATA_PAGES", isc_spb_sts_data_pages, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_STS_DB_LOG", isc_spb_sts_db_log, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_STS_HDR_PAGES", isc_spb_sts_hdr_pages, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_STS_IDX_PAGES", isc_spb_sts_idx_pages, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_STS_SYS_RELATIONS", isc_spb_sts_sys_relations, CONST_PERSISTENT);
|
||||
|
||||
/* server info arguments */
|
||||
REGISTER_LONG_CONSTANT("IBASE_SVC_SERVER_VERSION", isc_info_svc_server_version, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_SVC_IMPLEMENTATION", isc_info_svc_implementation, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_SVC_GET_ENV", isc_info_svc_get_env, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_SVC_GET_ENV_LOCK", isc_info_svc_get_env_lock, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_SVC_GET_ENV_MSG", isc_info_svc_get_env_msg, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_SVC_USER_DBPATH", isc_info_svc_user_dbpath, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_SVC_SVR_DB_INFO", isc_info_svc_svr_db_info, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("IBASE_SVC_GET_USERS", isc_info_svc_get_users, CONST_PERSISTENT);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static void _php_ibase_user(INTERNAL_FUNCTION_PARAMETERS, char operation) /* {{{ */
|
||||
{
|
||||
/* user = 0, password = 1, first_name = 2, middle_name = 3, last_name = 4 */
|
||||
static char const user_flags[] = { isc_spb_sec_username, isc_spb_sec_password,
|
||||
isc_spb_sec_firstname, isc_spb_sec_middlename, isc_spb_sec_lastname };
|
||||
char buf[128], *args[] = { NULL, NULL, NULL, NULL, NULL };
|
||||
int i, args_len[] = { 0, 0, 0, 0, 0 };
|
||||
unsigned short spb_len = 1;
|
||||
zval *res;
|
||||
ibase_service *svm;
|
||||
|
||||
RESET_ERRMSG;
|
||||
|
||||
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(),
|
||||
(operation == isc_action_svc_delete_user) ? "rs" : "rss|sss",
|
||||
&res, &args[0], &args_len[0], &args[1], &args_len[1], &args[2], &args_len[2],
|
||||
&args[3], &args_len[3], &args[4], &args_len[4])) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
svm = (ibase_service *)zend_fetch_resource_ex(res, "Interbase service manager handle",
|
||||
le_service);
|
||||
|
||||
buf[0] = operation;
|
||||
|
||||
for (i = 0; i < sizeof(user_flags); ++i) {
|
||||
if (args[i] != NULL) {
|
||||
int chunk = slprintf(&buf[spb_len], sizeof(buf) - spb_len, "%c%c%c%s",
|
||||
user_flags[i], (char)args_len[i], (char)(args_len[i] >> 8), args[i]);
|
||||
|
||||
if ((spb_len + chunk) > sizeof(buf) || chunk <= 0) {
|
||||
_php_ibase_module_error("Internal error: insufficient buffer space for SPB (%d)", spb_len);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
spb_len += chunk;
|
||||
}
|
||||
}
|
||||
|
||||
/* now start the job */
|
||||
if (isc_service_start(IB_STATUS, &svm->handle, NULL, spb_len, buf)) {
|
||||
IBASE_SVC_ERROR(svm);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
RETURN_TRUE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool ibase_add_user(resource service_handle, string user_name, string password [, string first_name [, string middle_name [, string last_name]]])
|
||||
Add a user to security database */
|
||||
PHP_FUNCTION(ibase_add_user)
|
||||
{
|
||||
_php_ibase_user(INTERNAL_FUNCTION_PARAM_PASSTHRU, isc_action_svc_add_user);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool ibase_modify_user(resource service_handle, string user_name, string password [, string first_name [, string middle_name [, string last_name]]])
|
||||
Modify a user in security database */
|
||||
PHP_FUNCTION(ibase_modify_user)
|
||||
{
|
||||
_php_ibase_user(INTERNAL_FUNCTION_PARAM_PASSTHRU, isc_action_svc_modify_user);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool ibase_delete_user(resource service_handle, string user_name, string password [, string first_name [, string middle_name [, string last_name]]])
|
||||
Delete a user from security database */
|
||||
PHP_FUNCTION(ibase_delete_user)
|
||||
{
|
||||
_php_ibase_user(INTERNAL_FUNCTION_PARAM_PASSTHRU, isc_action_svc_delete_user);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto resource ibase_service_attach(string host, string dba_username, string dba_password)
|
||||
Connect to the service manager */
|
||||
PHP_FUNCTION(ibase_service_attach)
|
||||
{
|
||||
size_t hlen, ulen, plen, spb_len;
|
||||
ibase_service *svm;
|
||||
char buf[128], *host, *user, *pass, *loc;
|
||||
isc_svc_handle handle = 0;
|
||||
|
||||
RESET_ERRMSG;
|
||||
|
||||
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "sss",
|
||||
&host, &hlen, &user, &ulen, &pass, &plen)) {
|
||||
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
/* construct the spb, hack the service name into it as well */
|
||||
spb_len = slprintf(buf, sizeof(buf), "%c%c%c%c%s%c%c%s" "%s:service_mgr",
|
||||
isc_spb_version, isc_spb_current_version, isc_spb_user_name, (char)ulen,
|
||||
user, isc_spb_password, (char)plen, pass, host);
|
||||
|
||||
if (spb_len > sizeof(buf) || spb_len == -1) {
|
||||
_php_ibase_module_error("Internal error: insufficient buffer space for SPB (%zd)", spb_len);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
spb_len -= hlen + 12;
|
||||
loc = buf + spb_len; /* points to %s:service_mgr part */
|
||||
|
||||
/* attach to the service manager */
|
||||
if (isc_service_attach(IB_STATUS, 0, loc, &handle, (unsigned short)spb_len, buf)) {
|
||||
_php_ibase_error();
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
svm = (ibase_service*)emalloc(sizeof(ibase_service));
|
||||
svm->handle = handle;
|
||||
svm->hostname = estrdup(host);
|
||||
svm->username = estrdup(user);
|
||||
|
||||
RETVAL_RES(zend_register_resource(svm, le_service));
|
||||
Z_TRY_ADDREF_P(return_value);
|
||||
svm->res = Z_RES_P(return_value);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool ibase_service_detach(resource service_handle)
|
||||
Disconnect from the service manager */
|
||||
PHP_FUNCTION(ibase_service_detach)
|
||||
{
|
||||
zval *res;
|
||||
|
||||
RESET_ERRMSG;
|
||||
|
||||
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "r", &res)) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
zend_list_delete(Z_RES_P(res));
|
||||
|
||||
RETURN_TRUE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static void _php_ibase_service_query(INTERNAL_FUNCTION_PARAMETERS, /* {{{ */
|
||||
ibase_service *svm, char info_action)
|
||||
{
|
||||
static char spb[] = { isc_info_svc_timeout, 10, 0, 0, 0 };
|
||||
|
||||
char res_buf[400], *result, *heap_buf = NULL, *heap_p;
|
||||
zend_long heap_buf_size = 200, line_len;
|
||||
|
||||
/* info about users requires an action first */
|
||||
if (info_action == isc_info_svc_get_users) {
|
||||
static char action[] = { isc_action_svc_display_user };
|
||||
|
||||
if (isc_service_start(IB_STATUS, &svm->handle, NULL, sizeof(action), action)) {
|
||||
IBASE_SVC_ERROR(svm);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
query_loop:
|
||||
result = res_buf;
|
||||
|
||||
if (isc_service_query(IB_STATUS, &svm->handle, NULL, sizeof(spb), spb,
|
||||
1, &info_action, sizeof(res_buf), res_buf)) {
|
||||
|
||||
IBASE_SVC_ERROR(svm);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
while (*result != isc_info_end) {
|
||||
switch (*result++) {
|
||||
default:
|
||||
RETURN_FALSE;
|
||||
|
||||
case isc_info_svc_line:
|
||||
if (! (line_len = isc_vax_integer(result, 2))) {
|
||||
/* done */
|
||||
if (heap_buf) {
|
||||
RETVAL_STRING(heap_buf);
|
||||
efree(heap_buf);
|
||||
return;
|
||||
} else {
|
||||
RETURN_TRUE;
|
||||
}
|
||||
}
|
||||
if (!heap_buf || (heap_p - heap_buf + line_len +2) > heap_buf_size) {
|
||||
zend_long res_size = heap_buf ? heap_p - heap_buf : 0;
|
||||
|
||||
while (heap_buf_size < (res_size + line_len +2)) {
|
||||
heap_buf_size *= 2;
|
||||
}
|
||||
heap_buf = (char*) erealloc(heap_buf, heap_buf_size);
|
||||
heap_p = heap_buf + res_size;
|
||||
}
|
||||
result += 2;
|
||||
*(result+line_len) = 0;
|
||||
snprintf(heap_p, heap_buf_size - (heap_p - heap_buf), "%s\n", result);
|
||||
heap_p += line_len +1;
|
||||
goto query_loop; /* repeat until result is exhausted */
|
||||
|
||||
case isc_info_svc_server_version:
|
||||
case isc_info_svc_implementation:
|
||||
case isc_info_svc_get_env:
|
||||
case isc_info_svc_get_env_lock:
|
||||
case isc_info_svc_get_env_msg:
|
||||
case isc_info_svc_user_dbpath:
|
||||
RETURN_STRINGL(result + 2, isc_vax_integer(result, 2));
|
||||
|
||||
case isc_info_svc_svr_db_info:
|
||||
array_init(return_value);
|
||||
|
||||
do {
|
||||
switch (*result++) {
|
||||
int len;
|
||||
|
||||
case isc_spb_num_att:
|
||||
add_assoc_long(return_value, "attachments", isc_vax_integer(result,4));
|
||||
result += 4;
|
||||
break;
|
||||
|
||||
case isc_spb_num_db:
|
||||
add_assoc_long(return_value, "databases", isc_vax_integer(result,4));
|
||||
result += 4;
|
||||
break;
|
||||
|
||||
case isc_spb_dbname:
|
||||
len = isc_vax_integer(result,2);
|
||||
add_next_index_stringl(return_value, result +2, len);
|
||||
result += len+2;
|
||||
}
|
||||
} while (*result != isc_info_flag_end);
|
||||
return;
|
||||
|
||||
case isc_info_svc_get_users: {
|
||||
zval user;
|
||||
array_init(return_value);
|
||||
|
||||
while (*result != isc_info_end) {
|
||||
|
||||
switch (*result++) {
|
||||
int len;
|
||||
|
||||
case isc_spb_sec_username:
|
||||
/* it appears that the username is always first */
|
||||
array_init(&user);
|
||||
add_next_index_zval(return_value, &user);
|
||||
|
||||
len = isc_vax_integer(result,2);
|
||||
add_assoc_stringl(&user, "user_name", result +2, len);
|
||||
result += len+2;
|
||||
break;
|
||||
|
||||
case isc_spb_sec_firstname:
|
||||
len = isc_vax_integer(result,2);
|
||||
add_assoc_stringl(&user, "first_name", result +2, len);
|
||||
result += len+2;
|
||||
break;
|
||||
|
||||
case isc_spb_sec_middlename:
|
||||
len = isc_vax_integer(result,2);
|
||||
add_assoc_stringl(&user, "middle_name", result +2, len);
|
||||
result += len+2;
|
||||
break;
|
||||
|
||||
case isc_spb_sec_lastname:
|
||||
len = isc_vax_integer(result,2);
|
||||
add_assoc_stringl(&user, "last_name", result +2, len);
|
||||
result += len+2;
|
||||
break;
|
||||
|
||||
case isc_spb_sec_userid:
|
||||
add_assoc_long(&user, "user_id", isc_vax_integer(result, 4));
|
||||
result += 4;
|
||||
break;
|
||||
|
||||
case isc_spb_sec_groupid:
|
||||
add_assoc_long(&user, "group_id", isc_vax_integer(result, 4));
|
||||
result += 4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static void _php_ibase_backup_restore(INTERNAL_FUNCTION_PARAMETERS, char operation) /* {{{ */
|
||||
{
|
||||
/**
|
||||
* It appears that the service API is a little bit confused about which flag
|
||||
* to use for the source and destination in the case of a restore operation.
|
||||
* When passing the backup file as isc_spb_dbname and the destination db as
|
||||
* bpk_file, things work well.
|
||||
*/
|
||||
zval *res;
|
||||
char *db, *bk, buf[200];
|
||||
size_t dblen, bklen, spb_len;
|
||||
zend_long opts = 0;
|
||||
zend_bool verbose = 0;
|
||||
ibase_service *svm;
|
||||
|
||||
RESET_ERRMSG;
|
||||
|
||||
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "rss|lb",
|
||||
&res, &db, &dblen, &bk, &bklen, &opts, &verbose)) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
svm = (ibase_service *)zend_fetch_resource_ex(res,
|
||||
"Interbase service manager handle", le_service);
|
||||
|
||||
/* fill the param buffer */
|
||||
spb_len = slprintf(buf, sizeof(buf), "%c%c%c%c%s%c%c%c%s%c%c%c%c%c",
|
||||
operation, isc_spb_dbname, (char)dblen, (char)(dblen >> 8), db,
|
||||
isc_spb_bkp_file, (char)bklen, (char)(bklen >> 8), bk, isc_spb_options,
|
||||
(char)opts,(char)(opts >> 8), (char)(opts >> 16), (char)(opts >> 24));
|
||||
|
||||
if (verbose) {
|
||||
buf[spb_len++] = isc_spb_verbose;
|
||||
}
|
||||
|
||||
if (spb_len > sizeof(buf) || spb_len <= 0) {
|
||||
_php_ibase_module_error("Internal error: insufficient buffer space for SPB (%zd)", spb_len);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
/* now start the backup/restore job */
|
||||
if (isc_service_start(IB_STATUS, &svm->handle, NULL, (unsigned short)spb_len, buf)) {
|
||||
IBASE_SVC_ERROR(svm);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (!verbose) {
|
||||
RETURN_TRUE;
|
||||
} else {
|
||||
_php_ibase_service_query(INTERNAL_FUNCTION_PARAM_PASSTHRU, svm, isc_info_svc_line);
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto mixed ibase_backup(resource service_handle, string source_db, string dest_file [, int options [, bool verbose]])
|
||||
Initiates a backup task in the service manager and returns immediately */
|
||||
PHP_FUNCTION(ibase_backup)
|
||||
{
|
||||
_php_ibase_backup_restore(INTERNAL_FUNCTION_PARAM_PASSTHRU, isc_action_svc_backup);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto mixed ibase_restore(resource service_handle, string source_file, string dest_db [, int options [, bool verbose]])
|
||||
Initiates a restore task in the service manager and returns immediately */
|
||||
PHP_FUNCTION(ibase_restore)
|
||||
{
|
||||
_php_ibase_backup_restore(INTERNAL_FUNCTION_PARAM_PASSTHRU, isc_action_svc_restore);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static void _php_ibase_service_action(INTERNAL_FUNCTION_PARAMETERS, char svc_action) /* {{{ */
|
||||
{
|
||||
zval *res;
|
||||
char buf[128], *db;
|
||||
size_t dblen;
|
||||
int spb_len;
|
||||
zend_long action, argument = 0;
|
||||
ibase_service *svm;
|
||||
|
||||
RESET_ERRMSG;
|
||||
|
||||
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "rsl|l",
|
||||
&res, &db, &dblen, &action, &argument)) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
svm = (ibase_service *)zend_fetch_resource_ex(res,
|
||||
"Interbase service manager handle", le_service);
|
||||
|
||||
if (svc_action == isc_action_svc_db_stats) {
|
||||
switch (action) {
|
||||
default:
|
||||
goto unknown_option;
|
||||
|
||||
case isc_spb_sts_data_pages:
|
||||
case isc_spb_sts_db_log:
|
||||
case isc_spb_sts_hdr_pages:
|
||||
case isc_spb_sts_idx_pages:
|
||||
case isc_spb_sts_sys_relations:
|
||||
goto options_argument;
|
||||
}
|
||||
} else {
|
||||
/* these actions all expect different types of arguments */
|
||||
switch (action) {
|
||||
default:
|
||||
unknown_option:
|
||||
_php_ibase_module_error("Unrecognised option (" ZEND_LONG_FMT ")", action);
|
||||
RETURN_FALSE;
|
||||
|
||||
case isc_spb_rpr_check_db:
|
||||
case isc_spb_rpr_ignore_checksum:
|
||||
case isc_spb_rpr_kill_shadows:
|
||||
case isc_spb_rpr_mend_db:
|
||||
case isc_spb_rpr_validate_db:
|
||||
case isc_spb_rpr_sweep_db:
|
||||
svc_action = isc_action_svc_repair;
|
||||
|
||||
case isc_spb_prp_activate:
|
||||
case isc_spb_prp_db_online:
|
||||
options_argument:
|
||||
argument |= action;
|
||||
action = isc_spb_options;
|
||||
|
||||
case isc_spb_prp_page_buffers:
|
||||
case isc_spb_prp_sweep_interval:
|
||||
case isc_spb_prp_shutdown_db:
|
||||
case isc_spb_prp_deny_new_transactions:
|
||||
case isc_spb_prp_deny_new_attachments:
|
||||
case isc_spb_prp_set_sql_dialect:
|
||||
spb_len = slprintf(buf, sizeof(buf), "%c%c%c%c%s%c%c%c%c%c",
|
||||
svc_action, isc_spb_dbname, (char)dblen, (char)(dblen >> 8), db,
|
||||
(char)action, (char)argument, (char)(argument >> 8), (char)(argument >> 16),
|
||||
(char)(argument >> 24));
|
||||
break;
|
||||
|
||||
case isc_spb_prp_reserve_space:
|
||||
case isc_spb_prp_write_mode:
|
||||
case isc_spb_prp_access_mode:
|
||||
spb_len = slprintf(buf, sizeof(buf), "%c%c%c%c%s%c%c",
|
||||
isc_action_svc_properties, isc_spb_dbname, (char)dblen, (char)(dblen >> 8),
|
||||
db, (char)action, (char)argument);
|
||||
}
|
||||
}
|
||||
|
||||
if (spb_len > sizeof(buf) || spb_len == -1) {
|
||||
_php_ibase_module_error("Internal error: insufficient buffer space for SPB (%d)", spb_len);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (isc_service_start(IB_STATUS, &svm->handle, NULL, (unsigned short)spb_len, buf)) {
|
||||
IBASE_SVC_ERROR(svm);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (svc_action == isc_action_svc_db_stats) {
|
||||
_php_ibase_service_query(INTERNAL_FUNCTION_PARAM_PASSTHRU, svm, isc_info_svc_line);
|
||||
} else {
|
||||
RETURN_TRUE;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool ibase_maintain_db(resource service_handle, string db, int action [, int argument])
|
||||
Execute a maintenance command on the database server */
|
||||
PHP_FUNCTION(ibase_maintain_db)
|
||||
{
|
||||
_php_ibase_service_action(INTERNAL_FUNCTION_PARAM_PASSTHRU, isc_action_svc_properties);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string ibase_db_info(resource service_handle, string db, int action [, int argument])
|
||||
Request statistics about a database */
|
||||
PHP_FUNCTION(ibase_db_info)
|
||||
{
|
||||
_php_ibase_service_action(INTERNAL_FUNCTION_PARAM_PASSTHRU, isc_action_svc_db_stats);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string ibase_server_info(resource service_handle, int action)
|
||||
Request information about a database server */
|
||||
PHP_FUNCTION(ibase_server_info)
|
||||
{
|
||||
zval *res;
|
||||
zend_long action;
|
||||
ibase_service *svm;
|
||||
|
||||
RESET_ERRMSG;
|
||||
|
||||
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &res, &action)) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
svm = (ibase_service *)zend_fetch_resource_ex(res,
|
||||
"Interbase service manager handle", le_service);
|
||||
|
||||
_php_ibase_service_query(INTERNAL_FUNCTION_PARAM_PASSTHRU, svm, (char)action);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#else
|
||||
|
||||
void php_ibase_register_service_constants(INIT_FUNC_ARGS) { /* nop */ }
|
||||
|
||||
#endif /* HAVE_IBASE */
|
File diff suppressed because it is too large
Load Diff
@ -1,193 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 7 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 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: Jouni Ahto <jouni.ahto@exdec.fi> |
|
||||
| Andrew Avdeev <andy@simgts.mv.ru> |
|
||||
| Ard Biesheuvel <a.k.biesheuvel@ewi.tudelft.nl> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#ifndef PHP_IBASE_INCLUDES_H
|
||||
#define PHP_IBASE_INCLUDES_H
|
||||
|
||||
#include <ibase.h>
|
||||
|
||||
#ifndef SQLDA_CURRENT_VERSION
|
||||
#define SQLDA_CURRENT_VERSION SQLDA_VERSION1
|
||||
#endif
|
||||
|
||||
#ifndef METADATALENGTH
|
||||
#define METADATALENGTH 68
|
||||
#endif
|
||||
|
||||
#define RESET_ERRMSG do { IBG(errmsg)[0] = '\0'; IBG(sql_code) = 0; } while (0)
|
||||
|
||||
#define IB_STATUS (IBG(status))
|
||||
|
||||
#ifdef IBASE_DEBUG
|
||||
#define IBDEBUG(a) php_printf("::: %s (%d)\n", a, __LINE__);
|
||||
#endif
|
||||
|
||||
#ifndef IBDEBUG
|
||||
#define IBDEBUG(a)
|
||||
#endif
|
||||
|
||||
extern int le_link, le_plink, le_trans;
|
||||
|
||||
#define LE_LINK "Firebird/InterBase link"
|
||||
#define LE_PLINK "Firebird/InterBase persistent link"
|
||||
#define LE_TRANS "Firebird/InterBase transaction"
|
||||
|
||||
#define IBASE_MSGSIZE 512
|
||||
#define MAX_ERRMSG (IBASE_MSGSIZE*2)
|
||||
|
||||
#define IB_DEF_DATE_FMT "%Y-%m-%d"
|
||||
#define IB_DEF_TIME_FMT "%H:%M:%S"
|
||||
|
||||
/* this value should never be > USHRT_MAX */
|
||||
#define IBASE_BLOB_SEG 4096
|
||||
|
||||
ZEND_BEGIN_MODULE_GLOBALS(ibase)
|
||||
ISC_STATUS status[20];
|
||||
zend_resource *default_link;
|
||||
zend_long num_links, num_persistent;
|
||||
char errmsg[MAX_ERRMSG];
|
||||
zend_long sql_code;
|
||||
ZEND_END_MODULE_GLOBALS(ibase)
|
||||
|
||||
ZEND_EXTERN_MODULE_GLOBALS(ibase)
|
||||
|
||||
typedef struct {
|
||||
isc_db_handle handle;
|
||||
struct tr_list *tr_list;
|
||||
unsigned short dialect;
|
||||
struct event *event_head;
|
||||
} ibase_db_link;
|
||||
|
||||
typedef struct {
|
||||
isc_tr_handle handle;
|
||||
unsigned short link_cnt;
|
||||
unsigned long affected_rows;
|
||||
ibase_db_link *db_link[1]; /* last member */
|
||||
} ibase_trans;
|
||||
|
||||
typedef struct tr_list {
|
||||
ibase_trans *trans;
|
||||
struct tr_list *next;
|
||||
} ibase_tr_list;
|
||||
|
||||
typedef struct {
|
||||
isc_blob_handle bl_handle;
|
||||
unsigned short type;
|
||||
ISC_QUAD bl_qd;
|
||||
} ibase_blob;
|
||||
|
||||
typedef struct event {
|
||||
ibase_db_link *link;
|
||||
zend_resource* link_res;
|
||||
ISC_LONG event_id;
|
||||
unsigned short event_count;
|
||||
char **events;
|
||||
char *event_buffer, *result_buffer;
|
||||
zval callback;
|
||||
void *thread_ctx;
|
||||
struct event *event_next;
|
||||
enum event_state { NEW, ACTIVE, DEAD } state;
|
||||
} ibase_event;
|
||||
|
||||
enum php_interbase_option {
|
||||
PHP_IBASE_DEFAULT = 0,
|
||||
PHP_IBASE_CREATE = 0,
|
||||
/* fetch flags */
|
||||
PHP_IBASE_FETCH_BLOBS = 1,
|
||||
PHP_IBASE_FETCH_ARRAYS = 2,
|
||||
PHP_IBASE_UNIXTIME = 4,
|
||||
/* transaction access mode */
|
||||
PHP_IBASE_WRITE = 1,
|
||||
PHP_IBASE_READ = 2,
|
||||
/* transaction isolation level */
|
||||
PHP_IBASE_CONCURRENCY = 4,
|
||||
PHP_IBASE_COMMITTED = 8,
|
||||
PHP_IBASE_REC_NO_VERSION = 32,
|
||||
PHP_IBASE_REC_VERSION = 64,
|
||||
PHP_IBASE_CONSISTENCY = 16,
|
||||
/* transaction lock resolution */
|
||||
PHP_IBASE_WAIT = 128,
|
||||
PHP_IBASE_NOWAIT = 256
|
||||
};
|
||||
|
||||
#define IBG(v) ZEND_MODULE_GLOBALS_ACCESSOR(ibase, v)
|
||||
|
||||
#if defined(ZTS) && defined(COMPILE_DL_INTERBASE)
|
||||
ZEND_TSRMLS_CACHE_EXTERN()
|
||||
#endif
|
||||
|
||||
#define BLOB_ID_LEN 18
|
||||
#define BLOB_ID_MASK "0x%" LL_MASK "x"
|
||||
|
||||
#define BLOB_INPUT 1
|
||||
#define BLOB_OUTPUT 2
|
||||
|
||||
#ifdef PHP_WIN32
|
||||
#define LL_MASK "I64"
|
||||
#define LL_LIT(lit) lit ## I64
|
||||
typedef void (__stdcall *info_func_t)(char*);
|
||||
#else
|
||||
#define LL_MASK "ll"
|
||||
#define LL_LIT(lit) lit ## ll
|
||||
typedef void (*info_func_t)(char*);
|
||||
#endif
|
||||
|
||||
void _php_ibase_error(void);
|
||||
void _php_ibase_module_error(char *, ...)
|
||||
PHP_ATTRIBUTE_FORMAT(printf,1,2);
|
||||
|
||||
/* determine if a resource is a link or transaction handle */
|
||||
#define PHP_IBASE_LINK_TRANS(zv, lh, th) \
|
||||
do { \
|
||||
if (!zv) { \
|
||||
lh = (ibase_db_link *)zend_fetch_resource2( \
|
||||
IBG(default_link), "InterBase link", le_link, le_plink); \
|
||||
} else { \
|
||||
_php_ibase_get_link_trans(INTERNAL_FUNCTION_PARAM_PASSTHRU, zv, &lh, &th); \
|
||||
} \
|
||||
if (SUCCESS != _php_ibase_def_trans(lh, &th)) { RETURN_FALSE; } \
|
||||
} while (0)
|
||||
|
||||
int _php_ibase_def_trans(ibase_db_link *ib_link, ibase_trans **trans);
|
||||
void _php_ibase_get_link_trans(INTERNAL_FUNCTION_PARAMETERS, zval *link_id,
|
||||
ibase_db_link **ib_link, ibase_trans **trans);
|
||||
|
||||
/* provided by ibase_query.c */
|
||||
void php_ibase_query_minit(INIT_FUNC_ARGS);
|
||||
|
||||
/* provided by ibase_blobs.c */
|
||||
void php_ibase_blobs_minit(INIT_FUNC_ARGS);
|
||||
int _php_ibase_string_to_quad(char const *id, ISC_QUAD *qd);
|
||||
zend_string *_php_ibase_quad_to_string(ISC_QUAD const qd);
|
||||
int _php_ibase_blob_get(zval *return_value, ibase_blob *ib_blob, zend_ulong max_len);
|
||||
int _php_ibase_blob_add(zval *string_arg, ibase_blob *ib_blob);
|
||||
|
||||
/* provided by ibase_events.c */
|
||||
void php_ibase_events_minit(INIT_FUNC_ARGS);
|
||||
void _php_ibase_free_event(ibase_event *event);
|
||||
|
||||
/* provided by ibase_service.c */
|
||||
void php_ibase_service_minit(INIT_FUNC_ARGS);
|
||||
|
||||
#ifndef max
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
#endif
|
||||
|
||||
#endif /* PHP_IBASE_INCLUDES_H */
|
@ -1,406 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 7 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 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. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Ard Biesheuvel <a.k.biesheuvel@ewi.tudelft.nl> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* This UDF library adds the ability to call PHP functions from SQL
|
||||
* statements. Because of SQL's strong typing, you will have to declare
|
||||
* an external function for every combination { output type, #args } that
|
||||
* your application requires.
|
||||
*
|
||||
* Declare the functions like this:
|
||||
*
|
||||
* DECLARE EXTERNAL FUNCTION CALL_PHP1
|
||||
* CSTRING(xx),
|
||||
* <return type> BY DESCRIPTOR,
|
||||
* INTEGER BY DESCRIPTOR
|
||||
* RETURNS PARAMETER 2
|
||||
* ENTRY_POINT 'udf_call_php1' MODULE_NAME 'php_ibase_udf'
|
||||
*
|
||||
* DECLARE EXTERNAL FUNCTION CALL_PHP2
|
||||
* CSTRING(xx),
|
||||
* <return type> BY DESCRIPTOR,
|
||||
* INTEGER BY DESCRIPTOR,
|
||||
* INTEGER BY DESCRIPTOR
|
||||
* RETURNS PARAMETER 2
|
||||
* ENTRY_POINT 'udf_call_php2' MODULE_NAME 'php_ibase_udf'
|
||||
*
|
||||
* ... and so on. [for up to 8 input arguments]
|
||||
*
|
||||
* The first input parameter contains the name of the PHP function you want
|
||||
* to call. The second argument is the result. (omit this argument when calling
|
||||
* the function) The return type of the function is the declared type of the
|
||||
* result. The value returned from the PHP function being called will
|
||||
* automatically be converted if necessary.
|
||||
* The arguments should have their types declared as well, but you're free
|
||||
* to pass arguments of other types instead. They will be converted to the
|
||||
* best matching PHP type before being passed to the PHP function.
|
||||
*
|
||||
* The declared functions can be called from SQL like:
|
||||
*
|
||||
* SELECT * FROM <table> WHERE CALL_PHP1('soundex',<field>) NOT LIKE ?
|
||||
* or
|
||||
* UPDATE <table> SET <field> = CALL_PHP1('ucwords',<field>)
|
||||
*
|
||||
* Additionally, there's a function 'exec_php' which allows the contents
|
||||
* of text BLOB fields to be parsed and executed by PHP. This is most useful
|
||||
* for declaring functions that can then be called with CALL_PHPx.
|
||||
*
|
||||
* DECLARE EXTERNAL FUNCTION EXEC_PHP
|
||||
* BLOB,
|
||||
* INTEGER BY DESCRIPTOR,
|
||||
* SMALLINT
|
||||
* RETURNS PARAMETER 2
|
||||
* ENTRY_POINT 'exec_php' MODULE_NAME 'php_ibase_udf'
|
||||
*
|
||||
* The function will return 1 if execution succeeded and 0 if an error
|
||||
* occurred. The result that is returned from the executed PHP code is
|
||||
* ignored. You can pass a non-zero value as second argument to force
|
||||
* the embedded PHP engine to re-initialise.
|
||||
*
|
||||
* There are several ways to build this library, depending on which way the
|
||||
* database is accessed. If you're using the classic server on a local
|
||||
* connection, you should compile the library like this:
|
||||
*
|
||||
* gcc -shared `php-config --includes` `php-config --ldflags` \
|
||||
* `php-config --libs` -o php_ibase_udf.so php_ibase_udf.c
|
||||
*
|
||||
* If you connect to the classic server by TCP/IP, you should build the
|
||||
* PHP embedded static library and link against that.
|
||||
*
|
||||
* gcc -shared `php-config --includes` `php-config --ldflags` \
|
||||
* `php-config --libs` -o php_ibase_udf.so php_ibase_udf.c \
|
||||
* /usr/lib/libphp7.a
|
||||
*
|
||||
* If you use the super server, you should also link against the embedded
|
||||
* library, but be sure to enable thread safety, as the super server is
|
||||
* multi-threaded. After building, copy the resulting file to the folder
|
||||
* where your database expects to find its UDFs.
|
||||
*/
|
||||
|
||||
#include "zend.h"
|
||||
#include "zend_API.h"
|
||||
|
||||
#include "php.h"
|
||||
#include "php_ini.h"
|
||||
|
||||
#include "ibase.h"
|
||||
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
|
||||
#ifdef PHP_WIN32
|
||||
#define LL_LIT(lit) lit ## I64
|
||||
#else
|
||||
#define LL_LIT(lit) lit ## ll
|
||||
#endif
|
||||
|
||||
#ifdef ZTS
|
||||
# include <pthread.h>
|
||||
|
||||
static void ***tsrm_ls;
|
||||
pthread_mutex_t mtx_res = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
#define LOCK() do { pthread_mutex_lock(&mtx_res); } while (0)
|
||||
#define UNLOCK() do { pthread_mutex_unlock(&mtx_res); } while (0)
|
||||
#else
|
||||
#define LOCK()
|
||||
#define UNLOCK()
|
||||
#endif
|
||||
|
||||
#ifdef PHP_EMBED
|
||||
# include "php_main.h"
|
||||
# include "sapi/embed/php_embed.h"
|
||||
|
||||
static void __attribute__((constructor)) init()
|
||||
{
|
||||
php_embed_init(0, NULL P);
|
||||
}
|
||||
|
||||
static void __attribute__((destructor)) fini()
|
||||
{
|
||||
php_embed_shutdown();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Gets the contents of the BLOB b and offers it to Zend for parsing/execution
|
||||
*/
|
||||
void exec_php(BLOBCALLBACK b, PARAMDSC *res, ISC_SHORT *init)
|
||||
{
|
||||
int result, remaining = b->blob_total_length, i = 0;
|
||||
char *code = pemalloc(remaining+1, 1);
|
||||
ISC_USHORT read;
|
||||
|
||||
for (code[remaining] = '\0'; remaining > 0; remaining -= read)
|
||||
b->blob_get_segment(b->blob_handle, &code[i++<<16],min(0x10000,remaining), &read);
|
||||
|
||||
LOCK();
|
||||
|
||||
switch (init && *init) {
|
||||
|
||||
default:
|
||||
#ifdef PHP_EMBED
|
||||
php_request_shutdown(NULL);
|
||||
if (FAILURE == (result = php_request_startup())) {
|
||||
break;
|
||||
}
|
||||
case 0:
|
||||
#endif
|
||||
/* feed it to the parser */
|
||||
zend_first_try {
|
||||
result = zend_eval_stringl(code, b->blob_total_length, NULL, "Firebird Embedded PHP engine");
|
||||
} zend_end_try();
|
||||
}
|
||||
|
||||
UNLOCK();
|
||||
|
||||
free(code);
|
||||
|
||||
res->dsc_dtype = dtype_long;
|
||||
*(ISC_LONG*)res->dsc_address = (result == SUCCESS);
|
||||
}
|
||||
|
||||
static ISC_INT64 const scales[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 100000000, 1000000000,
|
||||
1000000000, LL_LIT(10000000000),LL_LIT(100000000000),LL_LIT(10000000000000),LL_LIT(100000000000000),
|
||||
LL_LIT(1000000000000000),LL_LIT(1000000000000000),LL_LIT(1000000000000000000) };
|
||||
|
||||
|
||||
static void call_php(char *name, PARAMDSC *r, int argc, PARAMDSC **argv)
|
||||
{
|
||||
do {
|
||||
zval callback, args[4], return_value;
|
||||
PARAMVARY *res = (PARAMVARY*)r->dsc_address;
|
||||
int i;
|
||||
|
||||
ZVAL_STRING(&callback, name);
|
||||
|
||||
LOCK();
|
||||
|
||||
/* check if the requested function exists */
|
||||
if (!zend_is_callable(&callback, 0, NULL)) {
|
||||
break;
|
||||
}
|
||||
|
||||
UNLOCK();
|
||||
|
||||
/* create the argument array */
|
||||
for (i = 0; i < argc; ++i) {
|
||||
|
||||
/* test arg for null */
|
||||
if (argv[i]->dsc_flags & DSC_null) {
|
||||
ZVAL_NULL(&args[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (argv[i]->dsc_dtype) {
|
||||
ISC_INT64 l;
|
||||
struct tm t;
|
||||
char const *fmt;
|
||||
char d[64];
|
||||
|
||||
case dtype_cstring:
|
||||
//???
|
||||
ZVAL_STRING(&args[i], (char*)argv[i]->dsc_address);
|
||||
break;
|
||||
|
||||
case dtype_text:
|
||||
//???
|
||||
ZVAL_STRINGL(&args[i], (char*)argv[i]->dsc_address, argv[i]->dsc_length);
|
||||
break;
|
||||
|
||||
case dtype_varying:
|
||||
//???
|
||||
ZVAL_STRINGL(&args[i], ((PARAMVARY*)argv[i]->dsc_address)->vary_string,
|
||||
((PARAMVARY*)argv[i]->dsc_address)->vary_length);
|
||||
break;
|
||||
|
||||
case dtype_short:
|
||||
if (argv[i]->dsc_scale == 0) {
|
||||
ZVAL_LONG(&args[i], *(short*)argv[i]->dsc_address);
|
||||
} else {
|
||||
ZVAL_DOUBLE(&args[i],
|
||||
((double)*(short*)argv[i]->dsc_address)/scales[-argv[i]->dsc_scale]);
|
||||
}
|
||||
break;
|
||||
|
||||
case dtype_long:
|
||||
if (argv[i]->dsc_scale == 0) {
|
||||
ZVAL_LONG(&args[i], *(ISC_LONG*)argv[i]->dsc_address);
|
||||
} else {
|
||||
ZVAL_DOUBLE(&args[i],
|
||||
((double)*(ISC_LONG*)argv[i]->dsc_address)/scales[-argv[i]->dsc_scale]);
|
||||
}
|
||||
break;
|
||||
|
||||
case dtype_int64:
|
||||
l = *(ISC_INT64*)argv[i]->dsc_address;
|
||||
|
||||
if (argv[i]->dsc_scale == 0 && l <= ZEND_LONG_MAX && l >= ZEND_LONG_MIN) {
|
||||
ZVAL_LONG(&args[i], (zend_long)l);
|
||||
} else {
|
||||
ZVAL_DOUBLE(&args[i], ((double)l)/scales[-argv[i]->dsc_scale]);
|
||||
}
|
||||
break;
|
||||
|
||||
case dtype_real:
|
||||
ZVAL_DOUBLE(&args[i], *(float*)argv[i]->dsc_address);
|
||||
break;
|
||||
|
||||
case dtype_double:
|
||||
ZVAL_DOUBLE(&args[i], *(double*)argv[i]->dsc_address);
|
||||
break;
|
||||
|
||||
case dtype_sql_date:
|
||||
isc_decode_sql_date((ISC_DATE*)argv[i]->dsc_address, &t);
|
||||
ZVAL_STRINGL(&args[i], d, strftime(d, sizeof(d), INI_STR("ibase.dateformat"), &t),1);
|
||||
break;
|
||||
|
||||
case dtype_sql_time:
|
||||
isc_decode_sql_time((ISC_TIME*)argv[i]->dsc_address, &t);
|
||||
ZVAL_STRINGL(&args[i], d, strftime(d, sizeof(d), INI_STR("ibase.timeformat"), &t),1);
|
||||
break;
|
||||
|
||||
case dtype_timestamp:
|
||||
isc_decode_timestamp((ISC_TIMESTAMP*)argv[i]->dsc_address, &t);
|
||||
ZVAL_STRINGL(&args[i], d, strftime(d, sizeof(d), INI_STR("ibase.timestampformat"), &t));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LOCK();
|
||||
|
||||
/* now call the function */
|
||||
if (FAILURE == call_user_function(NULL, NULL,
|
||||
&callback, &return_value, argc, args)) {
|
||||
UNLOCK();
|
||||
break;
|
||||
}
|
||||
|
||||
UNLOCK();
|
||||
|
||||
for (i = 0; i < argc; ++i) {
|
||||
switch (argv[i]->dsc_dtype) {
|
||||
case dtype_sql_date:
|
||||
case dtype_sql_time:
|
||||
case dtype_timestamp:
|
||||
zval_ptr_dtor_nogc(&args[i]);
|
||||
}
|
||||
}
|
||||
|
||||
zval_ptr_dtor_str(&callback);
|
||||
|
||||
/* return whatever type we got back from the callback: let DB handle conversion */
|
||||
switch (Z_TYPE(return_value)) {
|
||||
|
||||
case IS_LONG:
|
||||
r->dsc_dtype = dtype_long;
|
||||
*(zend_long*)r->dsc_address = Z_LVAL(return_value);
|
||||
r->dsc_length = sizeof(zend_long);
|
||||
break;
|
||||
|
||||
case IS_DOUBLE:
|
||||
r->dsc_dtype = dtype_double;
|
||||
*(double*)r->dsc_address = Z_DVAL(return_value);
|
||||
r->dsc_length = sizeof(double);
|
||||
break;
|
||||
|
||||
case IS_NULL:
|
||||
r->dsc_flags |= DSC_null;
|
||||
break;
|
||||
|
||||
default:
|
||||
convert_to_string(&return_value);
|
||||
|
||||
case IS_STRING:
|
||||
r->dsc_dtype = dtype_varying;
|
||||
memcpy(res->vary_string, Z_STRVAL(return_value),
|
||||
(res->vary_length = min(r->dsc_length-2,Z_STRLEN(return_value))));
|
||||
r->dsc_length = res->vary_length+2;
|
||||
break;
|
||||
}
|
||||
|
||||
zval_ptr_dtor(&return_value);
|
||||
|
||||
return;
|
||||
|
||||
} while (0);
|
||||
|
||||
/**
|
||||
* If we end up here, we should report an error back to the DB engine, but
|
||||
* that's not possible. We can however report it back to PHP.
|
||||
*/
|
||||
LOCK();
|
||||
php_error_docref(NULL, E_WARNING, "Error calling function '%s' from database", name);
|
||||
UNLOCK();
|
||||
}
|
||||
|
||||
|
||||
/* Entry points for the DB engine */
|
||||
|
||||
void udf_call_php1(char *name, PARAMDSC *r, PARAMDSC *arg1)
|
||||
{
|
||||
PARAMDSC *args[1] = { arg1 };
|
||||
call_php(name, r, 1, args);
|
||||
}
|
||||
|
||||
void udf_call_php2(char *name, PARAMDSC *r, PARAMDSC *arg1, PARAMDSC *arg2)
|
||||
{
|
||||
PARAMDSC *args[2] = { arg1, arg2 };
|
||||
call_php(name, r, 2, args);
|
||||
}
|
||||
|
||||
void udf_call_php3(char *name, PARAMDSC *r, PARAMDSC *arg1, PARAMDSC *arg2, PARAMDSC *arg3)
|
||||
{
|
||||
PARAMDSC *args[3] = { arg1, arg2, arg3 };
|
||||
call_php(name, r, 3, args);
|
||||
}
|
||||
|
||||
void udf_call_php4(char *name, PARAMDSC *r, PARAMDSC *arg1, PARAMDSC *arg2, PARAMDSC *arg3,
|
||||
PARAMDSC *arg4)
|
||||
{
|
||||
PARAMDSC *args[4] = { arg1, arg2, arg3, arg4 };
|
||||
call_php(name, r, 4, args);
|
||||
}
|
||||
|
||||
void udf_call_php5(char *name, PARAMDSC *r, PARAMDSC *arg1, PARAMDSC *arg2, PARAMDSC *arg3,
|
||||
PARAMDSC *arg4, PARAMDSC *arg5)
|
||||
{
|
||||
PARAMDSC *args[5] = { arg1, arg2, arg3, arg4, arg5 };
|
||||
call_php(name, r, 5, args);
|
||||
}
|
||||
|
||||
void udf_call_php6(char *name, PARAMDSC *r, PARAMDSC *arg1, PARAMDSC *arg2, PARAMDSC *arg3,
|
||||
PARAMDSC *arg4, PARAMDSC *arg5, PARAMDSC *arg6)
|
||||
{
|
||||
PARAMDSC *args[6] = { arg1, arg2, arg3, arg4, arg5, arg6 };
|
||||
call_php(name, r, 6, args);
|
||||
}
|
||||
|
||||
void udf_call_php7(char *name, PARAMDSC *r, PARAMDSC *arg1, PARAMDSC *arg2, PARAMDSC *arg3,
|
||||
PARAMDSC *arg4, PARAMDSC *arg5, PARAMDSC *arg6, PARAMDSC *arg7)
|
||||
{
|
||||
PARAMDSC *args[7] = { arg1, arg2, arg3, arg4, arg5, arg6, arg7 };
|
||||
call_php(name, r, 7, args);
|
||||
}
|
||||
|
||||
void udf_call_php8(char *name, PARAMDSC *r, PARAMDSC *arg1, PARAMDSC *arg2, PARAMDSC *arg3,
|
||||
PARAMDSC *arg4, PARAMDSC *arg5, PARAMDSC *arg6, PARAMDSC *arg7, PARAMDSC *arg8)
|
||||
{
|
||||
PARAMDSC *args[8] = { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 };
|
||||
call_php(name, r, 8, args);
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 7 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 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: Jouni Ahto <jouni.ahto@exdec.fi> |
|
||||
| Andrew Avdeev <andy@simgts.mv.ru> |
|
||||
| Ard Biesheuvel <a.k.biesheuvel@its.tudelft.nl> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#ifndef PHP_INTERBASE_H
|
||||
#define PHP_INTERBASE_H
|
||||
|
||||
extern zend_module_entry ibase_module_entry;
|
||||
#define phpext_interbase_ptr &ibase_module_entry
|
||||
|
||||
#include "php_version.h"
|
||||
#define PHP_INTERBASE_VERSION PHP_VERSION
|
||||
|
||||
PHP_MINIT_FUNCTION(ibase);
|
||||
PHP_RINIT_FUNCTION(ibase);
|
||||
PHP_MSHUTDOWN_FUNCTION(ibase);
|
||||
PHP_RSHUTDOWN_FUNCTION(ibase);
|
||||
PHP_MINFO_FUNCTION(ibase);
|
||||
|
||||
PHP_FUNCTION(ibase_connect);
|
||||
PHP_FUNCTION(ibase_pconnect);
|
||||
PHP_FUNCTION(ibase_close);
|
||||
PHP_FUNCTION(ibase_drop_db);
|
||||
PHP_FUNCTION(ibase_query);
|
||||
PHP_FUNCTION(ibase_fetch_row);
|
||||
PHP_FUNCTION(ibase_fetch_assoc);
|
||||
PHP_FUNCTION(ibase_fetch_object);
|
||||
PHP_FUNCTION(ibase_free_result);
|
||||
PHP_FUNCTION(ibase_name_result);
|
||||
PHP_FUNCTION(ibase_prepare);
|
||||
PHP_FUNCTION(ibase_execute);
|
||||
PHP_FUNCTION(ibase_free_query);
|
||||
|
||||
PHP_FUNCTION(ibase_timefmt);
|
||||
|
||||
PHP_FUNCTION(ibase_gen_id);
|
||||
PHP_FUNCTION(ibase_num_fields);
|
||||
PHP_FUNCTION(ibase_num_params);
|
||||
#if abies_0
|
||||
PHP_FUNCTION(ibase_num_rows);
|
||||
#endif
|
||||
PHP_FUNCTION(ibase_affected_rows);
|
||||
PHP_FUNCTION(ibase_field_info);
|
||||
PHP_FUNCTION(ibase_param_info);
|
||||
|
||||
PHP_FUNCTION(ibase_trans);
|
||||
PHP_FUNCTION(ibase_commit);
|
||||
PHP_FUNCTION(ibase_rollback);
|
||||
PHP_FUNCTION(ibase_commit_ret);
|
||||
PHP_FUNCTION(ibase_rollback_ret);
|
||||
|
||||
PHP_FUNCTION(ibase_blob_create);
|
||||
PHP_FUNCTION(ibase_blob_add);
|
||||
PHP_FUNCTION(ibase_blob_cancel);
|
||||
PHP_FUNCTION(ibase_blob_open);
|
||||
PHP_FUNCTION(ibase_blob_get);
|
||||
PHP_FUNCTION(ibase_blob_close);
|
||||
PHP_FUNCTION(ibase_blob_echo);
|
||||
PHP_FUNCTION(ibase_blob_info);
|
||||
PHP_FUNCTION(ibase_blob_import);
|
||||
|
||||
PHP_FUNCTION(ibase_add_user);
|
||||
PHP_FUNCTION(ibase_modify_user);
|
||||
PHP_FUNCTION(ibase_delete_user);
|
||||
|
||||
PHP_FUNCTION(ibase_service_attach);
|
||||
PHP_FUNCTION(ibase_service_detach);
|
||||
PHP_FUNCTION(ibase_backup);
|
||||
PHP_FUNCTION(ibase_restore);
|
||||
PHP_FUNCTION(ibase_maintain_db);
|
||||
PHP_FUNCTION(ibase_db_info);
|
||||
PHP_FUNCTION(ibase_server_info);
|
||||
|
||||
PHP_FUNCTION(ibase_errmsg);
|
||||
PHP_FUNCTION(ibase_errcode);
|
||||
|
||||
PHP_FUNCTION(ibase_wait_event);
|
||||
PHP_FUNCTION(ibase_set_event_handler);
|
||||
PHP_FUNCTION(ibase_free_event_handler);
|
||||
|
||||
#else
|
||||
|
||||
#define phpext_interbase_ptr NULL
|
||||
|
||||
#endif /* PHP_INTERBASE_H */
|
@ -1,33 +0,0 @@
|
||||
--TEST--
|
||||
InterBase: connect, close and pconnect
|
||||
--SKIPIF--
|
||||
<?php include("skipif.inc"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require("interbase.inc");
|
||||
|
||||
ibase_connect($test_base);
|
||||
out_table("test1");
|
||||
ibase_close();
|
||||
|
||||
$con = ibase_connect($test_base);
|
||||
$pcon1 = ibase_pconnect($test_base);
|
||||
$pcon2 = ibase_pconnect($test_base);
|
||||
ibase_close($con);
|
||||
unset($con);
|
||||
ibase_close($pcon1);
|
||||
unset($pcon1);
|
||||
|
||||
out_table("test1");
|
||||
|
||||
ibase_close($pcon2);
|
||||
unset($pcon2);
|
||||
?>
|
||||
--EXPECT--
|
||||
--- test1 ---
|
||||
1 test table not created with isql
|
||||
---
|
||||
--- test1 ---
|
||||
1 test table not created with isql
|
||||
---
|
@ -1,183 +0,0 @@
|
||||
--TEST--
|
||||
InterBase: misc sql types (may take a while)
|
||||
--SKIPIF--
|
||||
<?php include("skipif.inc"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require("interbase.inc");
|
||||
ibase_connect($test_base);
|
||||
|
||||
ibase_query(
|
||||
"create table test3 (
|
||||
iter integer not null,
|
||||
v_char char(1000),
|
||||
v_date timestamp,
|
||||
v_decimal4_2 decimal(4,2),
|
||||
v_decimal4_0 decimal(4,0),
|
||||
v_decimal7_2 decimal(7,2),
|
||||
v_decimal7_0 decimal(7,0),
|
||||
v_numeric15_15 numeric(15,15),
|
||||
v_numeric15_0 numeric(15,0),
|
||||
v_double double precision,
|
||||
v_float float,
|
||||
v_integer integer,
|
||||
v_smallint smallint,
|
||||
v_varchar varchar(10000)
|
||||
)");
|
||||
ibase_commit();
|
||||
|
||||
/* should fail, but gracefully */
|
||||
@ibase_query("insert into test3 (iter) values (?)", null);
|
||||
|
||||
/* if timefmt is not supported, suppress error here */
|
||||
ini_set('ibase.timestampformat',"%m/%d/%Y %H:%M:%S");
|
||||
|
||||
for($iter = 0; $iter < 10; $iter++){
|
||||
/* prepare data */
|
||||
$v_char = rand_str(1000);
|
||||
$v_date = rand_datetime();
|
||||
$v_decimal4_2 = rand_number(4,2);
|
||||
$v_decimal4_0 = rand_number(4,0);
|
||||
$v_decimal7_2 = rand_number(7,2);
|
||||
$v_decimal7_0 = rand_number(7,0);
|
||||
$v_numeric15_15 = rand_number(15,15);
|
||||
$v_numeric15_0 = $iter ? rand_number(15,0) : 0;
|
||||
$v_double = rand_number(18);
|
||||
$v_float = rand_number(7);
|
||||
$v_integer = rand_number(9,0);
|
||||
$v_smallint = rand_number(5) % 32767;
|
||||
$v_varchar = rand_str(10000);
|
||||
|
||||
ibase_query(
|
||||
"insert into test3 (iter, v_char,v_date,v_decimal4_2, v_decimal4_0, v_decimal7_2, v_decimal7_0,v_numeric15_15, v_numeric15_0,v_double,v_float,v_integer,v_smallint,v_varchar)
|
||||
values ($iter, '$v_char','$v_date',$v_decimal4_2, $v_decimal4_0, $v_decimal7_2, $v_decimal7_0,$v_numeric15_15, $v_numeric15_0,$v_double,$v_float,$v_integer,$v_smallint,'$v_varchar')");
|
||||
$sel = ibase_query("select * from test3 where iter = $iter");
|
||||
$row = ibase_fetch_object($sel);
|
||||
if(substr($row->V_CHAR,0,strlen($v_char)) != $v_char){
|
||||
echo " CHAR fail:\n";
|
||||
echo " in: $v_char\n";
|
||||
echo " out: $row->V_CHAR\n";
|
||||
}
|
||||
if($row->V_DATE != $v_date){
|
||||
echo " DATE fail\n";
|
||||
echo " in: $v_date\n";
|
||||
echo " out: $row->V_DATE\n";
|
||||
}
|
||||
if($row->V_DECIMAL4_2 != $v_decimal4_2){
|
||||
echo " DECIMAL4_2 fail\n";
|
||||
echo " in: $v_decimal4_2\n";
|
||||
echo " out: $row->V_DECIMAL4_2\n";
|
||||
}
|
||||
if($row->V_DECIMAL4_0 != $v_decimal4_0){
|
||||
echo " DECIMAL4_0 fail\n";
|
||||
echo " in: $v_decimal4_0\n";
|
||||
echo " out: $row->V_DECIMAL4_0\n";
|
||||
}
|
||||
if($row->V_DECIMAL7_2 != $v_decimal7_2){
|
||||
echo " DECIMAL7_2 fail\n";
|
||||
echo " in: $v_decimal7_2\n";
|
||||
echo " out: $row->V_DECIMAL7_2\n";
|
||||
}
|
||||
if($row->V_DECIMAL7_0 != $v_decimal7_0){
|
||||
echo " DECIMAL7_0 fail\n";
|
||||
echo " in: $v_decimal7_0\n";
|
||||
echo " out: $row->V_DECIMAL7_0\n";
|
||||
}
|
||||
if($row->V_NUMERIC15_15 != $v_numeric15_15){
|
||||
echo " NUMERIC15_15 fail\n";
|
||||
echo " in: $v_numeric15_15\n";
|
||||
echo " out: $row->V_NUMERIC15_15\n";
|
||||
}
|
||||
if($row->V_NUMERIC15_0 != (string)$v_numeric15_0){
|
||||
echo " NUMERIC15_0 fail\n";
|
||||
echo " in: $v_numeric15_0\n";
|
||||
echo " out: $row->V_NUMERIC15_0\n";
|
||||
}
|
||||
|
||||
if(abs($row->V_DOUBLE - $v_double) > abs($v_double / 1E15)){
|
||||
echo " DOUBLE fail\n";
|
||||
echo " in: $v_double\n";
|
||||
echo " out: $row->V_DOUBLE\n";
|
||||
}
|
||||
if(abs($row->V_FLOAT - $v_float) > abs($v_float / 1E7)){
|
||||
echo " FLOAT fail\n";
|
||||
echo " in: $v_float\n";
|
||||
echo " out: $row->V_FLOAT\n";
|
||||
}
|
||||
if($row->V_INTEGER != $v_integer){
|
||||
echo " INTEGER fail\n";
|
||||
echo " in: $v_integer\n";
|
||||
echo " out: $row->V_INTEGER\n";
|
||||
}
|
||||
if($row->V_SMALLINT != $v_smallint){
|
||||
echo " SMALLINT fail\n";
|
||||
echo " in: $v_smallint\n";
|
||||
echo " out: $row->V_SMALLINT\n";
|
||||
}
|
||||
|
||||
if(substr($row->V_VARCHAR,0,strlen($v_varchar)) != $v_varchar){
|
||||
echo " VARCHAR fail:\n";
|
||||
echo " in: $v_varchar\n";
|
||||
echo " out: $row->V_VARCHAR\n";
|
||||
}
|
||||
|
||||
ibase_free_result($sel);
|
||||
} /* for($iter) */
|
||||
|
||||
/* check for correct handling of duplicate field names */
|
||||
$q = ibase_query('SELECT 1 AS id, 2 AS id, 3 AS id, 4 AS id, 5 AS id, 6 AS id, 7 AS id, 8 AS id, 9 AS id,
|
||||
10 AS id, 11 AS id, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 FROM rdb$database');
|
||||
var_dump(ibase_fetch_assoc($q));
|
||||
|
||||
ibase_close();
|
||||
echo "end of test\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
array(22) {
|
||||
["ID"]=>
|
||||
int(1)
|
||||
["ID_01"]=>
|
||||
int(2)
|
||||
["ID_02"]=>
|
||||
int(3)
|
||||
["ID_03"]=>
|
||||
int(4)
|
||||
["ID_04"]=>
|
||||
int(5)
|
||||
["ID_05"]=>
|
||||
int(6)
|
||||
["ID_06"]=>
|
||||
int(7)
|
||||
["ID_07"]=>
|
||||
int(8)
|
||||
["ID_08"]=>
|
||||
int(9)
|
||||
["ID_09"]=>
|
||||
int(10)
|
||||
["ID_10"]=>
|
||||
int(11)
|
||||
["CONSTANT"]=>
|
||||
int(12)
|
||||
["CONSTANT_01"]=>
|
||||
int(13)
|
||||
["CONSTANT_02"]=>
|
||||
int(14)
|
||||
["CONSTANT_03"]=>
|
||||
int(15)
|
||||
["CONSTANT_04"]=>
|
||||
int(16)
|
||||
["CONSTANT_05"]=>
|
||||
int(17)
|
||||
["CONSTANT_06"]=>
|
||||
int(18)
|
||||
["CONSTANT_07"]=>
|
||||
int(19)
|
||||
["CONSTANT_08"]=>
|
||||
int(20)
|
||||
["CONSTANT_09"]=>
|
||||
int(21)
|
||||
["CONSTANT_10"]=>
|
||||
int(22)
|
||||
}
|
||||
end of test
|
@ -1,182 +0,0 @@
|
||||
--TEST--
|
||||
InterBase: BLOB test
|
||||
--SKIPIF--
|
||||
<?php include("skipif.inc"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require("interbase.inc");
|
||||
|
||||
$link = ibase_connect($test_base);
|
||||
|
||||
ibase_query(
|
||||
"CREATE TABLE test4 (
|
||||
v_integer integer,
|
||||
v_blob blob)");
|
||||
ibase_commit();
|
||||
|
||||
/* create 100k blob file */
|
||||
$blob_str = rand_binstr(100*1024);
|
||||
|
||||
$name = tempnam(__DIR__,"blob.tmp");
|
||||
$ftmp = fopen($name,"w");
|
||||
fwrite($ftmp,$blob_str);
|
||||
fclose($ftmp);
|
||||
|
||||
echo "import blob 1\n";
|
||||
$ftmp = fopen($name,"r");
|
||||
$bl_s = ibase_blob_import($ftmp);
|
||||
ibase_query("INSERT INTO test4 (v_integer, v_blob) VALUES (1, ?)", $bl_s);
|
||||
|
||||
$bl_s = ibase_blob_import($link,$ftmp);
|
||||
ibase_query($link, "INSERT INTO test4 (v_integer, v_blob) VALUES (1, ?)", $bl_s);
|
||||
fclose($ftmp);
|
||||
|
||||
echo "test blob 1\n";
|
||||
$q = ibase_query("SELECT v_blob FROM test4 WHERE v_integer = 1");
|
||||
|
||||
$row = ibase_fetch_object($q);
|
||||
$bl_h = ibase_blob_open($row->V_BLOB);
|
||||
|
||||
$blob = '';
|
||||
while($piece = ibase_blob_get($bl_h, 1 + rand() % 1024))
|
||||
$blob .= $piece;
|
||||
if($blob != $blob_str)
|
||||
echo " BLOB 1 fail (1)\n";
|
||||
ibase_blob_close($bl_h);
|
||||
|
||||
$bl_h = ibase_blob_open($link,$row->V_BLOB);
|
||||
|
||||
$blob = '';
|
||||
while($piece = ibase_blob_get($bl_h, 100 * 1024))
|
||||
$blob .= $piece;
|
||||
if($blob != $blob_str)
|
||||
echo " BLOB 1 fail (2)\n";
|
||||
ibase_blob_close($bl_h);
|
||||
ibase_free_result($q);
|
||||
unset($blob);
|
||||
|
||||
echo "create blob 2\n";
|
||||
|
||||
ibase_query("INSERT INTO test4 (v_integer, v_blob) VALUES (2, ?)", $blob_str);
|
||||
|
||||
echo "test blob 2\n";
|
||||
|
||||
$q = ibase_query("SELECT v_blob FROM test4 WHERE v_integer = 2");
|
||||
$row = ibase_fetch_object($q,IBASE_TEXT);
|
||||
|
||||
if($row->V_BLOB != $blob_str)
|
||||
echo " BLOB 2 fail\n";
|
||||
ibase_free_result($q);
|
||||
unset($blob);
|
||||
|
||||
|
||||
echo "create blob 3\n";
|
||||
|
||||
$bl_h = ibase_blob_create($link);
|
||||
|
||||
ibase_blob_add($bl_h, "+----------------------------------------------------------------------+\n");
|
||||
ibase_blob_add($bl_h, "| PHP HTML Embedded Scripting Language Version 3.0 |\n");
|
||||
ibase_blob_add($bl_h, "+----------------------------------------------------------------------+\n");
|
||||
ibase_blob_add($bl_h, "| Copyright (c) 1997-2000 PHP Development Team (See Credits file) |\n");
|
||||
ibase_blob_add($bl_h, "+----------------------------------------------------------------------+\n");
|
||||
ibase_blob_add($bl_h, "| This program is free software; you can redistribute it and/or modify |\n");
|
||||
ibase_blob_add($bl_h, "| it under the terms of one of the following licenses: |\n");
|
||||
ibase_blob_add($bl_h, "| |\n");
|
||||
ibase_blob_add($bl_h, "| A) the GNU General Public License as published by the Free Software |\n");
|
||||
ibase_blob_add($bl_h, "| Foundation; either version 2 of the License, or (at your option) |\n");
|
||||
ibase_blob_add($bl_h, "| any later version. |\n");
|
||||
ibase_blob_add($bl_h, "| |\n");
|
||||
ibase_blob_add($bl_h, "| B) the PHP License as published by the PHP Development Team and |\n");
|
||||
ibase_blob_add($bl_h, "| included in the distribution in the file: LICENSE |\n");
|
||||
ibase_blob_add($bl_h, "| |\n");
|
||||
ibase_blob_add($bl_h, "| This program is distributed in the hope that it will be useful, |\n");
|
||||
ibase_blob_add($bl_h, "| but WITHOUT ANY WARRANTY; without even the implied warranty of |\n");
|
||||
ibase_blob_add($bl_h, "| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |\n");
|
||||
ibase_blob_add($bl_h, "| GNU General Public License for more details. |\n");
|
||||
ibase_blob_add($bl_h, "| |\n");
|
||||
ibase_blob_add($bl_h, "| You should have received a copy of both licenses referred to here. |\n");
|
||||
ibase_blob_add($bl_h, "| If you did not, or have any questions about PHP licensing, please |\n");
|
||||
ibase_blob_add($bl_h, "| contact core@php.net. |\n");
|
||||
ibase_blob_add($bl_h, "+----------------------------------------------------------------------+\n");
|
||||
$bl_s = ibase_blob_close($bl_h);
|
||||
ibase_query("INSERT INTO test4 (v_integer, v_blob) VALUES (3, ?)", $bl_s);
|
||||
ibase_commit();
|
||||
echo "echo blob 3\n";
|
||||
|
||||
$q = ibase_query("SELECT v_blob FROM test4 WHERE v_integer = 3");
|
||||
$row = ibase_fetch_object($q);
|
||||
ibase_commit();
|
||||
ibase_close();
|
||||
|
||||
$link = ibase_connect($test_base);
|
||||
ibase_blob_echo($link, $row->V_BLOB);
|
||||
ibase_free_result($q);
|
||||
|
||||
echo "fetch blob 3\n";
|
||||
$q = ibase_query("SELECT v_blob FROM test4 WHERE v_integer = 3");
|
||||
$row = ibase_fetch_object($q,IBASE_TEXT);
|
||||
echo $row->V_BLOB;
|
||||
ibase_free_result($q);
|
||||
|
||||
ibase_close();
|
||||
unlink($name);
|
||||
echo "end of test\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
import blob 1
|
||||
test blob 1
|
||||
create blob 2
|
||||
test blob 2
|
||||
create blob 3
|
||||
echo blob 3
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP HTML Embedded Scripting Language Version 3.0 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2000 PHP Development Team (See Credits file) |
|
||||
+----------------------------------------------------------------------+
|
||||
| This program is free software; you can redistribute it and/or modify |
|
||||
| it under the terms of one of the following licenses: |
|
||||
| |
|
||||
| A) the GNU General Public License as published by the Free Software |
|
||||
| Foundation; either version 2 of the License, or (at your option) |
|
||||
| any later version. |
|
||||
| |
|
||||
| B) the PHP License as published by the PHP Development Team and |
|
||||
| included in the distribution in the file: LICENSE |
|
||||
| |
|
||||
| This program is distributed in the hope that it will be useful, |
|
||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
| GNU General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of both licenses referred to here. |
|
||||
| If you did not, or have any questions about PHP licensing, please |
|
||||
| contact core@php.net. |
|
||||
+----------------------------------------------------------------------+
|
||||
fetch blob 3
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP HTML Embedded Scripting Language Version 3.0 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2000 PHP Development Team (See Credits file) |
|
||||
+----------------------------------------------------------------------+
|
||||
| This program is free software; you can redistribute it and/or modify |
|
||||
| it under the terms of one of the following licenses: |
|
||||
| |
|
||||
| A) the GNU General Public License as published by the Free Software |
|
||||
| Foundation; either version 2 of the License, or (at your option) |
|
||||
| any later version. |
|
||||
| |
|
||||
| B) the PHP License as published by the PHP Development Team and |
|
||||
| included in the distribution in the file: LICENSE |
|
||||
| |
|
||||
| This program is distributed in the hope that it will be useful, |
|
||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
| GNU General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of both licenses referred to here. |
|
||||
| If you did not, or have any questions about PHP licensing, please |
|
||||
| contact core@php.net. |
|
||||
+----------------------------------------------------------------------+
|
||||
end of test
|
@ -1,289 +0,0 @@
|
||||
--TEST--
|
||||
InterBase: transactions
|
||||
--SKIPIF--
|
||||
<?php include("skipif.inc"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require("interbase.inc");
|
||||
|
||||
ibase_connect($test_base);
|
||||
|
||||
@ibase_query("create table test5 (i integer)");
|
||||
@ibase_query("delete from test5");
|
||||
ibase_close();
|
||||
|
||||
|
||||
echo "default transaction:\n";
|
||||
|
||||
/*
|
||||
Difference between default and other transactions:
|
||||
default committed when you call ibase_close().
|
||||
Other transaction doing rollback.
|
||||
|
||||
If you not open default transaction with
|
||||
ibase_trans, default transaction open
|
||||
when you call ibase_query(), ibase_prepare(),
|
||||
ibase_blob_create(), ibase_blob_import() first time.
|
||||
*/
|
||||
|
||||
/*
|
||||
simple default transaction test without ibase_trans()
|
||||
*/
|
||||
|
||||
ibase_connect($test_base);
|
||||
|
||||
echo "empty table\n";
|
||||
|
||||
/* out_table call ibase_query()
|
||||
and ibase_query() start default transaction */
|
||||
out_table("test5");
|
||||
|
||||
/* in default transaction context */
|
||||
ibase_query("insert into test5 (i) values (1)");
|
||||
|
||||
echo "one row\n";
|
||||
out_table("test5");
|
||||
|
||||
ibase_rollback(); /* default rolled */
|
||||
|
||||
echo "after rollback table empty again\n";
|
||||
out_table("test5"); /* started new default transaction */
|
||||
|
||||
ibase_query("insert into test5 (i) values (2)");
|
||||
|
||||
ibase_close(); /* commit here! */
|
||||
|
||||
ibase_connect($test_base);
|
||||
|
||||
echo "one row\n";
|
||||
out_table("test5");
|
||||
ibase_close();
|
||||
|
||||
/*
|
||||
default transaction on default link
|
||||
First open transaction on link will be default.
|
||||
$tr_def_l1 may be omitted. All queryes without link and trans
|
||||
parameters run in this context
|
||||
*/
|
||||
|
||||
$link_def = ibase_connect($test_base);
|
||||
|
||||
$tr_def_l1 = ibase_trans(IBASE_READ); /* here transaction start */
|
||||
|
||||
/* all default */
|
||||
$res = ibase_query("select * from test5");
|
||||
|
||||
echo "one row\n";
|
||||
out_result($res,"test5");
|
||||
|
||||
ibase_free_result($res);
|
||||
|
||||
/* specify transaction context... */
|
||||
$res = ibase_query($tr_def_l1, "select * from test5");
|
||||
|
||||
echo "one row... again.\n";
|
||||
out_result($res,"test5");
|
||||
|
||||
ibase_free_result($res);
|
||||
|
||||
/* specify default transaction on link */
|
||||
$res = ibase_query($link_def, "select * from test5");
|
||||
|
||||
echo "one row.\n";
|
||||
out_result($res,"test5");
|
||||
|
||||
ibase_free_result($res);
|
||||
|
||||
ibase_rollback($link_def); /* just for example */
|
||||
|
||||
ibase_close();
|
||||
|
||||
/*
|
||||
three transaction on default link
|
||||
*/
|
||||
ibase_connect($test_base);
|
||||
|
||||
$res = ibase_query("select * from test5");
|
||||
|
||||
echo "one row\n";
|
||||
out_result($res,"test5");
|
||||
|
||||
ibase_free_result($res);
|
||||
|
||||
$tr_1 = ibase_query("SET TRANSACTION");
|
||||
$tr_2 = ibase_query("SET TRANSACTION READ ONLY");
|
||||
$tr_3 = ibase_trans(IBASE_READ+IBASE_COMMITTED+IBASE_REC_VERSION+IBASE_WAIT);
|
||||
$tr_4 = ibase_trans(IBASE_READ+IBASE_COMMITTED+IBASE_REC_NO_VERSION+IBASE_NOWAIT);
|
||||
|
||||
/* insert in first transaction context... */
|
||||
/* as default */
|
||||
ibase_query("insert into test5 (i) values (3)");
|
||||
/* specify context */
|
||||
ibase_query($tr_1, "insert into test5 (i) values (4)");
|
||||
|
||||
$res = ibase_query("select * from test5");
|
||||
|
||||
echo "two rows\n";
|
||||
out_result($res,"test5");
|
||||
|
||||
ibase_free_result($res);
|
||||
|
||||
$res = ibase_query($tr_1, "select * from test5");
|
||||
|
||||
echo "two rows again\n";
|
||||
out_result($res,"test5");
|
||||
|
||||
ibase_free_result($res);
|
||||
|
||||
ibase_commit();
|
||||
ibase_commit($tr_1);
|
||||
|
||||
$tr_1 = ibase_trans();
|
||||
ibase_query($tr_1, "insert into test5 (i) values (5)");
|
||||
|
||||
/* tr_2 is IBASE_READ + IBASE_CONCURRENCY + IBASE_WAIT */
|
||||
$res = ibase_query($tr_2, "select * from test5");
|
||||
|
||||
echo "one row in second transaction\n";
|
||||
out_result($res,"test5");
|
||||
|
||||
ibase_free_result($res);
|
||||
|
||||
/* tr_3 is IBASE_COMMITTED + IBASE_REC_VERSION + IBASE_WAIT */
|
||||
$res = ibase_query($tr_3, "select * from test5");
|
||||
|
||||
echo "three rows in third transaction\n";
|
||||
out_result($res,"test5");
|
||||
|
||||
ibase_free_result($res);
|
||||
|
||||
/* tr_4 IBASE_COMMITTED + IBASE_REC_NO_VERSION + IBASE_NOWAIT */
|
||||
$res = ibase_query($tr_4, "select * from test5");
|
||||
|
||||
echo "three rows in fourth transaction with deadlock\n";
|
||||
out_result_trap_error($res,"test5");
|
||||
|
||||
ibase_free_result($res);
|
||||
|
||||
ibase_rollback($tr_1);
|
||||
ibase_close();
|
||||
/*
|
||||
transactions on second link
|
||||
*/
|
||||
$link_1 = ibase_pconnect($test_base);
|
||||
$link_2 = ibase_pconnect($test_base);
|
||||
|
||||
$tr_1 = ibase_trans(IBASE_DEFAULT, $link_2); /* this default transaction also */
|
||||
$tr_2 = ibase_trans(IBASE_COMMITTED, $link_2);
|
||||
|
||||
$res = ibase_query($tr_1, "select * from test5");
|
||||
|
||||
echo "three rows\n";
|
||||
out_result($res,"test5");
|
||||
|
||||
ibase_free_result($res);
|
||||
|
||||
ibase_query($tr_1, "insert into test5 (i) values (5)");
|
||||
|
||||
$res = ibase_query($tr_1, "select * from test5");
|
||||
|
||||
echo "four rows\n";
|
||||
out_result($res,"test5");
|
||||
|
||||
ibase_free_result($res);
|
||||
|
||||
ibase_commit($tr_1);
|
||||
|
||||
$res = ibase_query($tr_2, "select * from test5");
|
||||
|
||||
echo "four rows again\n";
|
||||
out_result($res,"test5");
|
||||
|
||||
ibase_free_result($res);
|
||||
|
||||
ibase_close($link_1);
|
||||
ibase_close($link_2);
|
||||
|
||||
echo "end of test\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
default transaction:
|
||||
empty table
|
||||
--- test5 ---
|
||||
---
|
||||
one row
|
||||
--- test5 ---
|
||||
1
|
||||
---
|
||||
after rollback table empty again
|
||||
--- test5 ---
|
||||
---
|
||||
one row
|
||||
--- test5 ---
|
||||
2
|
||||
---
|
||||
one row
|
||||
--- test5 ---
|
||||
2
|
||||
---
|
||||
one row... again.
|
||||
--- test5 ---
|
||||
2
|
||||
---
|
||||
one row.
|
||||
--- test5 ---
|
||||
2
|
||||
---
|
||||
one row
|
||||
--- test5 ---
|
||||
2
|
||||
---
|
||||
two rows
|
||||
--- test5 ---
|
||||
2
|
||||
3
|
||||
---
|
||||
two rows again
|
||||
--- test5 ---
|
||||
2
|
||||
4
|
||||
---
|
||||
one row in second transaction
|
||||
--- test5 ---
|
||||
2
|
||||
---
|
||||
three rows in third transaction
|
||||
--- test5 ---
|
||||
2
|
||||
3
|
||||
4
|
||||
---
|
||||
three rows in fourth transaction with deadlock
|
||||
--- test5 ---
|
||||
2
|
||||
3
|
||||
4
|
||||
errmsg [lock conflict on no wait transaction deadlock %a]
|
||||
---
|
||||
three rows
|
||||
--- test5 ---
|
||||
2
|
||||
3
|
||||
4
|
||||
---
|
||||
four rows
|
||||
--- test5 ---
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
---
|
||||
four rows again
|
||||
--- test5 ---
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
---
|
||||
end of test
|
@ -1,300 +0,0 @@
|
||||
--TEST--
|
||||
InterBase: binding (may take a while)
|
||||
--SKIPIF--
|
||||
<?php include("skipif.inc"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require("interbase.inc");
|
||||
|
||||
ibase_connect($test_base);
|
||||
|
||||
ibase_query(
|
||||
"create table test6 (
|
||||
iter integer,
|
||||
v_char char(1000),
|
||||
v_date timestamp,
|
||||
v_decimal decimal(12,3),
|
||||
v_double double precision,
|
||||
v_float float,
|
||||
v_integer integer,
|
||||
v_numeric numeric(4,2),
|
||||
v_smallint smallint,
|
||||
v_varchar varchar(10000)
|
||||
)");
|
||||
ibase_query(
|
||||
"create procedure add1 (arg integer)
|
||||
returns (result integer)
|
||||
as
|
||||
begin
|
||||
result = arg +1;
|
||||
end");
|
||||
ibase_commit();
|
||||
|
||||
/* if timefmt not supported, hide error */
|
||||
ini_set('ibase.timestampformat',"%m/%d/%Y %H:%M:%S");
|
||||
|
||||
echo "insert\n";
|
||||
|
||||
for($iter = 0; $iter < 3; $iter++) {
|
||||
/* prepare data */
|
||||
$v_char = rand_str(1000);
|
||||
$v_date = rand_datetime();
|
||||
$v_decimal = rand_number(12,3);
|
||||
$v_double = rand_number(20);
|
||||
$v_float = rand_number(7);
|
||||
$v_integer = rand_number(9,0);
|
||||
$v_numeric = rand_number(4,2);
|
||||
$v_smallint = rand_number(5) % 32767;
|
||||
$v_varchar = rand_str(10000);
|
||||
|
||||
ibase_query("insert into test6
|
||||
(iter,v_char,v_date,v_decimal,v_double,v_float,
|
||||
v_integer,v_numeric,v_smallint,v_varchar)
|
||||
values (?,?,?,?,?,?,?,?,?,?)",
|
||||
$iter, $v_char, $v_date, $v_decimal, $v_double, $v_float,
|
||||
$v_integer, $v_numeric, $v_smallint, $v_varchar);
|
||||
$sel = ibase_query("select * from test6 where iter = ?", $iter);
|
||||
|
||||
$row = ibase_fetch_object($sel);
|
||||
if(substr($row->V_CHAR,0,strlen($v_char)) != $v_char) {
|
||||
echo " CHAR fail:\n";
|
||||
echo " in: $v_char\n";
|
||||
echo " out: $row->V_CHAR\n";
|
||||
}
|
||||
if($row->V_DATE != $v_date) {
|
||||
echo " DATE fail\n";
|
||||
echo " in: $v_date\n";
|
||||
echo " out: $row->V_DATE\n";
|
||||
}
|
||||
if($row->V_DECIMAL != $v_decimal) {
|
||||
echo " DECIMAL fail\n";
|
||||
echo " in: $v_decimal\n";
|
||||
echo " out: $row->V_DECIMAL\n";
|
||||
}
|
||||
if(abs($row->V_DOUBLE - $v_double) > abs($v_double / 1E15)) {
|
||||
echo " DOUBLE fail\n";
|
||||
echo " in: $v_double\n";
|
||||
echo " out: $row->V_DOUBLE\n";
|
||||
}
|
||||
if(abs($row->V_FLOAT - $v_float) > abs($v_float / 1E7)) {
|
||||
echo " FLOAT fail\n";
|
||||
echo " in: $v_float\n";
|
||||
echo " out: $row->V_FLOAT\n";
|
||||
}
|
||||
if($row->V_INTEGER != $v_integer) {
|
||||
echo " INTEGER fail\n";
|
||||
echo " in: $v_integer\n";
|
||||
echo " out: $row->V_INTEGER\n";
|
||||
}
|
||||
if ($row->V_NUMERIC != $v_numeric) {
|
||||
echo " NUMERIC fail\n";
|
||||
echo " in: $v_numeric\n";
|
||||
echo " out: $row->V_NUMERIC\n";
|
||||
}
|
||||
if ($row->V_SMALLINT != $v_smallint) {
|
||||
echo " SMALLINT fail\n";
|
||||
echo " in: $v_smallint\n";
|
||||
echo " out: $row->V_SMALLINT\n";
|
||||
}
|
||||
if ($row->V_VARCHAR != $v_varchar) {
|
||||
echo " VARCHAR fail:\n";
|
||||
echo " in: $v_varchar\n";
|
||||
echo " out: $row->V_VARCHAR\n";
|
||||
}
|
||||
ibase_free_result($sel);
|
||||
}/* for($iter)*/
|
||||
|
||||
echo "select\n";
|
||||
for($iter = 0; $iter < 3; $iter++) {
|
||||
/* prepare data */
|
||||
$v_char = rand_str(1000);
|
||||
$v_date = (int)rand_number(10,0,0);
|
||||
$v_decimal = rand_number(12,3);
|
||||
$v_double = rand_number(20);
|
||||
$v_float = rand_number(7);
|
||||
$v_integer = rand_number(9,0);
|
||||
$v_numeric = rand_number(4,2);
|
||||
$v_smallint = rand_number(5) % 32767;
|
||||
$v_varchar = rand_str(10000);
|
||||
|
||||
/* clear table*/
|
||||
ibase_query("delete from test6");
|
||||
|
||||
/* make one record */
|
||||
ibase_query("insert into test6
|
||||
(iter, v_char,v_date,v_decimal,
|
||||
v_integer,v_numeric,v_smallint,v_varchar)
|
||||
values (666, '$v_char',?,$v_decimal, $v_integer,
|
||||
$v_numeric, $v_smallint, '$v_varchar')",$v_date);
|
||||
|
||||
/* test all types */
|
||||
if(!($sel = ibase_query(
|
||||
"select iter from test6 where v_char = ?", $v_char)) ||
|
||||
!ibase_fetch_row($sel)) {
|
||||
echo "CHAR fail\n";
|
||||
}
|
||||
ibase_free_result($sel);
|
||||
if(!($sel = ibase_query(
|
||||
"select iter from test6 where v_date = ?", $v_date)) ||
|
||||
!ibase_fetch_row($sel)) {
|
||||
echo "DATE fail\n";
|
||||
}
|
||||
ibase_free_result($sel);
|
||||
if(!($sel = ibase_query(
|
||||
"select iter from test6 where v_decimal = ?", $v_decimal)) ||
|
||||
!ibase_fetch_row($sel)) {
|
||||
echo "DECIMAL fail\n";
|
||||
}
|
||||
ibase_free_result($sel);
|
||||
if(!($sel = ibase_query(
|
||||
"select iter from test6 where v_integer = ?", $v_integer)) ||
|
||||
!ibase_fetch_row($sel)) {
|
||||
echo "INTEGER fail\n";
|
||||
}
|
||||
ibase_free_result($sel);
|
||||
if(!($sel = ibase_query(
|
||||
"select iter from test6 where v_numeric = ?", $v_numeric)) ||
|
||||
!ibase_fetch_row($sel)) {
|
||||
echo "NUMERIC fail\n";
|
||||
}
|
||||
ibase_free_result($sel);
|
||||
if(!($sel = ibase_query(
|
||||
"select iter from test6 where v_smallint = ?", $v_smallint)) ||
|
||||
!ibase_fetch_row($sel)) {
|
||||
echo "SMALLINT fail\n";
|
||||
}
|
||||
ibase_free_result($sel);
|
||||
if(!($sel = ibase_query(
|
||||
"select iter from test6 where v_varchar = ?", $v_varchar)) ||
|
||||
!ibase_fetch_row($sel)) {
|
||||
echo "VARCHAR fail\n";
|
||||
}
|
||||
ibase_free_result($sel);
|
||||
|
||||
} /*for iter*/
|
||||
|
||||
echo "prepare and exec insert\n";
|
||||
|
||||
/* prepare table */
|
||||
ibase_query("delete from test6");
|
||||
|
||||
/* prepare query */
|
||||
$query = ibase_prepare(
|
||||
"insert into test6 (v_integer) values (?)");
|
||||
|
||||
for($i = 0; $i < 10; $i++) {
|
||||
ibase_execute($query, $i);
|
||||
}
|
||||
|
||||
out_table("test6");
|
||||
|
||||
ibase_free_query($query);
|
||||
|
||||
echo "prepare and exec select\n";
|
||||
|
||||
/* prepare query */
|
||||
$query = ibase_prepare("select * from test6
|
||||
where v_integer between ? and ?");
|
||||
|
||||
$low_border = 2;
|
||||
$high_border = 6;
|
||||
|
||||
$res = ibase_execute($query, $low_border, $high_border);
|
||||
out_result($res, "test6");
|
||||
ibase_free_result($res);
|
||||
|
||||
$low_border = 0;
|
||||
$high_border = 4;
|
||||
$res = ibase_execute($query, $low_border, $high_border);
|
||||
out_result($res, "test6");
|
||||
ibase_free_result($res);
|
||||
|
||||
$res = ibase_execute($query, "5", 7.499);
|
||||
out_result($res, "test6");
|
||||
ibase_free_result($res);
|
||||
|
||||
ibase_free_query($query);
|
||||
|
||||
/* test execute procedure */
|
||||
$query = ibase_prepare("execute procedure add1(?)");
|
||||
$res = array();
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$res[] = ibase_execute($query,$i);
|
||||
}
|
||||
ibase_free_query($query);
|
||||
foreach ($res as $r) {
|
||||
out_result($r, "proc add1");
|
||||
ibase_free_result($r);
|
||||
}
|
||||
|
||||
ibase_close();
|
||||
echo "end of test\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
insert
|
||||
select
|
||||
prepare and exec insert
|
||||
--- test6 ---
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
---
|
||||
prepare and exec select
|
||||
--- test6 ---
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
---
|
||||
--- test6 ---
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
---
|
||||
--- test6 ---
|
||||
5
|
||||
6
|
||||
7
|
||||
---
|
||||
--- proc add1 ---
|
||||
1
|
||||
---
|
||||
--- proc add1 ---
|
||||
2
|
||||
---
|
||||
--- proc add1 ---
|
||||
3
|
||||
---
|
||||
--- proc add1 ---
|
||||
4
|
||||
---
|
||||
--- proc add1 ---
|
||||
5
|
||||
---
|
||||
--- proc add1 ---
|
||||
6
|
||||
---
|
||||
--- proc add1 ---
|
||||
7
|
||||
---
|
||||
--- proc add1 ---
|
||||
8
|
||||
---
|
||||
--- proc add1 ---
|
||||
9
|
||||
---
|
||||
--- proc add1 ---
|
||||
10
|
||||
---
|
||||
end of test
|
@ -1,183 +0,0 @@
|
||||
--TEST--
|
||||
InterBase: array handling
|
||||
--SKIPIF--
|
||||
<?php include("skipif.inc"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require("interbase.inc");
|
||||
|
||||
ibase_connect($test_base);
|
||||
|
||||
ibase_query(
|
||||
"create table test7 (
|
||||
iter integer,
|
||||
v_multi integer[10,10,10],
|
||||
v_char char(100)[10],
|
||||
v_date timestamp[10],
|
||||
v_decimal decimal(18,3)[10],
|
||||
v_double double precision[10],
|
||||
v_float float[10],
|
||||
v_integer integer[10],
|
||||
v_numeric numeric(9,2)[10],
|
||||
v_smallint smallint[10],
|
||||
v_varchar varchar(1000)[10]
|
||||
)");
|
||||
ibase_commit();
|
||||
|
||||
/* if timefmt not supported, hide error */
|
||||
ini_set('ibase.timestampformat',"%m/%d/%Y %H:%M:%S");
|
||||
|
||||
echo "insert\n";
|
||||
|
||||
for ($i = 1; $i <= 10; ++$i) {
|
||||
for ($j = 1; $j <= 10; ++$j) {
|
||||
for ($k = 1; $k <= 10; ++$k) {
|
||||
$v_multi[$i][$j][$k] = $i * $j * $k;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for($iter = 0; $iter < 3; $iter++) {
|
||||
|
||||
/* prepare data */
|
||||
$v_char = array();
|
||||
$v_date = array();
|
||||
$v_decimal = array();
|
||||
$v_double = array();
|
||||
$v_float = array();
|
||||
$v_integer = array();
|
||||
$v_numeric = array();
|
||||
$v_smallint = array();
|
||||
$v_varchar = array();
|
||||
|
||||
for ($i = 1; $i <= 10; ++$i) {
|
||||
$v_char[$i] = rand_str(100);
|
||||
$v_date[$i] = rand_datetime();
|
||||
$v_decimal[$i] = rand_number(18,3);
|
||||
$v_double[$i] = rand_number(20);
|
||||
$v_float[$i] = rand_number(7);
|
||||
$v_integer[$i] = rand_number(9,0);
|
||||
$v_numeric[$i] = rand_number(9,2);
|
||||
$v_smallint[$i] = rand_number(5) % 32767;
|
||||
$v_varchar[$i] = rand_str(1000);
|
||||
}
|
||||
|
||||
ibase_query("insert into test7
|
||||
(iter,v_multi,v_char,v_date,v_decimal,v_double,v_float,
|
||||
v_integer,v_numeric,v_smallint,v_varchar)
|
||||
values (?,?,?,?,?,?,?,?,?,?,?)",
|
||||
$iter, $v_multi, $v_char, $v_date, $v_decimal, $v_double, $v_float,
|
||||
$v_integer, $v_numeric, $v_smallint, $v_varchar);
|
||||
$sel = ibase_query("select * from test7 where iter = $iter");
|
||||
|
||||
$row = ibase_fetch_object($sel,IBASE_FETCH_ARRAYS);
|
||||
for ($i = 1; $i <= 10; ++$i) {
|
||||
|
||||
if(strncmp($row->V_CHAR[$i],$v_char[$i],strlen($v_char[$i])) != 0) {
|
||||
echo " CHAR[$i] fail:\n";
|
||||
echo " in: ".$v_char[$i]."\n";
|
||||
echo " out: ".$row->V_CHAR[$i]."\n";
|
||||
}
|
||||
if($row->V_DATE[$i] != $v_date[$i]) {
|
||||
echo " DATE[$i] fail\n";
|
||||
echo " in: ".$v_date[$i]."\n";
|
||||
echo " out: ".$row->V_DATE[$i]."\n";
|
||||
}
|
||||
if($row->V_DECIMAL[$i] != $v_decimal[$i]) {
|
||||
echo " DECIMAL[$i] fail\n";
|
||||
echo " in: ".$v_decimal[$i]."\n";
|
||||
echo " out: ".$row->V_DECIMAL[$i]."\n";
|
||||
}
|
||||
if(abs($row->V_DOUBLE[$i] - $v_double[$i]) > abs($v_double[$i] / 1E15)) {
|
||||
echo " DOUBLE[$i] fail\n";
|
||||
echo " in: ".$v_double[$i]."\n";
|
||||
echo " out: ".$row->V_DOUBLE[$i]."\n";
|
||||
}
|
||||
if(abs($row->V_FLOAT[$i] - $v_float[$i]) > abs($v_float[$i] / 1E7)) {
|
||||
echo " FLOAT[$i] fail\n";
|
||||
echo " in: ".$v_float[$i]."\n";
|
||||
echo " out: ".$row->V_FLOAT[$i]."\n";
|
||||
}
|
||||
if($row->V_INTEGER[$i] != $v_integer[$i]) {
|
||||
echo " INTEGER[$i] fail\n";
|
||||
echo " in: ".$v_integer[$i]."\n";
|
||||
echo " out: ".$row->V_INTEGER[$i]."\n";
|
||||
}
|
||||
if ($row->V_NUMERIC[$i] != $v_numeric[$i]) {
|
||||
echo " NUMERIC[$i] fail\n";
|
||||
echo " in: ".$v_numeric[$i]."\n";
|
||||
echo " out: ".$row->V_NUMERIC[$i]."\n";
|
||||
}
|
||||
if ($row->V_SMALLINT[$i] != $v_smallint[$i]) {
|
||||
echo " SMALLINT[$i] fail\n";
|
||||
echo " in: ".$v_smallint[$i]."\n";
|
||||
echo " out: ".$row->V_SMALLINT[$i]."\n";
|
||||
}
|
||||
if ($row->V_VARCHAR[$i] != $v_varchar[$i]) {
|
||||
echo " VARCHAR[$i] fail:\n";
|
||||
echo " in: ".$v_varchar[$i]."\n";
|
||||
echo " out: ".$row->V_VARCHAR[$i]."\n";
|
||||
}
|
||||
}
|
||||
ibase_free_result($sel);
|
||||
}/* for($iter) */
|
||||
|
||||
echo "select\n";
|
||||
|
||||
$sel = ibase_query("SELECT v_multi[5,5,5],v_multi[10,10,10] FROM test7 WHERE iter = 0");
|
||||
print_r(ibase_fetch_row($sel));
|
||||
ibase_free_result($sel);
|
||||
|
||||
for($iter = 1; $iter <= 3; $iter++) {
|
||||
|
||||
if(!($sel = ibase_query(
|
||||
"select iter from test7 where v_char[$iter] LIKE ?", $v_char[$iter]."%")) ||
|
||||
!ibase_fetch_row($sel)) {
|
||||
echo "CHAR fail\n";
|
||||
}
|
||||
ibase_free_result($sel);
|
||||
|
||||
if(!($sel = ibase_query(
|
||||
"select iter from test7 where v_date[$iter] = ?", $v_date[$iter])) ||
|
||||
!ibase_fetch_row($sel)) {
|
||||
echo "DATE fail\n";
|
||||
}
|
||||
ibase_free_result($sel);
|
||||
if(!($sel = ibase_query(
|
||||
"select iter from test7 where v_decimal[$iter] = ?", $v_decimal[$iter])) ||
|
||||
!ibase_fetch_row($sel)) {
|
||||
echo "DECIMAL fail\n";
|
||||
}
|
||||
ibase_free_result($sel);
|
||||
if(!($sel = ibase_query(
|
||||
"select iter from test7 where v_integer[$iter] = ?", $v_integer[$iter])) ||
|
||||
!ibase_fetch_row($sel)) {
|
||||
echo "INTEGER fail\n";
|
||||
}
|
||||
ibase_free_result($sel);
|
||||
if(!($sel = ibase_query(
|
||||
"select iter from test7 where v_numeric[$iter] = ?", $v_numeric[$iter])) ||
|
||||
!ibase_fetch_row($sel)) {
|
||||
echo "NUMERIC fail\n";
|
||||
}
|
||||
ibase_free_result($sel);
|
||||
if(!($sel = ibase_query(
|
||||
"select iter from test7 where v_smallint[$iter] = ?", $v_smallint[$iter])) ||
|
||||
!ibase_fetch_row($sel)) {
|
||||
echo "SMALLINT fail\n";
|
||||
}
|
||||
ibase_free_result($sel);
|
||||
}
|
||||
ibase_close();
|
||||
echo "end of test\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
insert
|
||||
select
|
||||
Array
|
||||
(
|
||||
[0] => 125
|
||||
[1] => 1000
|
||||
)
|
||||
end of test
|
@ -1,48 +0,0 @@
|
||||
--TEST--
|
||||
InterBase: event handling
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (PHP_OS == "WINNT") echo "skip";
|
||||
include("skipif.inc");
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require("interbase.inc");
|
||||
|
||||
$count = 0;
|
||||
|
||||
function event_callback($event)
|
||||
{
|
||||
global $count;
|
||||
if ($event == 'TEST1') echo "FAIL TEST1\n";
|
||||
return (++$count < 5); /* cancel event */
|
||||
}
|
||||
|
||||
$link = ibase_connect($test_base);
|
||||
|
||||
ibase_query("CREATE PROCEDURE pevent AS BEGIN POST_EVENT 'TEST1'; POST_EVENT 'TEST2'; END");
|
||||
ibase_commit();
|
||||
|
||||
$e = ibase_set_event_handler('event_callback','TEST1');
|
||||
ibase_free_event_handler($e);
|
||||
|
||||
ibase_set_event_handler('event_callback','TEST2');
|
||||
|
||||
usleep(5E+5);
|
||||
|
||||
for ($i = 0; $i < 8; ++$i) {
|
||||
ibase_query("EXECUTE PROCEDURE pevent");
|
||||
ibase_commit();
|
||||
|
||||
usleep(3E+5);
|
||||
}
|
||||
|
||||
usleep(5E+5);
|
||||
|
||||
if (!$count || $count > 5) echo "FAIL ($count)\n";
|
||||
echo "end of test\n";
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
end of test
|
@ -1,47 +0,0 @@
|
||||
--TEST--
|
||||
Bug #45373 (php crash on query with errors in params)
|
||||
--SKIPIF--
|
||||
<?php include("skipif.inc"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require("interbase.inc");
|
||||
|
||||
$db = ibase_connect($test_base);
|
||||
|
||||
|
||||
$sql = "select * from test1 where i = ? and c = ?";
|
||||
|
||||
$q = ibase_prepare($db, $sql);
|
||||
$r = ibase_execute($q, 1, 'test table not created with isql');
|
||||
var_dump(ibase_fetch_assoc($r));
|
||||
ibase_free_result($r);
|
||||
|
||||
$r = ibase_execute($q, 1, 'test table not created with isql', 1);
|
||||
var_dump(ibase_fetch_assoc($r));
|
||||
ibase_free_result($r);
|
||||
|
||||
$r = ibase_execute($q, 1);
|
||||
var_dump(ibase_fetch_assoc($r));
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
array(2) {
|
||||
["I"]=>
|
||||
int(1)
|
||||
["C"]=>
|
||||
string(32) "test table not created with isql"
|
||||
}
|
||||
|
||||
Notice: ibase_execute(): Statement expects 2 arguments, 3 given in %s on line %d
|
||||
array(2) {
|
||||
["I"]=>
|
||||
int(1)
|
||||
["C"]=>
|
||||
string(32) "test table not created with isql"
|
||||
}
|
||||
|
||||
Warning: ibase_execute(): Statement expects 2 arguments, 1 given in %s on line %d
|
||||
|
||||
Warning: ibase_fetch_assoc() expects parameter 1 to be resource, bool given in %s on line %d
|
||||
NULL
|
@ -1,22 +0,0 @@
|
||||
--TEST--
|
||||
Bug #45575 (Segfault with invalid non-string as event handler callback)
|
||||
--SKIPIF--
|
||||
<?php include("skipif.inc"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require("interbase.inc");
|
||||
|
||||
$db = ibase_connect($test_base);
|
||||
|
||||
function foobar($var) { var_dump($var); return true; }
|
||||
|
||||
ibase_set_event_handler($db, null, 'TEST1');
|
||||
ibase_set_event_handler($db, 1, 'TEST1');
|
||||
ibase_set_event_handler('foobar', 'TEST1');
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: ibase_set_event_handler(): Callback argument is not a callable function in %s on line %d
|
||||
|
||||
Warning: ibase_set_event_handler(): Callback argument 1 is not a callable function in %s on line %d
|
@ -1,35 +0,0 @@
|
||||
--TEST--
|
||||
Bug #46247 (ibase_set_event_handler() is allowing to pass callback without event)
|
||||
--SKIPIF--
|
||||
<?php include("skipif.inc"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require("interbase.inc");
|
||||
|
||||
$db = ibase_connect($test_base);
|
||||
|
||||
function test() { }
|
||||
|
||||
ibase_set_event_handler();
|
||||
|
||||
ibase_set_event_handler('test', 1);
|
||||
ibase_set_event_handler($db, 'test', 1);
|
||||
ibase_set_event_handler(NULL, 'test', 1);
|
||||
|
||||
|
||||
ibase_set_event_handler('foo', 1);
|
||||
ibase_set_event_handler($db, 'foo', 1);
|
||||
ibase_set_event_handler(NULL, 'foo', 1);
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: Wrong parameter count for ibase_set_event_handler() in %s on line %d
|
||||
|
||||
Warning: ibase_set_event_handler(): supplied argument is not a valid InterBase link resource in %s on line %d
|
||||
|
||||
Warning: ibase_set_event_handler(): Callback argument foo is not a callable function in %s on line %d
|
||||
|
||||
Warning: ibase_set_event_handler(): Callback argument foo is not a callable function in %s on line %d
|
||||
|
||||
Warning: ibase_set_event_handler(): supplied argument is not a valid InterBase link resource in %s on line %d
|
@ -1,28 +0,0 @@
|
||||
--TEST--
|
||||
Bug #46543 (ibase_trans() memory leaks when using wrong parameters)
|
||||
--SKIPIF--
|
||||
<?php include("skipif.inc"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require("interbase.inc");
|
||||
|
||||
@ibase_close();
|
||||
|
||||
ibase_trans(1);
|
||||
ibase_trans();
|
||||
ibase_trans('foo');
|
||||
ibase_trans(fopen(__FILE__, 'r'));
|
||||
|
||||
$x = ibase_connect($test_base);
|
||||
ibase_trans(1, 2, $x, $x, 3);
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: ibase_trans(): supplied resource is not a valid Firebird/InterBase link resource in %sbug46543.php on line %d
|
||||
|
||||
Warning: ibase_trans(): supplied resource is not a valid Firebird/InterBase link resource in %sbug46543.php on line %d
|
||||
|
||||
Warning: ibase_trans(): supplied resource is not a valid Firebird/InterBase link resource in %sbug46543.php on line %d
|
||||
|
||||
Warning: ibase_trans(): supplied resource is not a valid Firebird/InterBase link resource in %sbug46543.php on line %d
|
@ -1,32 +0,0 @@
|
||||
--TEST--
|
||||
ibase_affected_rows(): Basic test
|
||||
--SKIPIF--
|
||||
<?php include("skipif.inc"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require("interbase.inc");
|
||||
|
||||
$x = ibase_connect($test_base);
|
||||
|
||||
ibase_query($x, 'INSERT INTO test1 VALUES (1, 100)');
|
||||
ibase_query($x, 'INSERT INTO test1 VALUES (10000, 100)');
|
||||
|
||||
ibase_query($x, 'UPDATE test1 SET i = 10000');
|
||||
var_dump(ibase_affected_rows($x));
|
||||
|
||||
|
||||
ibase_query($x, 'UPDATE test1 SET i = 10000 WHERE i = 2.0');
|
||||
var_dump(ibase_affected_rows($x));
|
||||
|
||||
ibase_query($x, 'UPDATE test1 SET i =');
|
||||
var_dump(ibase_affected_rows($x));
|
||||
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
int(3)
|
||||
int(0)
|
||||
|
||||
Warning: ibase_query(): Dynamic SQL Error SQL error code = -104 %s on line %d
|
||||
int(0)
|
@ -1,23 +0,0 @@
|
||||
--TEST--
|
||||
ibase_close(): Basic test
|
||||
--SKIPIF--
|
||||
<?php include("skipif.inc"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require("interbase.inc");
|
||||
|
||||
$x = ibase_connect($test_base);
|
||||
var_dump(ibase_close($x));
|
||||
var_dump(ibase_close($x));
|
||||
var_dump(ibase_close());
|
||||
var_dump(ibase_close('foo'));
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: ibase_close() expects parameter 1 to be resource, string given in %s on line %d
|
||||
NULL
|
@ -1,31 +0,0 @@
|
||||
--TEST--
|
||||
ibase_drop_db(): Basic test
|
||||
--SKIPIF--
|
||||
<?php include("skipif.inc"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require("interbase.inc");
|
||||
|
||||
unlink($file = tempnam('/tmp',"php_ibase_test"));
|
||||
|
||||
|
||||
$db = ibase_query(IBASE_CREATE,
|
||||
sprintf("CREATE SCHEMA '%s' USER '%s' PASSWORD '%s' DEFAULT CHARACTER SET %s",$file,
|
||||
$user, $password, ($charset = ini_get('ibase.default_charset')) ? $charset : 'NONE'));
|
||||
|
||||
var_dump($db);
|
||||
var_dump(ibase_drop_db($db));
|
||||
var_dump(ibase_drop_db(1));
|
||||
var_dump(ibase_drop_db(NULL));
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
resource(%d) of type (Firebird/InterBase link)
|
||||
bool(true)
|
||||
|
||||
Warning: ibase_drop_db() expects parameter 1 to be resource, int given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: ibase_drop_db() expects parameter 1 to be resource, null given in %s on line %d
|
||||
NULL
|
@ -1,22 +0,0 @@
|
||||
--TEST--
|
||||
ibase_errmsg(): Basic test
|
||||
--SKIPIF--
|
||||
<?php include("skipif.inc"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require("interbase.inc");
|
||||
|
||||
$x = ibase_connect($test_base);
|
||||
|
||||
ibase_query('SELECT Foobar');
|
||||
var_dump(ibase_errmsg());
|
||||
|
||||
ibase_close($x);
|
||||
var_dump(ibase_errmsg());
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: ibase_query(): Dynamic SQL Error SQL error code = -104 %s on line %d
|
||||
string(%d) "Dynamic SQL Error SQL error code = -104 %s"
|
||||
bool(false)
|
@ -1,28 +0,0 @@
|
||||
--TEST--
|
||||
ibase_free_query(): Basic test
|
||||
--SKIPIF--
|
||||
<?php include("skipif.inc"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require("interbase.inc");
|
||||
|
||||
$x = ibase_connect($test_base);
|
||||
|
||||
$q =ibase_prepare($x, 'SELECT 1 FROM test1 WHERE i = ?');
|
||||
$q =ibase_prepare($x, 'SELECT 1 FROM test1 WHERE i = ?');
|
||||
$q = ibase_prepare($x, 'SELECT 1 FROM test1 WHERE i = ?');
|
||||
|
||||
var_dump(ibase_free_query($q));
|
||||
var_dump(ibase_free_query($q));
|
||||
var_dump(ibase_free_query($x));
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
bool(true)
|
||||
|
||||
Warning: ibase_free_query(): supplied resource is not a valid Firebird/InterBase query resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: ibase_free_query(): supplied resource is not a valid Firebird/InterBase query resource in %s on line %d
|
||||
bool(false)
|
@ -1,25 +0,0 @@
|
||||
--TEST--
|
||||
ibase_num_fields(): Basic test
|
||||
--SKIPIF--
|
||||
<?php include("skipif.inc"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require("interbase.inc");
|
||||
|
||||
$x = ibase_connect($test_base);
|
||||
|
||||
var_dump(ibase_num_fields(ibase_query('SELECT * FROM test1')));
|
||||
|
||||
var_dump(ibase_num_fields(1));
|
||||
var_dump(ibase_num_fields());
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
int(2)
|
||||
|
||||
Warning: ibase_num_fields() expects parameter 1 to be resource, int given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: ibase_num_fields() expects exactly 1 parameter, 0 given in %s on line %d
|
||||
NULL
|
@ -1,32 +0,0 @@
|
||||
--TEST--
|
||||
ibase_num_params(): Basic test
|
||||
--SKIPIF--
|
||||
<?php include("skipif.inc"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require("interbase.inc");
|
||||
|
||||
$x = ibase_connect($test_base);
|
||||
|
||||
$rs = ibase_prepare('SELECT * FROM test1 WHERE 1 = ? AND 2 = ?');
|
||||
var_dump(ibase_num_params($rs));
|
||||
|
||||
$rs = ibase_prepare('SELECT * FROM test1 WHERE 1 = ? AND 2 = ?');
|
||||
var_dump(ibase_num_params());
|
||||
|
||||
$rs = ibase_prepare('SELECT * FROM test1 WHERE 1 = ? AND 2 = ? AND 3 = :x');
|
||||
var_dump(ibase_num_params($rs));
|
||||
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
int(2)
|
||||
|
||||
Warning: ibase_num_params() expects exactly 1 parameter, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: ibase_prepare(): Dynamic SQL Error SQL error code = -206 %s in %s on line %d
|
||||
|
||||
Warning: ibase_num_params() expects parameter 1 to be resource, bool given in %s on line %d
|
||||
NULL
|
@ -1,53 +0,0 @@
|
||||
--TEST--
|
||||
ibase_param_info(): Basic test
|
||||
--SKIPIF--
|
||||
<?php include("skipif.inc"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require("interbase.inc");
|
||||
|
||||
$x = ibase_connect($test_base);
|
||||
|
||||
$rs = ibase_prepare('SELECT * FROM test1 WHERE 1 = ? AND 2 = ?');
|
||||
var_dump(ibase_param_info($rs, 1));
|
||||
|
||||
print "---\n";
|
||||
|
||||
var_dump(ibase_param_info($rs, 100));
|
||||
|
||||
print "---\n";
|
||||
|
||||
var_dump(ibase_param_info(100));
|
||||
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
array(10) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
["name"]=>
|
||||
string(0) ""
|
||||
[1]=>
|
||||
string(0) ""
|
||||
["alias"]=>
|
||||
string(0) ""
|
||||
[2]=>
|
||||
string(0) ""
|
||||
["relation"]=>
|
||||
string(0) ""
|
||||
[3]=>
|
||||
string(1) "4"
|
||||
["length"]=>
|
||||
string(1) "4"
|
||||
[4]=>
|
||||
string(7) "INTEGER"
|
||||
["type"]=>
|
||||
string(7) "INTEGER"
|
||||
}
|
||||
---
|
||||
bool(false)
|
||||
---
|
||||
|
||||
Warning: ibase_param_info() expects exactly 2 parameters, 1 given in %s on line %d
|
||||
NULL
|
@ -1,41 +0,0 @@
|
||||
--TEST--
|
||||
ibase_rollback(): Basic test
|
||||
--SKIPIF--
|
||||
<?php include("skipif.inc"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require("interbase.inc");
|
||||
|
||||
$x = ibase_connect($test_base);
|
||||
|
||||
ibase_query('INSERT INTO test1 VALUES (100, 2)');
|
||||
ibase_query('INSERT INTO test1 VALUES (100, 2)');
|
||||
ibase_query('INSERT INTO test1 VALUES (100, 2)');
|
||||
|
||||
$rs = ibase_query('SELECT COUNT(*) FROM test1 WHERE i = 100');
|
||||
var_dump(ibase_fetch_row($rs));
|
||||
|
||||
var_dump(ibase_rollback($x));
|
||||
|
||||
$rs = ibase_query('SELECT COUNT(*) FROM test1 WHERE i = 100');
|
||||
var_dump(ibase_fetch_row($rs));
|
||||
|
||||
var_dump(ibase_rollback($x));
|
||||
var_dump(ibase_rollback());
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(3)
|
||||
}
|
||||
bool(true)
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(0)
|
||||
}
|
||||
bool(true)
|
||||
|
||||
Warning: ibase_rollback(): invalid transaction handle (expecting explicit transaction start) in %s on line %d
|
||||
bool(false)
|
@ -1,21 +0,0 @@
|
||||
--TEST--
|
||||
ibase_trans(): Basic test
|
||||
--SKIPIF--
|
||||
<?php include("skipif.inc"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require("interbase.inc");
|
||||
|
||||
$x = ibase_connect($test_base);
|
||||
var_dump(ibase_trans($x));
|
||||
var_dump(ibase_trans(1));
|
||||
var_dump(ibase_close());
|
||||
var_dump(ibase_close($x));
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
resource(%d) of type (Firebird/InterBase transaction)
|
||||
resource(%d) of type (Firebird/InterBase transaction)
|
||||
bool(true)
|
||||
bool(true)
|
@ -1,34 +0,0 @@
|
||||
--TEST--
|
||||
ibase_trans(): Basic operations
|
||||
--SKIPIF--
|
||||
<?php include("skipif.inc"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require("interbase.inc");
|
||||
|
||||
$x = ibase_connect($test_base);
|
||||
|
||||
$trans = ibase_trans(IBASE_DEFAULT, $x);
|
||||
$sth = ibase_prepare($trans, 'INSERT INTO test1 VALUES (?, ?)');
|
||||
|
||||
$res = ibase_execute($sth, 100, 100);
|
||||
var_dump($res);
|
||||
|
||||
ibase_commit($trans);
|
||||
|
||||
$rs = ibase_query($x, 'SELECT * FROM test1 WHERE i = 100');
|
||||
var_dump(ibase_fetch_assoc($rs));
|
||||
|
||||
ibase_free_query($sth);
|
||||
unset($res);
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
int(1)
|
||||
array(2) {
|
||||
["I"]=>
|
||||
int(100)
|
||||
["C"]=>
|
||||
string(3) "100"
|
||||
}
|
@ -1,120 +0,0 @@
|
||||
<?php
|
||||
|
||||
srand((double)microtime()*1000000);
|
||||
|
||||
$user = 'SYSDBA';
|
||||
$password = 'masterkey';
|
||||
ini_set('ibase.default_user',$user);
|
||||
ini_set('ibase.default_password',$password);
|
||||
|
||||
/* we need just the generated name, not the file itself */
|
||||
unlink($test_base = tempnam(sys_get_temp_dir(),"php_ibase_test"));
|
||||
|
||||
function init_db()
|
||||
{
|
||||
global $test_base, $user, $password;
|
||||
|
||||
$test_db = ibase_query(IBASE_CREATE,
|
||||
sprintf("CREATE SCHEMA '%s' USER '%s' PASSWORD '%s' DEFAULT CHARACTER SET %s",$test_base,
|
||||
$user, $password, ($charset = ini_get('ibase.default_charset')) ? $charset : 'NONE'));
|
||||
$tr = ibase_trans($test_db);
|
||||
ibase_query($tr,"create table test1 (i integer, c varchar(100))");
|
||||
ibase_commit_ret($tr);
|
||||
ibase_query($tr,"insert into test1(i, c) values(1, 'test table not created with isql')");
|
||||
ibase_commit($tr);
|
||||
ibase_close($test_db);
|
||||
}
|
||||
|
||||
function cleanup_db()
|
||||
{
|
||||
global $test_base;
|
||||
|
||||
$r = ibase_connect($test_base);
|
||||
ibase_drop_db($r);
|
||||
}
|
||||
|
||||
register_shutdown_function('cleanup_db');
|
||||
init_db();
|
||||
|
||||
function out_table($table_name)
|
||||
{
|
||||
echo "--- $table_name ---\n";
|
||||
$res = ibase_query("select * from $table_name");
|
||||
while ($r = ibase_fetch_row($res)) {
|
||||
echo join("\t",$r)."\t\n";
|
||||
}
|
||||
ibase_free_result($res);
|
||||
echo "---\n";
|
||||
}
|
||||
|
||||
function out_result($result, $table_name = "")
|
||||
{
|
||||
echo "--- $table_name ---\n";
|
||||
while ($r = ibase_fetch_row($result)) {
|
||||
echo join("\t",$r)."\t\n";
|
||||
}
|
||||
echo "---\n";
|
||||
}
|
||||
|
||||
function out_result_trap_error($result, $table_name = "")
|
||||
{
|
||||
echo "--- $table_name ---\n";
|
||||
while ($r = @ibase_fetch_row($result)) {
|
||||
echo join("\t",$r)."\t\n";
|
||||
}
|
||||
echo "errmsg [" . ibase_errmsg() . "]\n";
|
||||
echo "---\n";
|
||||
}
|
||||
|
||||
/* M/D/Y H:M:S */
|
||||
function rand_datetime()
|
||||
{
|
||||
return sprintf("%02d/%02d/%4d %02d:%02d:%02d",
|
||||
rand()%12+1, rand()%28+1, rand()%100+1910,
|
||||
rand()%24, rand()%60, rand()%60);
|
||||
}
|
||||
|
||||
/* random binary string */
|
||||
function rand_binstr($max_len)
|
||||
{
|
||||
$len = rand() % $max_len;
|
||||
$s = "";
|
||||
while($len--) {
|
||||
$s .= sprintf("%c", rand() % 256);
|
||||
}
|
||||
return $s;
|
||||
}
|
||||
|
||||
function rand_str($max_len)
|
||||
{
|
||||
$len = rand() % $max_len;
|
||||
$s = "";
|
||||
while ($len--) {
|
||||
$s .= sprintf("%c", rand() % 26 + 65);
|
||||
}
|
||||
return $s;
|
||||
}
|
||||
|
||||
function rand_number($len , $prec = -1, $sign = 1)
|
||||
{
|
||||
if ($prec == -1) {
|
||||
$n = substr(rand() . rand(), 0, rand() % $len + 1);
|
||||
if (strlen($n) < $len) {
|
||||
$n .= "." . substr(rand(), 0, rand() % ($len - strlen($n)) + 1);
|
||||
}
|
||||
} else if ($prec == 0) {
|
||||
$n = substr(rand() . rand(), 0, rand() % $len + 1);
|
||||
} else if (($prec - $len) == 0) {
|
||||
$n = substr(rand() . rand(), 0, 1);
|
||||
$n .= "." . substr(rand(), 0, $prec);
|
||||
} else {
|
||||
$n = substr(rand() . rand(), 0, rand() % ($len - $prec) + 1);
|
||||
$n .= "." . substr(rand(), 0, $prec);
|
||||
}
|
||||
if ($sign && (rand() % 3 == 0)) {
|
||||
$n = "-" .$n;
|
||||
}
|
||||
return $n;
|
||||
}
|
||||
|
||||
?>
|
@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
if (!extension_loaded("interbase")) print "skip interbase extension not available";
|
||||
require("interbase.inc");
|
||||
if(!@ibase_connect($test_base)){
|
||||
die("skip cannot connect");
|
||||
}
|
||||
?>
|
@ -32,7 +32,6 @@ CREDIT_LINE("GNU GMP support", "Stanislav Malyshev");
|
||||
CREDIT_LINE("Iconv", "Rui Hirokawa, Stig Bakken, Moriyoshi Koizumi");
|
||||
CREDIT_LINE("IMAP", "Rex Logan, Mark Musone, Brian Wang, Kaj-Michael Lang, Antoni Pamies Olive, Rasmus Lerdorf, Andrew Skalski, Chuck Hagenbuch, Daniel R Kalowsky");
|
||||
CREDIT_LINE("Input Filter", "Rasmus Lerdorf, Derick Rethans, Pierre-Alain Joye, Ilia Alshanetsky");
|
||||
CREDIT_LINE("InterBase", "Jouni Ahto, Andrew Avdeev, Ard Biesheuvel");
|
||||
CREDIT_LINE("Internationalization", "Ed Batutis, Vladimir Iordanov, Dmitry Lakhtyuk, Stanislav Malyshev, Vadim Savchuk, Kirti Velankar");
|
||||
CREDIT_LINE("JSON", "Jakub Zelenka, Omar Kilani, Scott MacVicar");
|
||||
CREDIT_LINE("LDAP", "Amitay Isaacs, Eric Warnke, Rasmus Lerdorf, Gerrit Thomson, Stig Venaas");
|
||||
|
Loading…
Reference in New Issue
Block a user