Re: Dynamic ESQLC Question
Posted in 1999
Use SQLDA: 1) prepare q from :statement 2) describe q into d 3) allocate memory to d->sqlvar[i].sqldata 4) declare cursor c for q 5) open c 6) fetch c using descriptor d 7) while(sqlca.sqlcode == 0) { ...; fetch ... } Hope this helps anandpa@my-deja.com wrote: > > Hi, > > Here is the problem i have.... > > I have a table called 'JOB'. > There are 20 columns in it. > I want to write a single function which will take one or more column > names and their values, at run time, and updates the database. > > The Function prototype is : > int updateJob (noofrecs, char* colNames, char* colValues) > > colNames is a string which contains one or more column > names separated by space character. > Each invokation of updateJob may have diff. number of columns in > colNames string. > colValues is a string which will have value for each > of the column name variable in colNames, separated by space character. > > I can parse the colNames and colValues to get the column names > colName1, colName2, ... and their values, colValue1, colValue2 ... > > The point is that since i don't know until run time, the actual number > of columns, how do i declare the ESQL host vairables, to hold these > values and put in the ESQL statement? > > Is it possible to do something like following func. > > int updateJob (noofrecs, char* colNames_inp, char* colValues_inp) > { > EXEC SQL begin declare section > char* colNames; > char* colValues; > EXEC SQL end declare section > > /* mempry allocation goes here */ > > strcpy(colNames, colNames_inp); > strcpy(colValues, colValues_inp); > > EXEC SQL update JOB set :colNames = :colValues > where jobid = '12345678'; > > } > > I know that, the problem i have presented is more complex, than i have > tried to put in the above function. > > Appretiate any help. > Anand > > Sent via Deja.com http://www.deja.com/ > Share what you know. Learn what you don't. -- /* ----------------------------------------------------- * * Willem Roos wroos@shoprite.co.za * * roosj@mweb.co.za * * 0(+27)21 980 4941 * * 0(+27)21 919 0198 * * ----------------------------------------------------- */