StringToDatatype()

All the StringToDatatype functions take an input string and output a parsed value of the appropriate data type.

If the parse cannot be performed, the functions return C8_FALSE. An invalid parse results in an undefined result. A valid parse returns C8_TRUE and the parsed value of the appropriate type in o_out.

Data can be preceded or followed by whitespace. The entire string is assumed to contain the data. The parse is not as in sscanf() where "123XX456" produces the integer 123. In Sybase CEP, parsing "123XX456" as a number will result in a parse error. A string of " 123\t " (where \t is the tab char), is perfectly acceptable since whitespace may lead and follow a numeric value.

The following functions can be used to convert strings to datatypes:

C8Bool C8ConvertStringToInt      (const C8Char *s, C8Int *o_out); C8Bool C8ConvertStringToLong     (const C8Char *s, C8Long *o_out); C8Bool C8ConvertStringToBool     (const C8Char *s, C8Bool *o_out); C8Bool C8ConvertStringToTimestamp(const C8Char *s, C8Char*i_format,                                  C8Timestamp *o_out); C8Bool C8ConvertStringToFloat    (const C8Char *s, C8Float *o_out); // Convert a "raw" blob to a "hex string" blob.C8Bool C8ConvertHexStringToBlob  (const C8Char *s, C8Blob *o_out,                                  C8SizeType *o_size,                                  C8SizeType i_buf_size);

Note that the C8ConvertStringToTimestamp() function is the only one of these StringToDatatype() functions that allows you to specify a format. If the format parameter is a null pointer, the output is in microseconds. To specify another format, for example, "YYYY-MM-DD HH24:MI:SS.FF", please refer to the description of valid formats for TIMESTAMP data type in the Sybase CEP CCL Reference Guide . If the format is invalid, conversion may fail.

Note that since 2 hex digits are converted to a single byte in the BLOB, and since the trailing null (string terminator) is not needed as part of the blob, the o_out parameter to the C8ConvertHexStringToBlob() function only needs to be CEIL((N-1)/2) bytes long, where N is the length of the hex string.

Note: C8SizeType is typdef'd in c8types.h.