php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15719 odbc_execute does not pass null values into the database
Submitted: 2002-02-25 17:10 UTC Modified: 2002-02-26 10:37 UTC
From: joseph at ud dot com Assigned:
Status: Closed Package: ODBC related
PHP Version: 4.1.1 OS: Redhat 7.1
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: joseph at ud dot com
New email:
PHP Version: OS:

 

 [2002-02-25 17:10 UTC] joseph at ud dot com
In the file ext/odbc/php_odbc.c

add an unsigned char called otype to the php function odbc_execute after populating *TMP, before calling convert_to_string save the value of (*TMP)->type into the otype buffer. Then at the end right before calling SQLPrepare (make sure it is the second call to SQLPrepare as the first is for pulling data from a file pointer and can't be null.) Check to see if otype == IS_NULL and if so set params[i-1].vallen = SQL_NULL_DATA. Problem solved. 

ex:

starting at line 919:

       for(i = 1; i <= result->numparams; i++) {
              if (zend_hash_get_current_data((*pv_param_arr)->value.ht, (void **) &tmp) == FAILURE) {
                php_error(E_WARNING,"Error getting parameter");
                SQLFreeStmt(result->stmt,SQL_RESET_PARAMS);
                efree(params);
                RETURN_FALSE;
            }
                  otype = (*tmp)->type;
              convert_to_string(*tmp);
                  if ((*tmp)->type != IS_STRING) {
                    php_error(E_WARNING,"Error converting parameter");
                    SQLFreeStmt(result->stmt, SQL_RESET_PARAMS);
                    efree(params);
                    RETURN_FALSE;
                }

              SQLDescribeParam(result->stmt, (UWORD)i, &sqltype, &precision,
                               &scale, &nullable);
                  params[i-1].vallen = (*tmp)->value.str.len;
              params[i-1].fp = -1;

                  if (IS_SQL_BINARY(sqltype))
                    ctype = SQL_C_BINARY;
              else
                ctype = SQL_C_CHAR;

                  if ((*tmp)->value.str.val[0] == '\'' &&
                      (*tmp)->value.str.val[(*tmp)->value.str.len - 1] == '\'') {
                    filename = &(*tmp)->value.str.val[1];
                    filename[(*tmp)->value.str.len - 2] = '\0';

                    if ((params[i-1].fp = open(filename,O_RDONLY)) == -1) {
                          php_error(E_WARNING,"Can't open file %s", filename);
                      SQLFreeStmt(result->stmt, SQL_RESET_PARAMS);
                          for(i = 0; i < result->numparams; i++) {
                            if (params[i].fp != -1) {
                                  close(params[i].fp);
                          }
                        }
                      efree(params);
                          RETURN_FALSE;
                  }

                    params[i-1].vallen = SQL_LEN_DATA_AT_EXEC(0);

                    rc = SQLBindParameter(result->stmt, (UWORD)i, SQL_PARAM_INPUT,
                                      ctype, sqltype, precision, scale,
                                            (void *)params[i-1].fp, 0,
                                          &params[i-1].vallen);
                } else {
#ifdef HAVE_DBMAKER
                  precision = params[i-1].vallen;
#endif
                  if(otype == IS_NULL)
                    {
                        params[i-1].vallen = SQL_NULL_DATA;
                }
                  rc = SQLBindParameter(result->stmt, (UWORD)i, SQL_PARAM_INPUT,
                                            ctype, sqltype, precision, scale,
                                          (*tmp)->value.str.val, 0,
                                        &params[i-1].vallen);
              }
              zend_hash_move_forward((*pv_param_arr)->value.ht);
           }


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-25 17:59 UTC] kalowsky@php.net
can you please submit this change as a patch?  This fix would become infinately simplier to make :)
 [2002-02-25 18:20 UTC] joseph at ud dot com
as requested, patch.....
881d880
< 	unsigned char otype;
927d925
< 			otype = (*tmp)->type;
973,976d970
< 				if(otype == IS_NULL)
< 				{
< 					params[i-1].vallen = SQL_NULL_DATA;
< 				}
 [2002-02-26 10:22 UTC] joseph at ud dot com
patch for php-latest

*** php_odbc.c.orig	Fri Feb 15 11:34:57 2002
--- php_odbc.c.new	Tue Feb 26 09:01:21 2002
***************
*** 878,883 ****
--- 878,884 ----
     	SWORD sqltype, ctype, scale;
  	SWORD nullable;
  	UDWORD precision;
+ 	unsigned char otype;
     	odbc_result   *result;
  	int numArgs, i, ne;
  	RETCODE rc;
***************
*** 925,930 ****
--- 926,932 ----
  				efree(params);
                  RETURN_FALSE;
              }
+ 			otype = (*tmp)->type;
              convert_to_string(*tmp);
  			if (Z_TYPE_PP(tmp) != IS_STRING) {
  				php_error(E_WARNING,"Error converting parameter");
***************
*** 984,989 ****
--- 986,995 ----
  #ifdef HAVE_DBMAKER
                  precision = params[i-1].vallen;
  #endif
+ 				if(otype == IS_NULL)
+ 				{
+ 					params[i-1].vallen = SQL_NULL_DATA;
+ 				}
  				rc = SQLBindParameter(result->stmt, (UWORD)i, SQL_PARAM_INPUT,
  									  ctype, sqltype, precision, scale,
  									  Z_STRVAL_PP(tmp), 0,
 [2002-02-26 10:37 UTC] kalowsky@php.net
This bug has been fixed in CVS.

Thanks for your patch.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Dec 06 10:00:01 2025 UTC