LONG Datatypes and Pro*C

From: William J. Bene <wjb_at_cscsun2.larc.nasa.gov>
Date: Wed, 15 Jul 1992 12:18:58 GMT
Message-ID: <1992Jul15.121858.11110_at_news.larc.nasa.gov>


I am having to struggle with long datatypes using Pro*C. This time it is with an update statement. Here is the routine:

static BoolEnum DoUpdate L1(RTRPtr, myPtr) {

	EXEC SQL BEGIN DECLARE SECTION;
		long		fiscalyr;
		VARCHAR		rrtr[20];
		VARCHAR		*rtrobj;		
	EXEC SQL END DECLARE SECTION;
	
	rtrobj = malloc(sizeof(short) + 5000 * sizeof(char));

	if (rtrobj == NULL) {
		strcpy(ErrStr, "Error allocating memory.");
		return(BOOL_FALSE);
		}

	STRING_TO_HOSTLONG(fiscalyr, FiscalYear);
	STRING_TO_HOSTSTR(rrtr, myPtr->rrtr);
	strcpy(rtrobj->arr, myPtr->rtrobj);
	rtrobj->len = strlen(rtrobj->arr);
	
	EXEC SQL WHENEVER SQLERROR GOTO SQLError;
	EXEC SQL WHENEVER NOT FOUND GOTO NotFound;
	
	EXEC SQL UPDATE RTR SET RTROBJ = :rtrobj 
		WHERE RRTR = :rrtr AND RFY = :fiscalyr;
			
	EXEC SQL WHENEVER SQLERROR CONTINUE;
	EXEC SQL WHENEVER NOT FOUND CONTINUE;
	
	if (rtrobj != NULL) free(rtrobj);

	return(BOOL_TRUE);
	
	SQLError:

/* Handle Error */
NotFound:
/* Handle Not Found */

}

This method works correctly when CHAR datatypes are length zero, which sets them to NULL, but does not work when a LONG datatype is zero length. It is my understanding that when rtrobj->len is zero, the LONG or CHAR datatype will be set to NULL. Do you have to treat LONG datatypes differently than CHAR datatypes? Do I have to check for a zero length string and use an indicator variable to set the LONG to NULL? I haven't found any documentation that says so. Any help would be appreciated.

Thanks,
Will



William J. Bene
Computer Sciences Corporation
wjb_at_cscsun2.larc.nasa.gov Received on Wed Jul 15 1992 - 14:18:58 CEST

Original text of this message