Index: PGConnection.h ================================================================== --- PGConnection.h +++ PGConnection.h @@ -4,12 +4,12 @@ #import "PGResult.h" @interface PGConnection: OFObject { - PGconn *conn; - OFDictionary *parameters; + PGconn *_connnection; + OFDictionary *_parameters; } #ifdef OF_HAVE_PROPERTIES @property (copy) OFDictionary *parameters; #endif Index: PGConnection.m ================================================================== --- PGConnection.m +++ PGConnection.m @@ -4,65 +4,65 @@ #import "PGCommandFailedException.h" @implementation PGConnection - (void)dealloc { - [parameters release]; + [_parameters release]; - if (conn != NULL) - PQfinish(conn); + if (_connnection != NULL) + PQfinish(_connnection); [super dealloc]; } -- (void)setParameters: (OFDictionary*)parameters_ +- (void)setParameters: (OFDictionary*)parameters { - OF_SETTER(parameters, parameters_, YES, YES) + OF_SETTER(_parameters, parameters, YES, YES) } - (OFDictionary*)parameters { - OF_GETTER(parameters, YES) + OF_GETTER(_parameters, YES) } - (void)connect { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFEnumerator *keyEnumerator = [parameters keyEnumerator]; - OFEnumerator *objectEnumerator = [parameters objectEnumerator]; - OFMutableString *conninfo = nil; + OFEnumerator *keyEnumerator = [_parameters keyEnumerator]; + OFEnumerator *objectEnumerator = [_parameters objectEnumerator]; + OFMutableString *connectionInfo = nil; OFString *key, *object; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { - if (conninfo != nil) - [conninfo appendFormat: @" %@=%@", key, object]; + if (connectionInfo != nil) + [connectionInfo appendFormat: @" %@=%@", key, object]; else - conninfo = [OFMutableString stringWithFormat: + connectionInfo = [OFMutableString stringWithFormat: @"%@=%@", key, object]; } - if ((conn = PQconnectdb([conninfo UTF8String])) == NULL) + if ((_connnection = PQconnectdb([connectionInfo UTF8String])) == NULL) @throw [OFOutOfMemoryException exceptionWithClass: [self class]]; - if (PQstatus(conn) == CONNECTION_BAD) + if (PQstatus(_connnection) == CONNECTION_BAD) @throw [PGConnectionFailedException exceptionWithClass: [self class] connection: self]; [pool release]; } - (void)reset { - PQreset(conn); + PQreset(_connnection); } - (PGResult*)executeCommand: (OFConstantString*)command { - PGresult *result = PQexec(conn, [command UTF8String]); + PGresult *result = PQexec(_connnection, [command UTF8String]); if (PQresultStatus(result) == PGRES_FATAL_ERROR) { PQclear(result); @throw [PGCommandFailedException exceptionWithClass: [self class] @@ -125,11 +125,11 @@ else values[i++] = [[parameter description] UTF8String]; } while ((parameter = va_arg(args, id)) != nil); - result = PQexecParams(conn, [command UTF8String], + result = PQexecParams(_connnection, [command UTF8String], argsCount, NULL, values, NULL, NULL, 0); } @finally { [self freeMemory: values]; } @@ -194,12 +194,12 @@ [command appendFormat: @"$%zd", ++i]; } [command appendString: @")"]; - result = PQexecParams(conn, [command UTF8String], (int)count, - NULL, values, NULL, NULL, 0); + result = PQexecParams(_connnection, [command UTF8String], + (int)count, NULL, values, NULL, NULL, 0); } @finally { [self freeMemory: values]; } [pool release]; @@ -229,8 +229,8 @@ [pool release]; } - (PGconn*)PG_connection { - return conn; + return _connnection; } @end Index: PGResult.h ================================================================== --- PGResult.h +++ PGResult.h @@ -2,11 +2,11 @@ #import @interface PGResult: OFArray { - PGresult *result; + PGresult *_result; } + PG_resultWithResult: (PGresult*)result; - PG_initWithResult: (PGresult*)result; - (PGresult*)PG_result; Index: PGResult.m ================================================================== --- PGResult.m +++ PGResult.m @@ -5,42 +5,42 @@ + PG_resultWithResult: (PGresult*)result { return [[[self alloc] PG_initWithResult: result] autorelease]; } -- PG_initWithResult: (PGresult*)result_ +- PG_initWithResult: (PGresult*)result { self = [super init]; - result = result_; + _result = result; return self; } - (void)dealloc { - if (result != NULL) - PQclear(result); + if (_result != NULL) + PQclear(_result); [super dealloc]; } - (size_t)count { - return PQntuples(result); + return PQntuples(_result); } - (id)objectAtIndex: (size_t)index { - if (index > PQntuples(result)) + if (index > PQntuples(_result)) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; return [PGResultRow rowWithResult: self row: (int)index]; } - (PGresult*)PG_result { - return result; + return _result; } @end Index: PGResultRow.h ================================================================== --- PGResultRow.h +++ PGResultRow.h @@ -4,13 +4,13 @@ #import "PGResult.h" @interface PGResultRow: OFDictionary { - PGResult *result; - PGresult *res; - int row; + PGResult *_result; + PGresult *_res; + int _row; } + rowWithResult: (PGResult*)result row: (int)row; - initWithResult: (PGResult*)result Index: PGResultRow.m ================================================================== --- PGResultRow.m +++ PGResultRow.m @@ -1,36 +1,39 @@ #import "PGResultRow.h" static id -convert_type(PGresult *res, int col, OFString *str) +convert_type(PGresult *res, int column, OFString *string) { - switch (PQftype(res, col)) { + switch (PQftype(res, column)) { case 16: /* BOOLOID */ - if ([str isEqual: @"t"]) + if ([string isEqual: @"t"]) return [OFNumber numberWithBool: YES]; else return [OFNumber numberWithBool: NO]; case 21: /* INT2OID */ - return [OFNumber numberWithInt16: (int16_t)[str decimalValue]]; + return [OFNumber numberWithInt16: + (int16_t)[string decimalValue]]; case 23: /* INT4OID */ - return [OFNumber numberWithInt32: (int32_t)[str decimalValue]]; + return [OFNumber numberWithInt32: + (int32_t)[string decimalValue]]; case 20: /* INT8OID */ - return [OFNumber numberWithInt64: (int64_t)[str decimalValue]]; + return [OFNumber numberWithInt64: + (int64_t)[string decimalValue]]; case 700: /* FLOAT4OID */ - return [OFNumber numberWithFloat: [str floatValue]]; + return [OFNumber numberWithFloat: [string floatValue]]; case 701: /* FLOAT8OID */ - return [OFNumber numberWithDouble: [str doubleValue]]; + return [OFNumber numberWithDouble: [string doubleValue]]; } - return str; + return string; } @interface PGResultRowEnumerator: OFEnumerator { - PGResult *result; - PGresult *res; - int row, pos, count; + PGResult *_result; + PGresult *_res; + int _row, _pos, _count; } - initWithResult: (PGResult*)result row: (int)row; @end @@ -47,68 +50,68 @@ { return [[[self alloc] initWithResult: result row: row] autorelease]; } -- initWithResult: (PGResult*)result_ - row: (int)row_ +- initWithResult: (PGResult*)result + row: (int)row { self = [super init]; - result = [result_ retain]; - res = [result PG_result]; - row = row_; + _result = [result retain]; + _res = [result PG_result]; + _row = row; return self; } - (void)dealloc { - [result release]; + [_result release]; [super dealloc]; } - (size_t)count { - int i, count, fields = PQnfields(res); + int i, count, fields = PQnfields(_res); for (i = count = 0; i < fields; i++) - if (!PQgetisnull(res, row, i)) + if (!PQgetisnull(_res, _row, i)) count++; return count; } - (id)objectForKey: (id)key { - int col; + int column; if ([key isKindOfClass: [OFNumber class]]) - col = [key intValue]; + column = [key intValue]; else - col = PQfnumber(res, [key UTF8String]); + column = PQfnumber(_res, [key UTF8String]); - if (PQgetisnull(res, row, col)) + if (PQgetisnull(_res, _row, column)) return nil; - return convert_type(res, col, - [OFString stringWithUTF8String: PQgetvalue(res, row, col)]); + return convert_type(_res, column, + [OFString stringWithUTF8String: PQgetvalue(_res, _row, column)]); } - (OFEnumerator*)keyEnumerator { return [[[PGResultRowKeyEnumerator alloc] - initWithResult: result - row: row] autorelease]; + initWithResult: _result + row: _row] autorelease]; } - (OFEnumerator*)objectEnumerator { return [[[PGResultRowObjectEnumerator alloc] - initWithResult: result - row: row] autorelease]; + initWithResult: _result + row: _row] autorelease]; } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state objects: (id*)objects count: (int)count @@ -115,25 +118,25 @@ { int i, j; if (state->extra[0] == 0) { state->extra[0] = 1; - state->extra[1] = PQnfields(res); + state->extra[1] = PQnfields(_res); } if (count > SIZE_MAX - state->state) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; if (state->state + count > state->extra[1]) count = state->extra[1] - state->state; for (i = j = 0; i < count; i++) { - if (PQgetisnull(res, row, state->state + i)) + if (PQgetisnull(_res, _row, state->state + i)) continue; objects[j++] = [OFString stringWithUTF8String: - PQfname(res, state->state + i)]; + PQfname(_res, state->state + i)]; } state->state += count; state->itemsPtr = objects; state->mutationsPtr = (unsigned long*)self; @@ -141,63 +144,63 @@ return j; } @end @implementation PGResultRowEnumerator -- initWithResult: (PGResult*)result_ - row: (int)row_ +- initWithResult: (PGResult*)result + row: (int)row { self = [super init]; - result = [result_ retain]; - res = [result PG_result]; - row = row_; - count = PQnfields(res); + _result = [result retain]; + _res = [result PG_result]; + _row = row; + _count = PQnfields(_res); return self; } - (void)dealloc { - [result release]; + [_result release]; [super dealloc]; } - (void)reset { - pos = 0; + _pos = 0; } @end @implementation PGResultRowKeyEnumerator - (id)nextObject { - if (pos >= count) + if (_pos >= _count) return nil; - while (pos < count && PQgetisnull(res, row, pos)) - pos++; + while (_pos < _count && PQgetisnull(_res, _row, _pos)) + _pos++; - if (pos >= count) + if (_pos >= _count) return nil; - return [OFString stringWithUTF8String: PQfname(res, pos++)]; + return [OFString stringWithUTF8String: PQfname(_res, _pos++)]; } @end @implementation PGResultRowObjectEnumerator - (id)nextObject { - if (pos >= count) + if (_pos >= _count) return nil; - while (pos < count && PQgetisnull(res, row, pos)) - pos++; + while (_pos < _count && PQgetisnull(_res, _row, _pos)) + _pos++; - if (pos >= count) + if (_pos >= _count) return nil; - return convert_type(res, pos, - [OFString stringWithUTF8String: PQgetvalue(res, row, pos++)]); + return convert_type(_res, _pos, + [OFString stringWithUTF8String: PQgetvalue(_res, _row, _pos++)]); } @end Index: exceptions/PGCommandFailedException.h ================================================================== --- exceptions/PGCommandFailedException.h +++ exceptions/PGCommandFailedException.h @@ -1,10 +1,10 @@ #import "PGException.h" @interface PGCommandFailedException: PGException { - OFString *command; + OFString *_command; } #ifdef OF_HAVE_PROPERTIES @property (readonly, copy, nonatomic) OFString *command; #endif Index: exceptions/PGCommandFailedException.m ================================================================== --- exceptions/PGCommandFailedException.m +++ exceptions/PGCommandFailedException.m @@ -8,19 +8,19 @@ return [[[self alloc] initWithClass: class connection: connection command: command] autorelease]; } -- initWithClass: (Class)class_ - connection: (PGConnection*)connection_ - command: (OFString*)command_ +- initWithClass: (Class)class + connection: (PGConnection*)connection + command: (OFString*)command { - self = [super initWithClass: class_ - connection: connection_]; + self = [super initWithClass: class + connection: connection]; @try { - command = [command_ copy]; + _command = [command copy]; } @catch (id e) { [self release]; @throw e; } @@ -27,27 +27,23 @@ return self; } - (void)dealloc { - [command release]; + [_command release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; - - description = [[OFString alloc] initWithFormat: + return [OFString stringWithFormat: @"A PostgreSQL command in class %@ failed: %s\nCommand: %@", - inClass, PQerrorMessage([connection PG_connection]), command]; - - return description; + [self inClass], PQerrorMessage([_connection PG_connection]), + _command]; } - (OFString*)command { - OF_GETTER(command, NO) + OF_GETTER(_command, NO) } @end Index: exceptions/PGConnectionFailedException.m ================================================================== --- exceptions/PGConnectionFailedException.m +++ exceptions/PGConnectionFailedException.m @@ -1,21 +1,12 @@ #import "PGConnectionFailedException.h" @implementation PGConnectionFailedException - (OFString*)description { - OFAutoreleasePool *pool; - - if (description != nil) - return description; - - pool = [[OFAutoreleasePool alloc] init]; - description = [[OFString alloc] initWithFormat: + return [OFString stringWithFormat: @"Establishing a PostgreSQL connection in class %@ failed:\n%s\n" - "Parameters: %@", inClass, - PQerrorMessage([connection PG_connection]), - [connection parameters]]; - [pool release]; - - return description; + "Parameters: %@", [self inClass], + PQerrorMessage([_connection PG_connection]), + [_connection parameters]]; } @end Index: exceptions/PGException.h ================================================================== --- exceptions/PGException.h +++ exceptions/PGException.h @@ -2,11 +2,11 @@ #import "PGConnection.h" @interface PGException: OFException { - PGConnection *connection; + PGConnection *_connection; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) PGConnection *connection; #endif Index: exceptions/PGException.m ================================================================== --- exceptions/PGException.m +++ exceptions/PGException.m @@ -6,39 +6,34 @@ { return [[[self alloc] initWithClass: class connection: connection] autorelease]; } -- initWithClass: (Class)class_ - connection: (PGConnection*)connection_ +- initWithClass: (Class)class + connection: (PGConnection*)connection { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - connection = [connection_ retain]; + _connection = [connection retain]; return self; } - (void)dealloc { - [connection release]; + [_connection release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; - - description = [[OFString alloc] initWithFormat: - @"A PostgreSQL operation in class %@ failed: %s", inClass, - PQerrorMessage([connection PG_connection])]; - - return description; + return [OFString stringWithFormat: + @"A PostgreSQL operation in class %@ failed: %s", [self inClass], + PQerrorMessage([_connection PG_connection])]; } - (PGConnection*)connection { - OF_GETTER(connection, NO) + OF_GETTER(_connection, NO) } @end