RE: looping through CSV list
Posted in 2011
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
> Date: Wed, 26 Jan 2011 16:21:35 +0000 > From: marco@4glworks.com > To: informix-list@iiug.org > Subject: Re: looping through CSV list > > As others have pointed out, the question is - do you want to do it from inside > the engine, or do you want to do it from a client? If you want to do it from a > client - ie read the file, parse it and then do something with it, like insert > values into a database, then you have many options. SQSL could easily do that > for you: > > let topix = "300000,310010,420011,650934" > > for top_loop in <+ get topix +>; > if (top_loop< 290000) then; > # do something > end if; > end for; > # do something else > > He never did say it was in engine or not. Since the values are in a comma delimited string (he said CSV) it could be in a comma delimited file. I saw Madison's response. In C, why not use strtok and create tokens using the delimiter of ',' ? Then you do an string to int conversion and then comparison. Much easier. And no, I'm not going to print out the code. That's left as an exercise of the user. (Hint: Google C and strtok example ) But hey! what do I know? ;-) -G
On Jan 26, 11:32 am, Ian Michael Gumby <im_gu...@hotmail.com> wrote: > > Date: Wed, 26 Jan 2011 16:21:35 +0000 > > From: ma...@4glworks.com > > To: informix-l...@iiug.org > > Subject: Re: looping through CSV list > > > As others have pointed out, the question is - do you want to do it from inside > > the engine, or do you want to do it from a client? If you want to do it from a > > client - ie read the file, parse it and then do something with it, like insert > > values into a database, then you have many options. SQSL could easily do that > > for you: > > > let topix = "300000,310010,420011,650934" > > > for top_loop in <+ get topix +>; > > if (top_loop< 290000) then; > > # do something > > end if; > > end for; > > # do something else > > He never did say it was in engine or not. Since the values are in a comma delimited string (he said CSV) it could be in a comma delimited file. > > I saw Madison's response. > In C, why not use strtok and create tokens using the delimiter of ',' ? > Then you do an string to int conversion and then comparison. > > Much easier. > > And no, I'm not going to print out the code. That's left as an exercise of the user. (Hint: Google C and strtok example ) > > But hey! what do I know? ;-) > > -G That only works if you are certain of the content of the string.