Apple Enterprise - NeXTanswers Support Archive

Search NeXTanswers for:


Title: Trailing spaces in fixed length non null character fields

Entry Number:

Last Updated: 22 November 1995
Document Revision:

space, Sybase, character, adaptor


After installing EOF Release 1.1, I noticed that my column attributes which are defined as fixed length non-null character fields are now blank padded when fetched. How can I correct this behavior?


With the EOF 1.1 Sybase adaptor, non-null fixed length CHAR fields (for example CHAR(8)) end up space padded when fetched. This behavior is peculiar to Sybase, even though EOF Release 1.0 automatically removes these spaces.

You can return to the same behavior as in EOF 1.0 by adding the following code to your application. Note that you must statically link the Sybase adaptor with your application in order to use this workaround with the following Makefile.preamble option:

OTHER_OFILES: /NextLibrary/Adaptors/Sybase.dbadaptor/Sybase

// You may freely copy, distribute, and reuse the code in this example.
// NeXT disclaims any warranty of any kind, expressed or implied, as to its
// fitness for any particular use.
// This code uses private API of the Sybase adaptor and will likely need
// to be changed for future releases of EOF.
// Below, we create a subclass of a private part of the Sybase adaptor
// (SybaseStringColumn) so that we can strip trailing blanks on columns
// declared "char not null". Char columns which can be null and varchar
// columns automatically have trailing spaces removed. If we were to let
// these extended values slip through to the database layer of EOF all kinds
// of problems would ensue because "hello" != "hello " in C, but they would
// be compared as equal in the db.

#import <eoaccess/eoaccess.h>


@interface SybaseColumn : NSObject
void *_channel;
void *_dbProcess;
void *_attribute;
int _srcType;

@interface SybaseStringColumn:SybaseColumn
- valueFromBytes:(void *)bytes length:(int)length zone:(NSZone *)zone;

@interface HackedSybaseStringColumn:SybaseStringColumn
+ load;
- valueFromBytes:(void *)bytes length:(int)length zone:(NSZone *)zone;

@implementation HackedSybaseStringColumn

+ load
[self poseAsClass:[SybaseStringColumn class]];
return self;

- valueFromBytes:(void *)bytes length:(int)length zone:(NSZone *)zone
const char *ptr;

if (_srcType == SYBASE_CHAR_TYPE) {
ptr = (const char *)bytes + length - 1;
while (ptr >= (const char *)bytes && *ptr == ' ')
length = ptr - (const char *)bytes + 1;

return [super valueFromBytes:bytes length:length zone:zone];


Valid for: EOF 1.1, NEXTSTEP 3.2 Developer, NEXTSTEP 3.3 Developer

See Also:

OpenStep | Alliances | Training | Tech Support | Where to Buy