Thread: [Mysql-cocoa-commits] CVS: SMySQL SMySQLResult.m,1.6,1.7
Brought to you by:
sergecohen
From: Serge C. <ser...@us...> - 2002-06-03 15:06:01
|
Update of /cvsroot/mysql-cocoa/SMySQL In directory usw-pr-cvs1:/tmp/cvs-serv19203 Modified Files: SMySQLResult.m Log Message: Corrected the NULL Field bug. When a NULL field is encountered a NSNull object is put in the NSArray or NSDictionary. Serge Cohen; MySQL Cocoa project, 2002-06-03. Index: SMySQLResult.m =================================================================== RCS file: /cvsroot/mysql-cocoa/SMySQL/SMySQLResult.m,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** SMySQLResult.m 15 May 2002 11:07:30 -0000 1.6 --- SMySQLResult.m 3 Jun 2002 15:05:58 -0000 1.7 *************** *** 213,287 **** id theCurrentObj,theDataObj; char *theData = calloc(sizeof(char),theLengths[i]+1); ! memcpy(theData, theRow[i],theLengths[i]); ! theData[theLengths[i]] = '\0'; ! // NSLog (@"in fetchRowAsDictionary : field type is %d, for column %d", (int)theField[i].type, (int)i); ! switch (theField[i].type) { ! case FIELD_TYPE_TINY: ! case FIELD_TYPE_SHORT: ! case FIELD_TYPE_LONG: ! case FIELD_TYPE_INT24: ! case FIELD_TYPE_LONGLONG: ! theCurrentObj = [NSNumber numberWithLong:atol(theData)]; ! break; ! case FIELD_TYPE_DECIMAL: ! case FIELD_TYPE_FLOAT: ! case FIELD_TYPE_DOUBLE: ! theCurrentObj = [NSNumber numberWithDouble:atof(theData)]; ! break; ! case FIELD_TYPE_TIMESTAMP: // Indeed one should check which format it is (14,12...2) and get the corresponding format string // a switch on theLength[i] would do that... // Here it will crash if it's not default presentation : TIMESTAMP(14) ! theCurrentObj = [NSCalendarDate dateWithString:[NSString stringWithUTF8String:theData] calendarFormat:@"%Y%m%d%H%M%S"]; ! break; ! case FIELD_TYPE_DATE: ! theCurrentObj = [NSCalendarDate dateWithString:[NSString stringWithUTF8String:theData] calendarFormat:@"%Y-%m-%d"]; ! break; ! case FIELD_TYPE_TIME: // Pass them back as string for the moment... not TIME object in Cocoa (so far) ! theCurrentObj = [NSString stringWithUTF8String:theData]; ! case FIELD_TYPE_DATETIME: ! theCurrentObj = [NSCalendarDate dateWithString:[NSString stringWithUTF8String:theData] calendarFormat:@"%Y-%m-%d %H:%M:%S"]; ! break; ! case FIELD_TYPE_YEAR: ! theCurrentObj = [NSCalendarDate dateWithString:[NSString stringWithUTF8String:theData] calendarFormat:@"%Y"]; ! break; ! case FIELD_TYPE_VAR_STRING: ! case FIELD_TYPE_STRING: ! theDataObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! theCurrentObj = [[NSString alloc] initWithData:theDataObj encoding:mEncoding]; ! [theCurrentObj autorelease]; ! break; ! case FIELD_TYPE_TINY_BLOB: ! case FIELD_TYPE_BLOB: ! case FIELD_TYPE_MEDIUM_BLOB: ! case FIELD_TYPE_LONG_BLOB: ! theCurrentObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! break; ! case FIELD_TYPE_SET: ! theDataObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! theCurrentObj = [[NSString alloc] initWithData:theDataObj encoding:mEncoding]; ! [theCurrentObj autorelease]; ! break; ! case FIELD_TYPE_ENUM: ! theDataObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! theCurrentObj = [[NSString alloc] initWithData:theDataObj encoding:mEncoding]; ! [theCurrentObj autorelease]; ! break; ! case FIELD_TYPE_NULL: ! theCurrentObj = nil; ! break; ! case FIELD_TYPE_NEWDATE: // Don't know what the format for this type is... ! theDataObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! theCurrentObj = [[NSString alloc] initWithData:theDataObj encoding:mEncoding]; ! [theCurrentObj autorelease]; ! break; ! default: ! NSLog (@"in fetchRowAsDictionary : Unknown type : %d for column %d, send back a NSData object", (int)theField[i].type, (int)i); ! theCurrentObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! break; } [theDict setObject:theCurrentObj forKey:[mNames objectAtIndex:i]]; --- 213,292 ---- id theCurrentObj,theDataObj; char *theData = calloc(sizeof(char),theLengths[i]+1); ! if (theRow[i] == NULL) { ! theCurrentObj = [NSNull null]; ! } ! else { ! memcpy(theData, theRow[i],theLengths[i]); ! theData[theLengths[i]] = '\0'; ! // NSLog (@"in fetchRowAsDictionary : field type is %d, for column %d", (int)theField[i].type, (int)i); ! switch (theField[i].type) { ! case FIELD_TYPE_TINY: ! case FIELD_TYPE_SHORT: ! case FIELD_TYPE_LONG: ! case FIELD_TYPE_INT24: ! case FIELD_TYPE_LONGLONG: ! theCurrentObj = [NSNumber numberWithLong:atol(theData)]; ! break; ! case FIELD_TYPE_DECIMAL: ! case FIELD_TYPE_FLOAT: ! case FIELD_TYPE_DOUBLE: ! theCurrentObj = [NSNumber numberWithDouble:atof(theData)]; ! break; ! case FIELD_TYPE_TIMESTAMP: // Indeed one should check which format it is (14,12...2) and get the corresponding format string // a switch on theLength[i] would do that... // Here it will crash if it's not default presentation : TIMESTAMP(14) ! theCurrentObj = [NSCalendarDate dateWithString:[NSString stringWithUTF8String:theData] calendarFormat:@"%Y%m%d%H%M%S"]; ! break; ! case FIELD_TYPE_DATE: ! theCurrentObj = [NSCalendarDate dateWithString:[NSString stringWithUTF8String:theData] calendarFormat:@"%Y-%m-%d"]; ! break; ! case FIELD_TYPE_TIME: // Pass them back as string for the moment... not TIME object in Cocoa (so far) ! theCurrentObj = [NSString stringWithUTF8String:theData]; ! case FIELD_TYPE_DATETIME: ! theCurrentObj = [NSCalendarDate dateWithString:[NSString stringWithUTF8String:theData] calendarFormat:@"%Y-%m-%d %H:%M:%S"]; ! break; ! case FIELD_TYPE_YEAR: ! theCurrentObj = [NSCalendarDate dateWithString:[NSString stringWithUTF8String:theData] calendarFormat:@"%Y"]; ! break; ! case FIELD_TYPE_VAR_STRING: ! case FIELD_TYPE_STRING: ! theDataObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! theCurrentObj = [[NSString alloc] initWithData:theDataObj encoding:mEncoding]; ! [theCurrentObj autorelease]; ! break; ! case FIELD_TYPE_TINY_BLOB: ! case FIELD_TYPE_BLOB: ! case FIELD_TYPE_MEDIUM_BLOB: ! case FIELD_TYPE_LONG_BLOB: ! theCurrentObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! break; ! case FIELD_TYPE_SET: ! theDataObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! theCurrentObj = [[NSString alloc] initWithData:theDataObj encoding:mEncoding]; ! [theCurrentObj autorelease]; ! break; ! case FIELD_TYPE_ENUM: ! theDataObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! theCurrentObj = [[NSString alloc] initWithData:theDataObj encoding:mEncoding]; ! [theCurrentObj autorelease]; ! break; ! case FIELD_TYPE_NULL: ! theCurrentObj = nil; ! break; ! case FIELD_TYPE_NEWDATE: // Don't know what the format for this type is... ! theDataObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! theCurrentObj = [[NSString alloc] initWithData:theDataObj encoding:mEncoding]; ! [theCurrentObj autorelease]; ! break; ! default: ! NSLog (@"in fetchRowAsDictionary : Unknown type : %d for column %d, send back a NSData object", (int)theField[i].type, (int)i); ! theCurrentObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! break; ! } } [theDict setObject:theCurrentObj forKey:[mNames objectAtIndex:i]]; *************** *** 324,399 **** id theCurrentObj,theDataObj; char *theData = calloc(sizeof(char),theLengths[i]+1); ! memcpy(theData, theRow[i],theLengths[i]); ! theData[theLengths[i]] = '\0'; ! // NSLog (@"in fetchRowAsArray : field type is %d, for column %d", (int)theField[i].type, (int)i); ! switch (theField[i].type) { ! case FIELD_TYPE_TINY: ! case FIELD_TYPE_SHORT: ! case FIELD_TYPE_LONG: ! case FIELD_TYPE_INT24: ! case FIELD_TYPE_LONGLONG: ! theCurrentObj = [NSNumber numberWithLong:atol(theData)]; ! break; ! case FIELD_TYPE_DECIMAL: ! case FIELD_TYPE_FLOAT: ! case FIELD_TYPE_DOUBLE: ! theCurrentObj = [NSNumber numberWithDouble:atof(theData)]; ! break; ! case FIELD_TYPE_TIMESTAMP: // Indeed one should check which format it is (14,12...2) and get the corresponding format string // a switch on theLength[i] would do that... // Here it will crash if it's not default presentation : TIMESTAMP(14) ! theCurrentObj = [NSCalendarDate dateWithString:[NSString stringWithUTF8String:theData] calendarFormat:@"%Y%m%d%H%M%S"]; ! break; ! case FIELD_TYPE_DATE: ! theCurrentObj = [NSCalendarDate dateWithString:[NSString stringWithUTF8String:theData] calendarFormat:@"%Y-%m-%d"]; ! break; ! case FIELD_TYPE_TIME: // Pass them back as string for the moment... not TIME object in Cocoa (so far) ! theCurrentObj = [NSString stringWithUTF8String:theData]; ! case FIELD_TYPE_DATETIME: ! theCurrentObj = [NSCalendarDate dateWithString:[NSString stringWithUTF8String:theData] calendarFormat:@"%Y-%m-%d %H:%M:%S"]; ! break; ! case FIELD_TYPE_YEAR: ! theCurrentObj = [NSCalendarDate dateWithString:[NSString stringWithUTF8String:theData] calendarFormat:@"%Y"]; ! break; ! case FIELD_TYPE_VAR_STRING: ! case FIELD_TYPE_STRING: ! theDataObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! theCurrentObj = [[NSString alloc] initWithData:theDataObj encoding:mEncoding]; ! [theCurrentObj autorelease]; ! break; ! case FIELD_TYPE_TINY_BLOB: ! case FIELD_TYPE_BLOB: ! case FIELD_TYPE_MEDIUM_BLOB: ! case FIELD_TYPE_LONG_BLOB: ! theCurrentObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! break; ! case FIELD_TYPE_SET: ! theDataObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! theCurrentObj = [[NSString alloc] initWithData:theDataObj encoding:mEncoding]; ! [theCurrentObj autorelease]; ! break; ! case FIELD_TYPE_ENUM: ! theDataObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! theCurrentObj = [[NSString alloc] initWithData:theDataObj encoding:mEncoding]; ! [theCurrentObj autorelease]; ! break; ! case FIELD_TYPE_NULL: ! theCurrentObj = nil; ! break; ! case FIELD_TYPE_NEWDATE: // Don't know what the format for this type is... ! theDataObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! theCurrentObj = [[NSString alloc] initWithData:theDataObj encoding:mEncoding]; ! [theCurrentObj autorelease]; ! break; ! default: ! NSLog (@"in fetchRowAsArray : Unknown type : %d for column %d, send back a NSData object", (int)theField[i].type, (int)i); ! theCurrentObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! break; } [theArray addObject:theCurrentObj]; --- 329,409 ---- id theCurrentObj,theDataObj; char *theData = calloc(sizeof(char),theLengths[i]+1); ! if (theRow[i] == NULL) { ! theCurrentObj = [NSNull null]; ! } ! else { ! memcpy(theData, theRow[i],theLengths[i]); ! theData[theLengths[i]] = '\0'; ! // NSLog (@"in fetchRowAsArray : field type is %d, for column %d", (int)theField[i].type, (int)i); ! switch (theField[i].type) { ! case FIELD_TYPE_TINY: ! case FIELD_TYPE_SHORT: ! case FIELD_TYPE_LONG: ! case FIELD_TYPE_INT24: ! case FIELD_TYPE_LONGLONG: ! theCurrentObj = [NSNumber numberWithLong:atol(theData)]; ! break; ! case FIELD_TYPE_DECIMAL: ! case FIELD_TYPE_FLOAT: ! case FIELD_TYPE_DOUBLE: ! theCurrentObj = [NSNumber numberWithDouble:atof(theData)]; ! break; ! case FIELD_TYPE_TIMESTAMP: // Indeed one should check which format it is (14,12...2) and get the corresponding format string // a switch on theLength[i] would do that... // Here it will crash if it's not default presentation : TIMESTAMP(14) ! theCurrentObj = [NSCalendarDate dateWithString:[NSString stringWithUTF8String:theData] calendarFormat:@"%Y%m%d%H%M%S"]; ! break; ! case FIELD_TYPE_DATE: ! theCurrentObj = [NSCalendarDate dateWithString:[NSString stringWithUTF8String:theData] calendarFormat:@"%Y-%m-%d"]; ! break; ! case FIELD_TYPE_TIME: // Pass them back as string for the moment... not TIME object in Cocoa (so far) ! theCurrentObj = [NSString stringWithUTF8String:theData]; ! case FIELD_TYPE_DATETIME: ! theCurrentObj = [NSCalendarDate dateWithString:[NSString stringWithUTF8String:theData] calendarFormat:@"%Y-%m-%d %H:%M:%S"]; ! break; ! case FIELD_TYPE_YEAR: ! theCurrentObj = [NSCalendarDate dateWithString:[NSString stringWithUTF8String:theData] calendarFormat:@"%Y"]; ! break; ! case FIELD_TYPE_VAR_STRING: ! case FIELD_TYPE_STRING: ! theDataObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! theCurrentObj = [[NSString alloc] initWithData:theDataObj encoding:mEncoding]; ! [theCurrentObj autorelease]; ! break; ! case FIELD_TYPE_TINY_BLOB: ! case FIELD_TYPE_BLOB: ! case FIELD_TYPE_MEDIUM_BLOB: ! case FIELD_TYPE_LONG_BLOB: ! theCurrentObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! break; ! case FIELD_TYPE_SET: ! theDataObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! theCurrentObj = [[NSString alloc] initWithData:theDataObj encoding:mEncoding]; ! [theCurrentObj autorelease]; ! break; ! case FIELD_TYPE_ENUM: ! theDataObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! theCurrentObj = [[NSString alloc] initWithData:theDataObj encoding:mEncoding]; ! [theCurrentObj autorelease]; ! break; ! case FIELD_TYPE_NULL: ! theCurrentObj = nil; ! break; ! case FIELD_TYPE_NEWDATE: // Don't know what the format for this type is... ! theDataObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! theCurrentObj = [[NSString alloc] initWithData:theDataObj encoding:mEncoding]; ! [theCurrentObj autorelease]; ! break; ! default: ! NSLog (@"in fetchRowAsArray : Unknown type : %d for column %d, send back a NSData object", (int)theField[i].type, (int)i); ! theCurrentObj = [NSData dataWithBytes:theData length:theLengths[i]]; ! break; ! } } [theArray addObject:theCurrentObj]; |