Q: Problem with ESQL/C and fetch
Posted in 1997
Hello out there, I've a problem with fetching a row of type char from a table within ESQL/C. When I try to fetch, I get always the char field filled up with blanks. How can I obtain informations about the real length of the stored value? I've attached a short piece of code, demonstrating my method to get the data. There's a table called "gebiet" containing a field called "str" of type CHAR(30). The host variable "str" is always filled up with trailing blanks. Does anybody have an idea? Any hints are welcome... If you want to answer via email, please respond to the follwing address: dirk.scheer@stadt-mh.de ---> #include <stdio.h> $include sqlca.h; $include sqltypes.h; # include "sqlproto.h" int main() { long status; EXEC SQL BEGIN DECLARE SECTION; char str[31]; long strs, hnr; EXEC SQL END DECLARE SECTION; <snipp ... OPEN DATABASE ... snipp> /* Description: The opened database contains a table named 'gebiet'. The field "str" is defined as CHAR(30). There is one record in the table that contains the value " " (one blank). After fetching this row, the host variable contains 30 Blanks !!!! */ EXEC SQL prepare q_id from "select str from gebiet where strs=? and hnr = ?"; EXEC SQL declare q_cursor cursor for q_id; strs = 1; hnr = 1; EXEC SQL open q_cursor using :strs, :hnr; EXEC SQL FETCH q_cursor into :str; <snipp ... CLOSE CURSOR / DATABASE ... snipp> return 0; }