mirror of
https://github.com/php/php-src.git
synced 2024-12-02 22:34:55 +08:00
added initial support for PostgreSQL to ext/dbx.
This commit is contained in:
parent
10bb608e4e
commit
6ee15704e8
@ -32,10 +32,12 @@
|
||||
#define DBX_UNKNOWN 0
|
||||
#define DBX_MYSQL 1
|
||||
#define DBX_ODBC 2
|
||||
#define DBX_PGSQL 3
|
||||
/*/ includes for supported databases /*/
|
||||
#include "dbx.h"
|
||||
#include "dbx_mysql.h"
|
||||
#include "dbx_odbc.h"
|
||||
#include "dbx_pgsql.h"
|
||||
|
||||
/*/ support routines /*/
|
||||
int module_exists(char * module_name) {
|
||||
@ -48,6 +50,7 @@ int module_exists(char * module_name) {
|
||||
int get_module_identifier(char * module_name) {
|
||||
if (!strcmp("mysql", module_name)) return DBX_MYSQL;
|
||||
if (!strcmp("odbc", module_name)) return DBX_ODBC;
|
||||
if (!strcmp("pgsql", module_name)) return DBX_PGSQL;
|
||||
return DBX_UNKNOWN;
|
||||
}
|
||||
|
||||
@ -98,11 +101,22 @@ int switch_dbx_getrow(zval ** rv, zval ** result_handle, INTERNAL_FUNCTION_PARAM
|
||||
int switch_dbx_error(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module);
|
||||
/*/ returns string /*/
|
||||
|
||||
#ifdef ZTS
|
||||
int dbx_globals_id;
|
||||
#else
|
||||
ZEND_DBX_API zend_dbx_globals dbx_globals;
|
||||
#endif
|
||||
/* If you declare any globals in php_dbx.h uncomment this: */
|
||||
/*/ZEND_DECLARE_MODULE_GLOBALS(dbx) /*/
|
||||
/* ZEND_DECLARE_MODULE_GLOBALS(dbx) */
|
||||
/* True global resources - no need for thread safety here */
|
||||
static int le_dbx;
|
||||
|
||||
static void zend_dbx_init_globals(PGLS_D)
|
||||
{
|
||||
DBXG(row_count) = 0;
|
||||
DBXG(num_rows) = 0;
|
||||
}
|
||||
|
||||
/* Every user visible function must have an entry in dbx_functions[].
|
||||
*/
|
||||
function_entry dbx_functions[] = {
|
||||
@ -141,8 +155,12 @@ ZEND_GET_MODULE(dbx)
|
||||
/*/
|
||||
ZEND_MINIT_FUNCTION(dbx)
|
||||
{
|
||||
/*/ zend_dbx_globals *dbx_globals; /*/
|
||||
/*/ ZEND_INIT_MODULE_GLOBALS(dbx, NULL, NULL); /*/
|
||||
|
||||
#ifdef ZTS
|
||||
dbx_globals_id = ts_allocate_id(sizeof(zend_dbx_globals), (ts_allocate_ctor) zend_dbx_init_globals, NULL);
|
||||
#else
|
||||
zend_dbx_init_globals(DBXLS_C);
|
||||
#endif
|
||||
|
||||
/*/ REGISTER_INI_ENTRIES(); /*/
|
||||
|
||||
@ -151,20 +169,14 @@ ZEND_MINIT_FUNCTION(dbx)
|
||||
REGISTER_LONG_CONSTANT("DBX_RESULT_INDEX", DBX_RESULT_INDEX, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("DBX_RESULT_ASSOC", DBX_RESULT_ASSOC, CONST_CS | CONST_PERSISTENT);
|
||||
|
||||
/*/ dbx_globals = ts_resource(dbx_globals_id); /*/
|
||||
/*/ global_dbx_ctor(&DBXG(dbx_global)); /*/
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
ZEND_MSHUTDOWN_FUNCTION(dbx)
|
||||
{
|
||||
/*/ DBXLS_FETCH(); /*/
|
||||
/*/ global_dbx_dtor(&DBXG(dbx_global)); /*/
|
||||
|
||||
/*/ UNREGISTER_INI_ENTRIES(); /*/
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove if there's nothing to do at request start */
|
||||
/*ZEND_RINIT_FUNCTION(dbx)
|
||||
@ -182,6 +194,7 @@ ZEND_MINFO_FUNCTION(dbx)
|
||||
php_info_print_table_row(2, "dbx support", "enabled");
|
||||
php_info_print_table_row(2, "dbx support for MySQL", "enabled");
|
||||
php_info_print_table_row(2, "dbx support for ODBC", "enabled");
|
||||
php_info_print_table_row(2, "dbx support for PostgreSQL", "enabled");
|
||||
php_info_print_table_end();
|
||||
/*/ DISPLAY_INI_ENTRIES(); /*/
|
||||
}
|
||||
@ -677,6 +690,7 @@ int switch_dbx_connect(zval ** rv, zval ** host, zval ** db, zval ** username, z
|
||||
switch ((*dbx_module)->value.lval) {
|
||||
case DBX_MYSQL: return dbx_mysql_connect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
case DBX_ODBC: return dbx_odbc_connect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
case DBX_PGSQL: return dbx_pgsql_connect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
}
|
||||
zend_error(E_WARNING, "dbx_connect: not supported in this module");
|
||||
return 0;
|
||||
@ -687,6 +701,7 @@ int switch_dbx_pconnect(zval ** rv, zval ** host, zval ** db, zval ** username,
|
||||
switch ((*dbx_module)->value.lval) {
|
||||
case DBX_MYSQL: return dbx_mysql_pconnect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
case DBX_ODBC: return dbx_odbc_pconnect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
case DBX_PGSQL: return dbx_pgsql_pconnect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
}
|
||||
zend_error(E_WARNING, "dbx_pconnect: not supported in this module");
|
||||
return 0;
|
||||
@ -697,6 +712,7 @@ int switch_dbx_close(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETER
|
||||
switch ((*dbx_module)->value.lval) {
|
||||
case DBX_MYSQL: return dbx_mysql_close(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
case DBX_ODBC: return dbx_odbc_close(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
case DBX_PGSQL: return dbx_pgsql_close(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
}
|
||||
zend_error(E_WARNING, "dbx_close: not supported in this module");
|
||||
return 0;
|
||||
@ -707,6 +723,7 @@ int switch_dbx_query(zval ** rv, zval ** dbx_handle, zval ** sql_statement, INTE
|
||||
switch ((*dbx_module)->value.lval) {
|
||||
case DBX_MYSQL: return dbx_mysql_query(rv, dbx_handle, sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
case DBX_ODBC: return dbx_odbc_query(rv, dbx_handle, sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
case DBX_PGSQL: return dbx_pgsql_query(rv, dbx_handle, sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
}
|
||||
zend_error(E_WARNING, "dbx_query: not supported in this module");
|
||||
return 0;
|
||||
@ -717,6 +734,7 @@ int switch_dbx_getcolumncount(zval ** rv, zval ** result_handle, INTERNAL_FUNCTI
|
||||
switch ((*dbx_module)->value.lval) {
|
||||
case DBX_MYSQL: return dbx_mysql_getcolumncount(rv, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
case DBX_ODBC: return dbx_odbc_getcolumncount(rv, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
case DBX_PGSQL: return dbx_pgsql_getcolumncount(rv, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
}
|
||||
zend_error(E_WARNING, "dbx_getcolumncount: not supported in this module");
|
||||
return 0;
|
||||
@ -727,6 +745,7 @@ int switch_dbx_getcolumnname(zval ** rv, zval ** result_handle, long column_inde
|
||||
switch ((*dbx_module)->value.lval) {
|
||||
case DBX_MYSQL: return dbx_mysql_getcolumnname(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
case DBX_ODBC: return dbx_odbc_getcolumnname(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
case DBX_PGSQL: return dbx_pgsql_getcolumnname(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
}
|
||||
zend_error(E_WARNING, "dbx_getcolumnname: not supported in this module");
|
||||
return 0;
|
||||
@ -737,6 +756,7 @@ int switch_dbx_getcolumntype(zval ** rv, zval ** result_handle, long column_inde
|
||||
switch ((*dbx_module)->value.lval) {
|
||||
case DBX_MYSQL: return dbx_mysql_getcolumntype(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
case DBX_ODBC: return dbx_odbc_getcolumntype(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
case DBX_PGSQL: return dbx_pgsql_getcolumntype(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
}
|
||||
zend_error(E_WARNING, "dbx_getcolumntype: not supported in this module");
|
||||
return 0;
|
||||
@ -747,6 +767,7 @@ int switch_dbx_getrow(zval ** rv, zval ** result_handle, INTERNAL_FUNCTION_PARAM
|
||||
switch ((*dbx_module)->value.lval) {
|
||||
case DBX_MYSQL: return dbx_mysql_getrow(rv, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
case DBX_ODBC: return dbx_odbc_getrow(rv, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
case DBX_PGSQL: return dbx_pgsql_getrow(rv, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
}
|
||||
zend_error(E_WARNING, "dbx_getrow: not supported in this module");
|
||||
return 0;
|
||||
@ -757,6 +778,7 @@ int switch_dbx_error(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETER
|
||||
switch ((*dbx_module)->value.lval) {
|
||||
case DBX_MYSQL: return dbx_mysql_error(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
case DBX_ODBC: return dbx_odbc_error(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
case DBX_PGSQL: return dbx_pgsql_error(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
||||
}
|
||||
zend_error(E_WARNING, "dbx_error: not supported in this module");
|
||||
return 0;
|
||||
|
281
ext/dbx/dbx_pgsql.c
Normal file
281
ext/dbx/dbx_pgsql.c
Normal file
@ -0,0 +1,281 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| stentor module version 1.0 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 2001 Guidance Rotterdam BV |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 1.0 of the STENTOR license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at |
|
||||
| http://www.guidance.nl/php/dbx/license/1_00.txt. |
|
||||
| If you did not receive a copy of the STENTOR license and are unable |
|
||||
| to obtain it through the world-wide-web, please send a note to |
|
||||
| license@guidance.nl so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author : Rui Hirokawa <hirokawa@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#include "dbx.h"
|
||||
#include "php_dbx.h"
|
||||
#include "dbx_pgsql.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifdef ZTS
|
||||
extern int dbx_globals_id;
|
||||
#else
|
||||
extern ZEND_DBX_API zend_dbx_globals dbx_globals;
|
||||
#endif
|
||||
|
||||
#define PGSQL_ASSOC 1<<0
|
||||
#define PGSQL_NUM 1<<1
|
||||
|
||||
int dbx_pgsql_connect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS) {
|
||||
/* returns connection handle as resource on success or 0
|
||||
as long on failure */
|
||||
int nargs=5;
|
||||
char *port="5432", *connstring=NULL;
|
||||
zval **args[5], *rarg = NULL;
|
||||
zval *conn_zval = NULL;
|
||||
zval *returned_zval=NULL;
|
||||
|
||||
MAKE_STD_ZVAL(conn_zval);
|
||||
|
||||
if (Z_STRLEN_PP(username)>0 && Z_STRLEN_PP(password)>0){
|
||||
int len;
|
||||
|
||||
len = Z_STRLEN_PP(host)+Z_STRLEN_PP(db)+strlen(port);
|
||||
len += Z_STRLEN_PP(username)+Z_STRLEN_PP(password)+35;
|
||||
connstring = (char *)emalloc(len+1);
|
||||
sprintf(connstring, "host=%s port=%s dbname=%s user=%s password=%s",
|
||||
Z_STRVAL_PP(host),port, Z_STRVAL_PP(db),
|
||||
Z_STRVAL_PP(username), Z_STRVAL_PP(password));
|
||||
ZVAL_STRING(conn_zval, connstring, 1);
|
||||
args[0] = &conn_zval;
|
||||
nargs = 1;
|
||||
} else {
|
||||
int k;
|
||||
|
||||
args[0] = host;
|
||||
for (k=1;k<4;k++){
|
||||
MAKE_STD_ZVAL(rarg);
|
||||
ZVAL_EMPTY_STRING(rarg);
|
||||
args[k] = &rarg;
|
||||
}
|
||||
args[4] = db;
|
||||
}
|
||||
dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "pg_connect", &returned_zval, nargs, args);
|
||||
|
||||
if (!returned_zval || returned_zval->type!=IS_RESOURCE) {
|
||||
if (returned_zval) zval_ptr_dtor(&returned_zval);
|
||||
return 0;
|
||||
}
|
||||
MOVE_RETURNED_TO_RV(rv, returned_zval);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dbx_pgsql_pconnect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS) {
|
||||
/* returns persistent connection handle as resource on success or 0
|
||||
as long on failure */
|
||||
int nargs=5;
|
||||
char *port="5432", *connstring=NULL;
|
||||
zval **args[5], *rarg = NULL;
|
||||
zval *conn_zval = NULL;
|
||||
zval *returned_zval=NULL;
|
||||
|
||||
MAKE_STD_ZVAL(conn_zval);
|
||||
|
||||
if (Z_STRLEN_PP(username)>0 && Z_STRLEN_PP(password)>0){
|
||||
int len;
|
||||
|
||||
len = Z_STRLEN_PP(host)+Z_STRLEN_PP(db)+strlen(port);
|
||||
len += Z_STRLEN_PP(username)+Z_STRLEN_PP(password)+35;
|
||||
connstring = (char *)emalloc(len+1);
|
||||
sprintf(connstring, "host=%s port=%s dbname=%s user=%s password=%s",
|
||||
Z_STRVAL_PP(host),port, Z_STRVAL_PP(db),
|
||||
Z_STRVAL_PP(username), Z_STRVAL_PP(password));
|
||||
ZVAL_STRING(conn_zval, connstring, 1);
|
||||
args[0] = &conn_zval;
|
||||
nargs = 1;
|
||||
} else {
|
||||
int k;
|
||||
|
||||
args[0] = host;
|
||||
for (k=1;k<4;k++){
|
||||
MAKE_STD_ZVAL(rarg);
|
||||
ZVAL_EMPTY_STRING(rarg);
|
||||
args[k] = &rarg;
|
||||
}
|
||||
args[4] = db;
|
||||
}
|
||||
dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "pg_pconnect", &returned_zval, nargs, args);
|
||||
|
||||
if (!returned_zval || returned_zval->type!=IS_RESOURCE) {
|
||||
if (returned_zval) zval_ptr_dtor(&returned_zval);
|
||||
return 0;
|
||||
}
|
||||
MOVE_RETURNED_TO_RV(rv, returned_zval);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dbx_pgsql_close(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS) {
|
||||
/* returns 1 as long on success or 0 as long on failure */
|
||||
int number_of_arguments=1;
|
||||
zval ** arguments[1];
|
||||
zval * returned_zval=NULL;
|
||||
|
||||
arguments[0]=dbx_handle;
|
||||
dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "pg_close", &returned_zval, number_of_arguments, arguments);
|
||||
if (!returned_zval || returned_zval->type!=IS_BOOL) {
|
||||
if (returned_zval) zval_ptr_dtor(&returned_zval);
|
||||
return 0;
|
||||
}
|
||||
MOVE_RETURNED_TO_RV(rv, returned_zval);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dbx_pgsql_query(zval ** rv, zval ** dbx_handle, zval ** sql_statement, INTERNAL_FUNCTION_PARAMETERS) {
|
||||
/* returns 1 as long or a result identifier as resource on success
|
||||
or 0 as long on failure */
|
||||
int nargs=2;
|
||||
zval **args[2];
|
||||
zval *returned_zval=NULL, *num_rows_zval=NULL;
|
||||
|
||||
args[0]=dbx_handle;
|
||||
args[1]=sql_statement;
|
||||
dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "pg_exec", &returned_zval, nargs, args);
|
||||
/* pg_query returns a bool for success or failure,
|
||||
or a result_identifier for select statements */
|
||||
if (!returned_zval || (returned_zval->type!=IS_BOOL && returned_zval->type!=IS_RESOURCE)) {
|
||||
if (returned_zval) zval_ptr_dtor(&returned_zval);
|
||||
return 0;
|
||||
}
|
||||
MOVE_RETURNED_TO_RV(rv, returned_zval);
|
||||
|
||||
if(strstr(Z_STRVAL_PP(sql_statement), "SELECT") ||
|
||||
strstr(Z_STRVAL_PP(sql_statement), "select")){
|
||||
DBXG(row_count) = 0;
|
||||
|
||||
args[0]=rv;
|
||||
nargs = 1;
|
||||
dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "pg_numrows", &num_rows_zval, nargs, args);
|
||||
DBXG(num_rows) = Z_LVAL_P(num_rows_zval);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dbx_pgsql_getcolumncount(zval ** rv, zval ** result_handle, INTERNAL_FUNCTION_PARAMETERS) {
|
||||
/* returns column-count as long on success or 0 as long on failure */
|
||||
int number_of_arguments=1;
|
||||
zval ** arguments[1];
|
||||
zval * returned_zval=NULL;
|
||||
|
||||
arguments[0]=result_handle;
|
||||
dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "pg_numfields", &returned_zval, number_of_arguments, arguments);
|
||||
if (!returned_zval || returned_zval->type!=IS_LONG) {
|
||||
if (returned_zval) zval_ptr_dtor(&returned_zval);
|
||||
return 0;
|
||||
}
|
||||
MOVE_RETURNED_TO_RV(rv, returned_zval);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dbx_pgsql_getcolumnname(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS) {
|
||||
/* returns column-name as string on success or 0 as long on failure */
|
||||
int number_of_arguments=2;
|
||||
zval ** arguments[2];
|
||||
zval * zval_column_index;
|
||||
zval * returned_zval=NULL;
|
||||
|
||||
MAKE_STD_ZVAL(zval_column_index);
|
||||
ZVAL_LONG(zval_column_index, column_index);
|
||||
arguments[0]=result_handle;
|
||||
arguments[1]=&zval_column_index;
|
||||
dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "pg_fieldname", &returned_zval, number_of_arguments, arguments);
|
||||
/*/ pgsql_field_name returns a string /*/
|
||||
if (!returned_zval || returned_zval->type!=IS_STRING) {
|
||||
if (returned_zval) zval_ptr_dtor(&returned_zval);
|
||||
FREE_ZVAL(zval_column_index);
|
||||
return 0;
|
||||
}
|
||||
FREE_ZVAL(zval_column_index);
|
||||
MOVE_RETURNED_TO_RV(rv, returned_zval);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dbx_pgsql_getcolumntype(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS) {
|
||||
/* returns column-type as string on success or 0 as long on failure */
|
||||
int number_of_arguments=2;
|
||||
zval ** arguments[2];
|
||||
zval * zval_column_index;
|
||||
zval * returned_zval=NULL;
|
||||
|
||||
MAKE_STD_ZVAL(zval_column_index);
|
||||
ZVAL_LONG(zval_column_index, column_index);
|
||||
arguments[0]=result_handle;
|
||||
arguments[1]=&zval_column_index;
|
||||
dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "pg_fieldtype", &returned_zval, number_of_arguments, arguments);
|
||||
/* pgsql_field_name returns a string */
|
||||
if (!returned_zval || returned_zval->type!=IS_STRING) {
|
||||
if (returned_zval) zval_ptr_dtor(&returned_zval);
|
||||
FREE_ZVAL(zval_column_index);
|
||||
return 0;
|
||||
}
|
||||
FREE_ZVAL(zval_column_index);
|
||||
MOVE_RETURNED_TO_RV(rv, returned_zval);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dbx_pgsql_getrow(zval ** rv, zval ** result_handle, INTERNAL_FUNCTION_PARAMETERS) {
|
||||
/* returns array[0..columncount-1] as strings on success or 0
|
||||
as long on failure */
|
||||
int number_of_arguments=2;
|
||||
zval ** arguments[2];
|
||||
zval * zval_row=NULL;
|
||||
zval * returned_zval=NULL;
|
||||
|
||||
MAKE_STD_ZVAL(zval_row);
|
||||
ZVAL_LONG(zval_row, DBXG(row_count));
|
||||
arguments[0]=result_handle;
|
||||
arguments[1]=&zval_row;
|
||||
DBXG(row_count)++;
|
||||
if (DBXG(row_count)>DBXG(num_rows)){
|
||||
return 0;
|
||||
}
|
||||
dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "pg_fetch_array", &returned_zval, number_of_arguments, arguments);
|
||||
if (!returned_zval || returned_zval->type!=IS_ARRAY) {
|
||||
if (returned_zval) zval_ptr_dtor(&returned_zval);
|
||||
FREE_ZVAL(zval_row);
|
||||
return 0;
|
||||
}
|
||||
FREE_ZVAL(zval_row);
|
||||
MOVE_RETURNED_TO_RV(rv, returned_zval);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dbx_pgsql_error(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS) {
|
||||
/* returns string */
|
||||
int number_of_arguments=1;
|
||||
zval ** arguments[1];
|
||||
zval * returned_zval=NULL;
|
||||
|
||||
arguments[0]=dbx_handle;
|
||||
if (!dbx_handle) number_of_arguments=0;
|
||||
dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "pg_errormessage", &returned_zval, number_of_arguments, arguments);
|
||||
if (!returned_zval || returned_zval->type!=IS_STRING) {
|
||||
if (returned_zval) zval_ptr_dtor(&returned_zval);
|
||||
return 0;
|
||||
}
|
||||
MOVE_RETURNED_TO_RV(rv, returned_zval);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
54
ext/dbx/dbx_pgsql.h
Normal file
54
ext/dbx/dbx_pgsql.h
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| stentor module version 1.0 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 2001 Guidance Rotterdam BV |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 1.0 of the STENTOR license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at |
|
||||
| http://www.guidance.nl/php/dbx/license/1_00.txt. |
|
||||
| If you did not receive a copy of the STENTOR license and are unable |
|
||||
| to obtain it through the world-wide-web, please send a note to |
|
||||
| license@guidance.nl so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author : Rui Hirokawa <hirokawa@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#ifndef ZEND_DBX_PGSQL_H
|
||||
#define ZEND_DBX_PGSQL_H
|
||||
|
||||
#ifndef INIT_FUNC_ARGS
|
||||
#include "zend_modules.h"
|
||||
#endif
|
||||
|
||||
#include "php.h"
|
||||
|
||||
int dbx_pgsql_connect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS);
|
||||
/*/ returns connection handle as resource on success or 0 as long on failure /*/
|
||||
int dbx_pgsql_pconnect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS);
|
||||
/*/ returns persistent connection handle as resource on success or 0 as long on failure /*/
|
||||
int dbx_pgsql_close(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS);
|
||||
/*/ returns 1 as long on success or 0 as long on failure /*/
|
||||
int dbx_pgsql_query(zval ** rv, zval ** dbx_handle, zval ** sql_statement, INTERNAL_FUNCTION_PARAMETERS);
|
||||
/*/ returns 1 as long or a result identifier as resource on success or 0 as long on failure /*/
|
||||
int dbx_pgsql_getcolumncount(zval ** rv, zval ** result_handle, INTERNAL_FUNCTION_PARAMETERS);
|
||||
/*/ returns column-count as long on success or 0 as long on failure /*/
|
||||
int dbx_pgsql_getcolumnname(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS);
|
||||
/*/ returns column-name as string on success or 0 as long on failure /*/
|
||||
int dbx_pgsql_getcolumntype(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS);
|
||||
/*/ returns column-type as string on success or 0 as long on failure /*/
|
||||
int dbx_pgsql_getrow(zval ** rv, zval ** result_handle, INTERNAL_FUNCTION_PARAMETERS);
|
||||
/*/ returns array[0..columncount-1] as strings on success or 0 as long on failure /*/
|
||||
int dbx_pgsql_error(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS);
|
||||
/*/ returns string /*/
|
||||
|
||||
#endif /* ZEND_DBX_PGSQL_H */
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
@ -58,10 +58,10 @@ ZEND_FUNCTION(dbx_test);
|
||||
Declare any global variables you may need between the BEGIN
|
||||
and END macros here:
|
||||
*/
|
||||
/*ZEND_BEGIN_MODULE_GLOBALS(dbx)
|
||||
void * dbx_global;
|
||||
ZEND_END_MODULE_GLOBALS(dbx)
|
||||
*/
|
||||
ZEND_BEGIN_MODULE_GLOBALS(dbx)
|
||||
int row_count;
|
||||
int num_rows;
|
||||
ZEND_END_MODULE_GLOBALS(dbx)
|
||||
|
||||
/* In every function that needs to use variables in php_dbx_globals,
|
||||
do call dbxLS_FETCH(); after declaring other variables used by
|
||||
@ -71,9 +71,17 @@ ZEND_FUNCTION(dbx_test);
|
||||
*/
|
||||
|
||||
#ifdef ZTS
|
||||
#define DBXLS_D zend_dbx_globals *dbx_globals
|
||||
#define DBXLS_DC , DBXLS_D
|
||||
#define DBXLS_C dbx_globals
|
||||
#define DBXLS_CC , DBXLS_C
|
||||
#define DBXG(v) (dbx_globals->v)
|
||||
#define DBXLS_FETCH() zend_dbx_globals *dbx_globals = ts_resource(dbx_globals_id)
|
||||
#else
|
||||
#define DBXLS_D
|
||||
#define DBXLS_DC
|
||||
#define DBXLS_C
|
||||
#define DBXLS_CC
|
||||
#define DBXG(v) (dbx_globals.v)
|
||||
#define DBXLS_FETCH()
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user