From: <dav...@us...> - 2009-01-14 05:02:54
|
Revision: 225 http://pgsqlformac.svn.sourceforge.net/pgsqlformac/?rev=225&view=rev Author: davydgeyl Date: 2009-01-14 05:02:50 +0000 (Wed, 14 Jan 2009) Log Message: ----------- PGgetisnull was using wrong argument 'column' and fields with NULL result simply did not work. data was not released - memory leak as Boolean worked wrong Modified Paths: -------------- trunk/PGSQLKit/PGSQLField.m Modified: trunk/PGSQLKit/PGSQLField.m =================================================================== --- trunk/PGSQLKit/PGSQLField.m 2009-01-13 02:07:48 UTC (rev 224) +++ trunk/PGSQLKit/PGSQLField.m 2009-01-14 05:02:50 UTC (rev 225) @@ -14,30 +14,36 @@ -(id)initWithResult:(void *)result forColumn:(PGSQLColumn *)forColumn atRow:(int)atRow { - [super init]; + self = [super init]; - data = nil; + if (self) + { + data = nil; - if (PQgetisnull(result, atRow, [column index]) == 1) { - return self; + if (PQgetisnull(result, atRow, [forColumn index]) != 1) + { + char* szBuf = nil; + + column = [forColumn retain]; + int iLen = PQgetlength(result, atRow, [column index]) + 1; + + // this may have to be adjust if the column type is not 0 (eg, it's binary) + szBuf = PQgetvalue(result, atRow, [column index]); + if (iLen > 0) + data = [[NSData alloc] initWithBytes:szBuf length:iLen]; + } } - - int iLen; - char *szBuf; - - column = forColumn; - iLen = PQgetlength(result, atRow, [column index]) + 1; - - // this may have to be adjust if the column type is not 0 (eg, it's binary) - szBuf = PQgetvalue(result, atRow, [column index]); - data = nil; - if (iLen > 0) { - data = [[NSData alloc] initWithBytes:szBuf length:iLen]; - } return self; } +- (void)dealloc +{ + [data release]; + [column release]; + [super dealloc]; +} + -(NSString *)asString { NSString* result = @""; @@ -127,13 +133,15 @@ -(BOOL)asBoolean { - if (data != nil) { - return ([data bytes] == 't'); + BOOL result = NO; + if (data != nil) + { + char charResult = *(char*)[data bytes]; + result = (charResult == 't'); } - return NO; + return result; } - -(BOOL)isNull { return (data == nil); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |