Re: Q: Problem with ESQL/C and fetch
Posted in 1997
Dirk,
Why not return the length when you return the value? Just add another
host variable for the length and do:
select str, length(str) from gebiet where .....
Now you can either stringcopy into another variable, only the chars
which are good, or manipulate the "str" anyway you want.
Hope this helps,
Tracy
}
} 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;
} }
}
--
=========================================================================
= Tracy W. Nedd =
= Banctec Inc. - DBA =
= Silver Spring, Md =
= tracyn@banctec.clark.net or tracyn@asd.banctec.com =
=========================================================================
= ALL RIGHTS RESERVED. =
= This posting is copyright and may be used only for the purposes =
= of professional study, or the professional exchange of information. =
= Use of this posting by any commercial organization for the purposes =
= of vilifying another is explicitly prohibited. =
=========================================================================