[freetds] Stored Procedure Output Parameters

Paul Robinson paul.robinson at groupbc.com
Tue Aug 2 07:08:52 EDT 2005


We've been trying to use PHP 5.0.4 with FreeTDS 0.63 in order to enable 
communication with a Windows 2000 Server running MS SQL Server 2000.

We ran into problems with input and output parameters that I believe 
I've now solved. In order to do so I have had to change PHP code (which 
I will be submitting as a PHP bug shortly) and I've added an extra 
function to dblib/dblib.c to enable the calling application (PHP in this 
case) to determine if the output parameter is NULL.

Diff is as follows:

3972a3973,3990
 > int
 > dbretisnull(DBPROCESS * dbproc, int retnum)
 > {
 >       TDSCOLUMN *colinfo;
 >       TDSPARAMINFO *param_info;
 >       TDSSOCKET *tds;
 >
 >       dbnumrets(dbproc);
 >
 >       tds = (TDSSOCKET *) dbproc->tds_socket;
 >       param_info = tds->param_info;
 >       if (!param_info || !param_info->columns || retnum < 1 || retnum 
 > param_info->num_cols)
 >               return NULL;
 >
 >       return tds_get_null(param_info->current_row, retnum - 1);
 > }
 >
 >

I hope you'll either point out a more sensible way that I could have 
implemented this without having to resort to implementing a new function 
or you will consider this for inclusion in a future release.

For information the calling code in PHP (ext/mssql/php_mssql.c) looks 
like this (in _mssql_get_sp_result inside the loop over the result columns):

is_null = dbretisnull(mssql_ptr->link, i);
if (is_null) {
	ZVAL_NULL(bind->zval);
}

Thanks,
	Paul
-- 
Paul Robinson
Systems Manager
Business Collaborator Ltd
WWW: http://www.groupbc.com



More information about the FreeTDS mailing list