Re: Cursors, datablades and host variables
Posted in 1999
Mark Jenkins wrote: > > I'm using an insert cursor to update a simple database table which consists > of an integer and a datablade blade_t, which requires four integer values > to be created. The statement I am using is: > > EXEC SQL declare cInsert cursor for insert into dbTable values (:hostvar1, > createValue(1,2,3,4)); > EXEC SQL open cInsert; > > this works fine however if I declare an integer host variable :hostVar2 then > the following locks on attempting to open the cursor: > > EXEC SQL declare cInsert cursor for insert into dbTable values (:hostVar1, > createValue(:hostVar2,2,3,4)); > EXEC SQL open cInsert; > > Any ideas why, or how to get around this? I assume you are going to be PUTting several rows to the cursor and want to vary the value of hostVar2 each time, so: EXEC SQL BEGIN DECLARE SECTION; int hostVar2; blade_t bladeValue; ... EXEC SQL END DECLARE SECTION; EXEC SQL PREPARE sInsert FROM "INSERT INTO dbTable values (?,?)"; EXEC SQL DECLARE cInsert CURSOR FOR sInsert; EXEC SQL OPEN cInsert; for (;;) { ... hostVar2 = foo(); bladeValue = createValue(hostVar2, 2, 3, 4); EXEC SQL PUT cInsert USING :hostVar1, :bladeValue; ... } EXEC SQL FLUSH cInsert; EXEC SQL CLOSE cInsert; EXEC SQL FREE cInsert; EXEC SQL FREE sInsert; Art S. Kagel