Datablade: system cast returns NIL
Posted in 1999
Hi ! We are developping some datablade that needs to retrieve column values from a row paramter, which are in binary representation, bt we needs the values in string representation. As we are not using SQL interfaces we have to explicitly cast the MI_DATUM found in the row to lvarchar. The following code should do this for non-complex values. At the heart of the procedure is the routine mi_td_cast_get and the following fast-path call using mi_routine exec. Debuging the blade I can see that the dosyscast() internal cast routine is called and returns with no error indications. However, the returned result seems always to be a NILL lvarchar, which is not what I want :( I talked to informix support people who have been very helpful up to know, but maybe there is some informix cracck out there who has caed this problem, already, and knows what I am doing wrong, and can point me to a working solution. Thanx a lot, Chris PS: please cc your response to chris@informatik.tu-darmstadt.de ---- here is the code fragment ----------------------------------------- char* _val_to_string(MI_CONNECTION* db_conn, MI_DATUM value,MI_TYPE_DESC* td) { MI_TYPEID * srctypeid; MI_TYPE_DESC* srcdesc; MI_TYPE_DESC* targetdesc; MI_TYPEID * targettypeid; mi_string* typename; mi_integer typelen, typeprec; mi_char status; MI_FUNC_DESC* cast; MI_FPARAM* fpcast; mi_lvarchar* casted_value; mi_integer func_err, nargs, iter; MI_TYPEID* argtype; MI_TYPE_DESC* argdesc; char smsg[255]; mi_string* tmpresult; // thos parameters will be needed if we use dosyscast typelen = mi_type_length(td); typeprec = mi_type_precision(td); if (mi_typeid_is_complex(srctypeid)) { _TRACE("WARN1", "_val_to_string found complex type"); return(NULL); } else { targetdesc = mi_typestring_to_typedesc(db_conn, "lvarchar"); targettypeid = mi_typedesc_typeid(targetdesc); cast = mi_td_cast_get(db_conn, td, targetdesc, &status); switch(status) { case MI_NOP_CAST: // actually we should never get to this point, as we have // the shortcut above (no shown here :)! _TRACE("INFO1", "val_to_string: no cast needed"); tmpresult = mi_lvarchar_to_string((mi_lvarchar*) value); return(tmpresult); break; case MI_SYSTEM_CAST: _TRACE("INFO1","_val_to_string using system cast"); case MI_UDR_CAST: case MI_EXPLICIT_CAST: case MI_IMPLICIT_CAST: // informix people reported a bug, that the system cast routine // takes additional parameters, although a cast routine should only // take one paramter. As we are using dynamic args on the // stack, we are always pusing those additional paramters :) casted_value = (mi_lvarchar*) mi_routine_exec(db_conn, cast, &func_err, value, typeprec, typelen); if(func_err==MI_ERROR) { _TRACE("ERROR1", "val_to_string: fastpath to cast-op failed"); mi_routine_end(db_conn, cast); return(NULL); } else { // here is the problem: // tmpresult is always NIL tmpresult = mi_lvarchar_to_string((mi_lvarchar*)casted_value); mi_routine_end(db_conn, cast); return(tmpresult); } break; case MI_ERROR_CAST: case MI_NO_CAST: default: _TRACE("EROR1", "val_to_string: no cast routine"); return(NULL); break; } // end switch } // end else }