Skip to content

Commit

Permalink
Adding FrontBase support to the DBX extension
Browse files Browse the repository at this point in the history
  • Loading branch information
fmk committed Aug 7, 2001
1 parent 5e867ac commit 21e2a8f
Show file tree
Hide file tree
Showing 4 changed files with 330 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ext/dbx/dbx.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
#define DBX_ODBC 2
#define DBX_PGSQL 3
#define DBX_MSSQL 4
#define DBX_FBSQL 5
/* includes for supported databases */
#include "dbx.h"
#include "dbx_mysql.h"
#include "dbx_odbc.h"
#include "dbx_pgsql.h"
#include "dbx_mssql.h"
#include "dbx_fbsql.h"

/* support routines */
int module_exists(char * module_name) {
Expand All @@ -56,6 +58,7 @@ int module_identifier_exists(long module_identifier) {
case DBX_ODBC: return module_exists("odbc");
case DBX_PGSQL: return module_exists("pgsql");
case DBX_MSSQL: return module_exists("mssql");
case DBX_FBSQL: return module_exists("fbsql");
}
return 0;
}
Expand All @@ -65,6 +68,7 @@ int get_module_identifier(char * module_name) {
if (!strcmp("odbc", module_name)) return DBX_ODBC;
if (!strcmp("pgsql", module_name)) return DBX_PGSQL;
if (!strcmp("mssql", module_name)) return DBX_MSSQL;
if (!strcmp("fbsql", module_name)) return DBX_FBSQL;
return DBX_UNKNOWN;
}

Expand Down Expand Up @@ -154,6 +158,7 @@ ZEND_MINIT_FUNCTION(dbx)
REGISTER_LONG_CONSTANT("DBX_ODBC", DBX_ODBC, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DBX_PGSQL", DBX_PGSQL, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DBX_MSSQL", DBX_MSSQL, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DBX_FBSQL", DBX_FBSQL, CONST_CS | CONST_PERSISTENT);

REGISTER_LONG_CONSTANT("DBX_PERSISTENT", DBX_PERSISTENT, CONST_CS | CONST_PERSISTENT);

Expand Down Expand Up @@ -190,7 +195,7 @@ ZEND_MINFO_FUNCTION(dbx)
php_info_print_table_start();
php_info_print_table_row(2, "dbx support", "enabled");
php_info_print_table_row(2, "dbx version", "1.0.0");
php_info_print_table_row(2, "supported databases", "MySQL<br />ODBC<br />PostgreSQL<br />Microsoft SQL Server");
php_info_print_table_row(2, "supported databases", "MySQL<br />ODBC<br />PostgreSQL<br />Microsoft SQL Server<br />FrontBase");
php_info_print_table_end();
}

