Skip to Content.
Sympa Menu

freetds - [freetds] Error getting second (or third) SYBINT4 column

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Xander Maas (GMAIL)" <xjmaas AT gmail.com>
  • To: freetds AT lists.ibiblio.org
  • Subject: [freetds] Error getting second (or third) SYBINT4 column
  • Date: Mon, 15 Nov 2010 16:26:04 +0100

Hi all,

I am just beginning using the FreeTDS library to write an Objective-C
application for Mac OS X. I have build the library from the
freetds-0.82.1.dev.20100810 tree.

When I try to get a second column containing a SYBINT4 column, I keep getting
a EXC_BAD_ACCESS error from gdb. I have tried several ways to get the value,
to no avail.

I am trying this in the code below. First I tried it with dbdata, like
intObject=*((DBINT *)dbdata(sybConn,i)); but also using a memcpy.

The first time I fetch the SYBINT4 I get the correct result, the second
column I fetch, kills my application.

Hope someone can help me with this.

Thanks in advance,

Xander


- (NSArray *)getRecordForCurrentRow {
int numCols = [self numberOfFields];
int i;
NSMutableArray *record = [NSMutableArray arrayWithCapacity:numCols];

/* First run through the columns and get their type and put their
value
* in our Array
*/

static DBINT intObject;
char charObject[255];
char varCharObject[255];
/*
* To be implemented later on...
* float floatObject;
*/

NSLog(@"We have %d columns to process", numCols);

for ( i = 1; i < (numCols + 1); i++ ) {
NSLog(@"We got a field of type: %d for column %d",
dbcoltype(sybConn, i), i);
switch (dbcoltype(sybConn, i)) {
case SYBINT4:

NSLog(@"We want to read the value at: %d",
(DBINT *)dbdata(sybConn, 1));

/*
* We want to return a value, if we got no
value from the query, BUT
* requested the field, return a nil to be
inserted into the array
*/
/*
if (dbdatlen(sybConn, i) == 0 ) {
NSLog(@"The length of this intObject
is: %d", dbdatlen(sybConn, i));
NSLog(@"We got no result? adding nil
to array");
[record addObject:[NSNumber
numberWithInt:0]];
} else {
NSLog(@"The length of this intObject
is: %d", dbdatlen(sybConn, i));

intObject = *((DBINT
*)dbdata(sybConn, i));

// Add the INT value to the array
NSLog(@"Adding INT: %d", intObject);
[record addObject:[NSNumber
numberWithInt:intObject]];
}
*/

memcpy(&intObject, dbdata(sybConn, i),
sizeof(intObject));
NSLog(@"Add the INT value: %d", intObject);
[record addObject:[NSNumber
numberWithInt:intObject]];

break;
case SYBCHAR:

if (dbdatlen(sybConn, 1) == 0 ) {
NSLog(@"The length of this charObject
is: %d", dbdatlen(sybConn, i));
NSLog(@"We got no result? adding nil
to array");
[record addObject:[NSString
stringWithString:@""]];
} else {
/* Copy the data from the buffer */
NSLog(@"This wil be address of our
charObject: %d", &charObject);
strncpy(charObject, (char
*)dbdata(sybConn, i), (int)dbdatlen(sybConn, i));

/* Add the terminating null character
*/
charObject[dbdatlen(sybConn, i)] =
'\0';

/* Add the charObject to the Array */
[record addObject: [self
stringWithUTF8CString:charObject] ];
NSLog(@"Adding NSString value %s",
charObject);
}
break;
case SYBVARCHAR:
if (dbdatlen(sybConn, 1) == 0 ) {
NSLog(@"The length of this charObject
is: %d", dbdatlen(sybConn, i));
NSLog(@"We got no result? adding nil
to array");
[record addObject:[NSString
stringWithString:@""]];
} else {

/* Copy the data from the buffer */
strncpy(varCharObject, (char
*)dbdata(sybConn, i), (int)dbdatlen(sybConn, i));

/* Add the terminating null character
*/
charObject[dbdatlen(sybConn, i)] =
'\0';

/* Add the charObject to the Array */
[record addObject:[self
stringWithUTF8CString:varCharObject]];
NSLog(@"Adding NSString value %s",
varCharObject);
}
break;

default:
return NULL;
break;
}
}
NSLog(@"We got the following Array: \n%@", record);
return (record) ? [NSArray arrayWithArray:record] : nil;
}


  • [freetds] Error getting second (or third) SYBINT4 column, Xander Maas (GMAIL), 11/15/2010

Archive powered by MHonArc 2.6.24.

Top of Page