error 1223 ... how to avoid it ?!
Posted in 2009
Topics: Error Codes & Troubleshooting, Connectivity: ESQL/C, 4GL & Embedded SQL, Data Types & Schema Design
Dear All... I've a esql/c application which calculate option theory,gamma,theta,and so on, sometimes , some data will cause -1223 error while update DB , if I printf that var(data type double in esql/c) , it showes nil ... What can I do with these vars ?! I try to code : if ( (gamma1 >=0)||(gamma1 <=0) ) tmpgamma1 = gamma1 ; else tmpgamma1 = 0 ; if gamma1 = nil , it still does not go to "else" , the bother me !! another question is , I've a lot of fileds in update sql , like update tablex set gammas = $gammas , gammaf = $gammf,gammag = $gammg , thetas = $thetas , thetaf = $thetaf,thetag = $thetag , deltas = $deltas , deltaf = $deltaf,deltag = $deltag , vegas = $vegas ,vegaf = $vegaf ,vegag = $vegag where opt_id = $opt_id ; while one of those vars cause -1223 , it won't showes which one cause the errors , so I have to take times to printf the vars to get it , is there any way to get it easier ?! like sqlerrd structure or sqlcode or else , which can tell the field make this -1223 error !! Thanks for suggestion ...
Please next type always send your database and operating system version. You must realize that C does not understand SQL datatypes and that any modern compiler seeing the expression below would complete remove the condition and do only the assignment of gamma1 to tmpgamma1.. > if ( (gamma1 >=0)||(gamma1 <=0) ) > > tmpgamma1 = gamma1 ; > else > > tmpgamma1 = 0; If you are trying to test for NULL in an esql/c application you can use the risnull() function to check any datatype for a NULL value. Here is what I think you meant to do (assuming gamma1 is a double): if (risnull( CDOUBLETYPE, gamma1)) tmpgamma1 = 0 else tmpgamma1 = gamma1; In addition, you can use the new SQL function NVL( gama1 , 0 ) to ensure that if gama1 is NULL then subsitute 0 in an SQL statement. John F. Miller III STSM, Support Architect miller3@us.ibm.com 503-578-5645 IBM Informix Dynamic Server (IDS) ids-bounces@iiug.org wrote on 09/01/2009 08:33:18 PM: > [image removed] > > error 1223 ... how to avoid it ?! [16830]: > > MARS CHEN > > to: > > ids > > 09/01/2009 08:34 PM > > Sent by: > > ids-bounces@iiug.org > > Please respond to ids > > Dear All... > > I've a esql/c application which calculate option > theory,gamma,theta,and so on, > sometimes , some data will cause -1223 error while update DB , > if I printf that var(data type double in esql/c) , it showes nil ... > > What can I do with these vars ?! I try to code : > if ( (gamma1 >=0)||(gamma1 <=0) ) > > tmpgamma1 = gamma1 ; > else > > tmpgamma1 = 0 ; > > if gamma1 = nil , it still does not go to "else" , the bother me !! > > another question is , I've a lot of fileds in update sql , like > > update tablex > set gammas = $gammas , gammaf = $gammf,gammag = $gammg , > thetas = $thetas , thetaf = $thetaf,thetag = $thetag , > deltas = $deltas , deltaf = $deltaf,deltag = $deltag , > vegas = $vegas ,vegaf = $vegaf ,vegag = $vegag > where opt_id = $opt_id ; > > while one of those vars cause -1223 , it won't showes which one cause > the errors , so I have to take times to printf the vars to get it , > is there any way to get it easier ?! like sqlerrd structure or > sqlcode or else , which can tell the field make this -1223 error !! > > Thanks for suggestion ... > > > ******************************************************************************* > Forum Note: Use "Reply" to post a response in the discussion forum. >
Thanks for John's response ... I test the following in RedHat RHEL 5 , IDS 11.50.UC4 , esql/c 3.50.UC4, it showes -1223 , I use some functions which is coded by somebody else, those functions produce gamma,theta like the following case sometimes , and that bother me , what can I do to avoid these nil value ?! int main(int argc ,char *argv[]) { EXEC SQL BEGIN DECLARE SECTION; double x1,x2,x3 ; char field1[21] ; EXEC SQL END DECLARE SECTION; EXEC SQL CONNECT TO "stores7@ifx" ; EXEC SQL WHENEVER ERROR STOP; x1 = 0.0 ; x2 = 100.0 ; x3 = x2 / x1 ; if (risnull(CDOUBLETYPE,(char *)&x3 )) printf("x3 is divided zero..... \\ ") ; strcpy(field1,"12345") ; printf("x3=(%f)\\ ",x3) ; EXEC SQL insert into table1 values($field1,$x3) ; printf("done...\\ ") ; } $./test x3=(inf) Program stopped by WHENEVER STOP sqlca: sqlcode:-1223
My first suggestions would be to not use floats/doubles, but rather use decimals. With decimals you do not have to deal with machine specific implementations. What you need to do with x3 is ensure you are inserting a valid value. You have a value which is not a number. The print statement shows this, but let me try to make this a little more clear. Now what value you want to insert once you have an illegal float value, I am not sure. I have inserted a NULL in the code below. x3 = x2 / x1 ; if (risnull(CDOUBLETYPE,(char *)&x3 )) printf("x3 is divided zero..... \\ ") ; if (isnan(x3)) { printf("x3 is nan..... \\ ") ;.. rsetnull(CDOUBLETYPE, (char *) &x3); } else if (!finite(x3)) { printf("x3 is infinite, setting to null..... \\ ") ; rsetnull(CDOUBLETYPE, (char *) &x3); } strcpy(field1,"12345") ;, John F. Miller III STSM, Support Architect miller3@us.ibm.com 503-578-5645 IBM Informix Dynamic Server (IDS) ids-bounces@iiug.org wrote on 09/02/2009 02:22:20 AM: > [image removed] > > Re: error 1223 ... how to avoid it ?! [16832] > > MARS CHEN > > to: > > ids > > 09/02/2009 02:22 AM > > Sent by: > > ids-bounces@iiug.org > > Please respond to ids > > Thanks for John's response ... > > I test the following in RedHat RHEL 5 , IDS 11.50.UC4 , esql/c 3.50.UC4, > it showes -1223 , I use some functions which is coded by somebody else, > those functions produce gamma,theta like the following case sometimes , > and that bother me , what can I do to avoid these nil value ?! > > int main(int argc ,char *argv[]) > { > > EXEC SQL BEGIN DECLARE SECTION; > > double x1,x2,x3 ; > > char field1[21] ; > > EXEC SQL END DECLARE SECTION; > > EXEC SQL CONNECT TO "stores7@ifx" ; > > EXEC SQL WHENEVER ERROR STOP; > > x1 = 0.0 ; > > x2 = 100.0 ; > > x3 = x2 / x1 ; > > if (risnull(CDOUBLETYPE,(char *)&x3 )) > > printf("x3 is divided zero..... \\ ") ; > > strcpy(field1,"12345") ; > > printf("x3=(%f)\\ ",x3) ; > > EXEC SQL insert into table1 values($field1,$x3) ; > > printf("done...\\ ") ; > } > > $./test > > x3=(inf) > > Program stopped by WHENEVER STOP > sqlca: > sqlcode:-1223 > > > ******************************************************************************* > Forum Note: Use "Reply" to post a response in the discussion forum. >
Thank you John , finite() and rsetnull() functions do solve my problem , that is really helpful a lot ... Thanks a lot !