Subject | Re: [firebird-support] How do you trim fetched char/varchar column? |
---|---|
Author | Martijn Tonies |
Post date | 2006-04-13T15:02:02Z |
> select id, name from Staff;╠╠╠╠╠╠╠╠╠╠╠
>
> with sqlda defined as:
>
> pSqlda->sqlvar[1].sqldata = (char *)&name;
> pSqlda->sqlvar[1].sqltype = SQL_TEXT + 1;
> pSqlda->sqlvar[1].sqlind = &nameFlag;
>
> where name is declared as char(64).
>
> What I got is:
>
> id: 10 name: Amy Ambrose
>
;╠╠╠╠╠╠╠╠╠╠μ
8;╠╠╠╠╠╠╠╠╠╠_
68;╠╠╠e
> id: 110 name: Barbara Betty╠╠╠╠╠╠╠╠╠╠╠
>
;╠╠╠╠╠╠╠╠╠╠μ
8;╠╠╠╠╠╠╠╠╠╠_
68;╠╠╠e
>Actually, CHAR(n) always returns "n" characters, as it should, and
> I tried using trim function to trim the returned name but that didn't
> fix it.
>
> If only I know the fetched data length, then I can physically trim the
> returned string by inserting a 0x00 at the proper length.
>
> In other commercial databse APIs that I used, the pSQLDA->sqllen
> contains the actual fetched data length returned. But in Firebird,
> this field returns the max. size of the column.
padded with spaces.
VARCHAR(n) will return unpadded data.
Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Oracle &
MS SQL Server
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com