Expand Down Expand Up @@ -664,6 +669,7 @@ int switch_dbx_connect(zval ** rv, zval ** host, zval ** db, zval ** username, z
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);
case DBX_MSSQL: return dbx_mssql_connect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
case DBX_FBSQL: return dbx_fbsql_connect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
zend_error(E_WARNING, "dbx_connect: not supported in this module");
return 0;
Expand All @@ -676,6 +682,7 @@ int switch_dbx_pconnect(zval ** rv, zval ** host, zval ** db, zval ** username,
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);
case DBX_MSSQL: return dbx_mssql_pconnect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
case DBX_FBSQL: return dbx_fbsql_pconnect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
zend_error(E_WARNING, "dbx_pconnect: not supported in this module");
return 0;
Expand All @@ -688,6 +695,7 @@ int switch_dbx_close(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETER
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);
case DBX_MSSQL: return dbx_mssql_close(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
case DBX_FBSQL: return dbx_fbsql_close(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
zend_error(E_WARNING, "dbx_close: not supported in this module");
return 0;
Expand All @@ -700,6 +708,7 @@ int switch_dbx_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** sq
case DBX_ODBC: return dbx_odbc_query(rv, dbx_handle, db_name, sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU);
case DBX_PGSQL: return dbx_pgsql_query(rv, dbx_handle, db_name, sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU);
case DBX_MSSQL: return dbx_mssql_query(rv, dbx_handle, db_name, sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU);
case DBX_FBSQL: return dbx_fbsql_query(rv, dbx_handle, db_name, sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
zend_error(E_WARNING, "dbx_query: not supported in this module");
return 0;
Expand All @@ -712,6 +721,7 @@ int switch_dbx_getcolumncount(zval ** rv, zval ** result_handle, INTERNAL_FUNCTI
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);
case DBX_MSSQL: return dbx_mssql_getcolumncount(rv, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
case DBX_FBSQL: return dbx_fbsql_getcolumncount(rv, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
zend_error(E_WARNING, "dbx_getcolumncount: not supported in this module");
return 0;
Expand All @@ -724,6 +734,7 @@ int switch_dbx_getcolumnname(zval ** rv, zval ** result_handle, long column_inde
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);
case DBX_MSSQL: return dbx_mssql_getcolumnname(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
case DBX_FBSQL: return dbx_fbsql_getcolumnname(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
zend_error(E_WARNING, "dbx_getcolumnname: not supported in this module");
return 0;
Expand All @@ -736,6 +747,7 @@ int switch_dbx_getcolumntype(zval ** rv, zval ** result_handle, long column_inde
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);
case DBX_MSSQL: return dbx_mssql_getcolumntype(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
case DBX_FBSQL: return dbx_fbsql_getcolumntype(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
zend_error(E_WARNING, "dbx_getcolumntype: not supported in this module");
return 0;
Expand All @@ -748,6 +760,7 @@ int switch_dbx_getrow(zval ** rv, zval ** result_handle, long row_number, INTERN
case DBX_ODBC: return dbx_odbc_getrow(rv, result_handle, row_number, INTERNAL_FUNCTION_PARAM_PASSTHRU);
case DBX_PGSQL: return dbx_pgsql_getrow(rv, result_handle, row_number, INTERNAL_FUNCTION_PARAM_PASSTHRU);
case DBX_MSSQL: return dbx_mssql_getrow(rv, result_handle, row_number, INTERNAL_FUNCTION_PARAM_PASSTHRU);
case DBX_FBSQL: return dbx_fbsql_getrow(rv, result_handle, row_number, INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
zend_error(E_WARNING, "dbx_getrow: not supported in this module");
return 0;
Expand All @@ -760,6 +773,7 @@ int switch_dbx_error(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETER
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);
case DBX_MSSQL: return dbx_mssql_error(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
case DBX_FBSQL: return dbx_fbsql_error(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
zend_error(E_WARNING, "dbx_error: not supported in this module");
return 0;
Expand Down
8 changes: 8 additions & 0 deletions ext/dbx/dbx.dsp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

248 changes: 248 additions & 0 deletions ext/dbx/dbx_fbsql.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
/*
+----------------------------------------------------------------------+
| PHP version 4.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2001 The PHP Group |
+----------------------------------------------------------------------+
| dbx module version 1.0 |
+----------------------------------------------------------------------+
| Copyright (c) 2001 Guidance Rotterdam BV |
+----------------------------------------------------------------------+
| This source file is subject to version 2.02 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available at through the world-wide-web at |
| http://www.php.net/license/2_02.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 |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author : Marc Boeren <[email protected]> |
| Frank M. Kromann <[email protected]> |
+----------------------------------------------------------------------+
*/

#include "dbx.h"
#include "dbx_fbsql.h"

#define FBSQL_ASSOC 1<<0
#define FBSQL_NUM 1<<1

int dbx_fbsql_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 number_of_arguments=3;
zval ** arguments[3];
zval * returned_zval=NULL;
zval * select_db_zval=NULL;

arguments[0]=host;
arguments[1]=username;
arguments[2]=password;
dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "fbsql_connect", &returned_zval, number_of_arguments, arguments);
if (!returned_zval || returned_zval->type!=IS_RESOURCE) {
if (returned_zval) zval_ptr_dtor(&returned_zval);
return 0;
}

number_of_arguments=2;
arguments[0]=db;
arguments[1]=&returned_zval;
dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "fbsql_select_db", &select_db_zval, number_of_arguments, arguments);
if (!select_db_zval || (select_db_zval->type==IS_BOOL && select_db_zval->value.lval==0) ) {
if (select_db_zval) zval_ptr_dtor(&select_db_zval);
/* also close connection */
number_of_arguments=1;
arguments[0]=&returned_zval;
zend_list_addref(returned_zval->value.lval);
dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "fbsql_close", &select_db_zval, number_of_arguments, arguments);
if (select_db_zval) zval_ptr_dtor(&select_db_zval);
zval_ptr_dtor(&returned_zval);
return 0;
}
zval_ptr_dtor(&select_db_zval);

MOVE_RETURNED_TO_RV(rv, returned_zval);

return 1;
}

int dbx_fbsql_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 number_of_arguments=3;
zval ** arguments[3];
zval * returned_zval=NULL;
zval * select_db_zval=NULL;

arguments[0]=host;
arguments[1]=username;
arguments[2]=password;
dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "fbsql_pconnect", &returned_zval, number_of_arguments, arguments);
if (!returned_zval || returned_zval->type!=IS_RESOURCE) {
if (returned_zval) zval_ptr_dtor(&returned_zval);
return 0;
}

number_of_arguments=2;
arguments[0]=db;
arguments[1]=&returned_zval;
dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "fbsql_select_db", &select_db_zval, number_of_arguments, arguments);
if (!select_db_zval || (select_db_zval->type==IS_BOOL && select_db_zval->value.lval==0) ) {
if (select_db_zval) zval_ptr_dtor(&select_db_zval);
/* also close connection */
number_of_arguments=1;
arguments[0]=&returned_zval;
zend_list_addref(returned_zval->value.lval);
dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "fbsql_close", &select_db_zval, number_of_arguments, arguments);
if (select_db_zval) zval_ptr_dtor(&select_db_zval);
zval_ptr_dtor(&returned_zval);
return 0;
}
zval_ptr_dtor(&select_db_zval);

MOVE_RETURNED_TO_RV(rv, returned_zval);

return 1;
}

int dbx_fbsql_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, "fbsql_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_fbsql_query(zval ** rv, zval ** dbx_handle, zval ** db_name, 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 number_of_arguments=3;
zval ** arguments[3];
zval * returned_zval=NULL;

arguments[0]=db_name;
arguments[1]=sql_statement;
arguments[2]=dbx_handle;
dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "fbsql_db_query", &returned_zval, number_of_arguments, arguments);
/* fbsql_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);
return 1;
}

int dbx_fbsql_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, "fbsql_num_fields", &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_fbsql_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, "fbsql_field_name", &returned_zval, number_of_arguments, arguments);
/* fbsql_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_fbsql_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, "fbsql_field_type", &returned_zval, number_of_arguments, arguments);
/* fbsql_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_fbsql_getrow(zval ** rv, zval ** result_handle, long row_number, 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_resulttype=NULL;
zval * returned_zval=NULL;

MAKE_STD_ZVAL(zval_resulttype);
ZVAL_LONG(zval_resulttype, FBSQL_NUM);
arguments[0]=result_handle;
arguments[1]=&zval_resulttype;
dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "fbsql_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_resulttype);
return 0;
}
FREE_ZVAL(zval_resulttype);
MOVE_RETURNED_TO_RV(rv, returned_zval);
return 1;
}

int dbx_fbsql_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, "fbsql_error", &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:
*/
Loading

0 comments on commit 21e2a8f

Please sign in to comment.