Re: using variables to index into substrings
Posted in 2000
From: "Andrew McPherson" <amcphers@dcc.govt.nz> > >I would *really* like to use variables to index substring arguments, but >the >Infomix 9 manual blithely states that only constants are allowed to be used >to index substrings. Duh! > >e.g. something like: > ....... > DEFINE in_index INTEGER; > DEFINE out_index INTEGER; > DEFINE in_str CHAR(60); > DEFINE out_str CHAR(4); > ....... > LET out_str[1] = in_str[1]; --should work > > LET out_str[out_index] = in_str[in_index]; --not allowed > ....... Well, you could always write a 60-way CASE statement... :0) >Has anyone written DataBlade wrappers to the std C library for string >handling routines like substr? Well, I guess they're already there, sort of by implication, I think the real problem would be how to access them. I don't know of what I speak, but I had a look at code from someone else who had to call an OS system call (random) and the code to do it looks pretty trivial (see attached). Dunno how you would register it, but I'm sure it's in TFM somewhere. You could lay out a plea to someone from Informix or on CDI to knock it out, or you could use the attached as a sample. Please note that all disclaimers apply! :0) As a final alternative, Paul Brown has written a "bladelet" that does dynamic SQL within stored procedures on the iiug.org web site -- perhaps you could use that? --------------------------------- /* ** Title: prand.c ** Description: Random? ** Comments: ** */ /* ** The following is placed here to insure ** that name "mangling" does not occur. */ #ifdef __cplusplus extern "C" { #endif /* Standard library includes. */ #include <ctype.h> #include <stdio.h> #include <string.h> #include <stddef.h> #include <fcntl.h> #include <sys/stat.h> #include <errno.h> #include <mi.h> /* * */ static long state1[32] = { 3, 0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342, 0x7449e56b, 0xbeb1dbb0, 0xab5c5918, 0x946554fd, 0x8c2e680f, 0xeb3d799f, 0xb11ee0b7, 0x2d436b86, 0xda672e2a, 0x1588ca88, 0xe369735d, 0x904f35f7, 0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc, 0xde3b81e0, 0xdf0a6fb5, 0xf103bc02, 0x48f340fb, 0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b, 0xf5ad9d0e, 0x8999220b, 0x27fb47b9 }; static int random0=0; long prandom() { unsigned seed; int n; seed = 1; n = 128; if (random0==0) { initstate(seed, state1, n); random0++; setstate(state1); } return random(); } #ifdef __cplusplus } #endif ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com