#37209 [Asn->Csd]: mssql_execute with non fatal errors

From: Date: Mon, 23 Feb 2009 21:22:02 +0000
Subject: #37209 [Asn->Csd]: mssql_execute with non fatal errors
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-134136@lists.php.net to get a copy of this message
 ID:               37209
 Updated by:       kalle@php.net
 Reported By:      netvbonline at yahoo dot co dot uk
-Status:           Assigned
+Status:           Closed
 Bug Type:         MSSQL related
 Operating System: Win XP Pro
 PHP Version:      5.1.2
 Assigned To:      fmk
 New Comment:

This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Fixed in 5.2.9RC4


Previous Comments:
------------------------------------------------------------------------

[2007-08-15 08:19:09] netvbonline at yahoo dot co dot uk

issvar left the comment

"This is caused by php stopping processing when dbsqlok() returns
FAIL."

Will this change be carried out at source? Seems to me that handling
output parameters in a non fatal sp error should be resolved. Has this
been fixed?

:-) Cheers

------------------------------------------------------------------------

[2006-09-29 15:59:32] issvar at hotmail dot com

This is caused by php stopping processing when dbsqlok() returns FAIL.

Microsoft db-library for c manual states that even if dbsqlok() returns
FAIL there could be results, so results and return values and output
parameters should be processed.

So in ext/mssql/php_mssql.c there should be changed the following part
in PHP_FUNCTION(mssql_execute):

	if (dbrpcexec(mssql_ptr->link)==FAIL ||
dbsqlok(mssql_ptr->link)==FAIL) {
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "stored procedure
execution failed");
		dbcancel(mssql_ptr->link);
		RETURN_FALSE;
	}

this should be changed to:

	if (dbrpcexec(mssql_ptr->link)==FAIL) {
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "stored procedure
execution failed");
		dbcancel(mssql_ptr->link);
		RETURN_FALSE;
	}
	if (dbsqlok(mssql_ptr->link)==FAIL) {
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "stored procedure
execution failed");
	}

------------------------------------------------------------------------

[2006-07-27 00:03:22] sniper@php.net

Frank, there's the feedback now. :)

------------------------------------------------------------------------

[2006-05-02 08:24:19] netvbonline at yahoo dot co dot uk

*
[Description]
  Procedure handles the process of either fetching or inserting a
forename, this procedure must never update existing name otherwise it
would affect all other person  FK's


*/

CREATE PROCEDURE usp_fetch_or_insert_forename
@Forename [varchar](50),
@ForenameID [int] OUTPUT

AS 
DECLARE @err int -- needed as the global @@ERROR is reset after each
statement, even logical comparison

	-- reduce network traffic
	SET NOCOUNT ON
	

	-- first do common validation and checks
	BEGIN
				
		
INSERT INTO [dbtest].[dbo].[Forename]   ( [Forename] ) 
          VALUES ( @Forename )
		
		SET @err=@@ERROR
		
		print 'non fatal error ...'

		IF (@err = 2627)
		  BEGIN
			RAISERROR('myMessage:test', 2, 1) WITH SETERROR
		  END
			
			
		IF (@err=0)
		  BEGIN

		      -- explicitly retrieve the identity of row just inserted from
above statement
		      SET @ForenameID=SCOPE_IDENTITY()			
	                   RETURN(0)
		   
		   END
			
		 -- Test for key violation before returning error code
		 IF (@err=2627 ) 
		   BEGIN
		       
		      print 'Looking up the forename value'
		      
		         -- I know the name exists, so fetch the PK	
 		        SELECT @ForenameID=ForenameID FROM Forename WHERE
Forename=@Forename

print 'still here .. and forenameid is ' + str(@ForenameID)

 		         RETURN(0) 
		   END
		
	             -- There was an error in the insert statement, not
related to unique key violation constraint so return error code
	  	RETURN(@err)
		
	END
GO



Hope this is ok, as you can see it contains various debug messages.

------------------------------------------------------------------------

[2006-04-29 03:13:35] fmk@php.net

Please provide a short example of the procedure used to generate this.

The current implementation will handle multiple results from a storred
procedure and it will skip all results without column.

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/37209

-- 
Edit this bug report at http://bugs.php.net/?id=37209&edit=1



Thread (9 messages)

« previous php.bugs (#134136) next »