Re: Using indicators to set values to null
Posted in 2000
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
Steve Molitor wrote:
> I haven't had much luck using indicator values to indicate a null
> value in an insert or update statement, using esql/c. Even if I set
> the indicator value to -1, the database always ignores it and puts the
> value I supply into the column, instead of null.
>
> For example, this doesn't seem to work right:
>
> EXEC SQL BEGIN DECLARE SECTION:
> long age = 43;
> short ind = 1;
ind = -1; !!!
>
> EXEC SQL END DECLARE SECTION;
>
> EXEC SQL
> UPDATE EMPLOYEES SET AGE = :age INDICATOR :ind;>
> The age field is set to 43, not null as I would expect. (Nulls are
> allowed in the age column). This is a contrived example, but it
> illustrates the problem.
>
> Is this a known bug? Any workarounds? Am I doing something wrong?
> The esql documentation indicates that you can use indicators to update
> values, but I couldn't find any examples.
>
> Thanks!
>
> --
> Steve Molitor
> smolitor@erac.com
> "Emacs is the Computer"
This is not a bug, your esql/c is doing what it should do!
MC.
Michel <noresponse@autelca.ascom.ch> writes: > Steve Molitor wrote: > > > I haven't had much luck using indicator values to indicate a null > > value in an insert or update statement, using esql/c. Even if I set > > the indicator value to -1, the database always ignores it and puts the > > value I supply into the column, instead of null. > > > > For example, this doesn't seem to work right: > > > > EXEC SQL BEGIN DECLARE SECTION: > > long age = 43; > > short ind = 1; > > ind = -1; !!! Sorry, typo on my part. I'm actually setting it to -1. But I'm still having trouble getting it to work. I guess I should have said that my example was a simplified example typed in manually. I'll try to copy in a real example from actually code shortly (I'm a bit busy at the moment). But, anyway, does this kind of code work (when the indicator is properly set to -1 :)) for you? Thanks! -- Steve Molitor smolitor@erac.com "Emacs is the Computer"
Steve Molitor wrote: > Michel <noresponse@autelca.ascom.ch> writes: > > > Steve Molitor wrote: > > > > > I haven't had much luck using indicator values to indicate a null > > > value in an insert or update statement, using esql/c. Even if I set > > > the indicator value to -1, the database always ignores it and puts the > > > value I supply into the column, instead of null. > > > > > > For example, this doesn't seem to work right: > > > > > > EXEC SQL BEGIN DECLARE SECTION: > > > long age = 43; short ind = -1; > EXEC SQL END DECLARE SECTION; EXEC SQL UPDATE EMPLOYEES SET AGE = (:age INDICATOR :ind) WHERE .... ; if (sqlca.sqlcode) printf ("sqlcode %ld\\n", sqlca.sqlcode); > > Sorry, typo on my part. I'm actually setting it to -1. But I'm still > having trouble getting it to work. I guess I should have said that my > example was a simplified example typed in manually. I'll try to copy > in a real example from actually code shortly (I'm a bit busy at the > moment). > > But, anyway, does this kind of code work (when the indicator is > properly set to -1 :)) for you? No. it need: 1) paranthesis if not exec error ! 2) always test your request: may be your syntax is wrong, as it appears here. 3) an esql/c manual. > > > Thanks! > > -- > Steve Molitor > smolitor@erac.com > "Emacs is the Computer"