开发者

Issue in reading the value and storing in host variable?

My program reads records from file and for each record in file it fetches value from DB. I have declared a host variable in my Pro*C program. I used that host variable in one of my select query inside the program. The memory of the variable doesn't get cleared for each record.

For example, for the first record the sql query fetches "ABCD". Then for the second record the query开发者_Python百科 fetches "EFGHIJKL". For the third record the actual value in DB is "GHI" but the memory doesn't get cleared and it prints "GHIHIJKL".

How to resolve it?


Here basically what you should do. There's also a Pro*C inline setting that should do that automatically, but I had some problems with it, so I prefer this solution, which is fast and simple.

VARCHAR var[50+1];      /* Add 1 char more than the size of the queried column of the database */

EXEC SQL SELECT thing INTO :var WHERE /* whatever */

if(sqlca.sqlcode == 0) 
  var.arr[var.len] = 0;      /* Add the \0 char at the end of you var.


You either should work with the length provided with the database call, providing you with the capability of working with data containing NUL bytes.

Or you terminate your string manually with the given length. This works only with "NUL-less" strings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