ObjPgSQL  Artifact [4f6df79034]

Artifact 4f6df79034a8b614f1b8627c7ab3fe775fbaef9b9c93dae2cdf9867220f10b4e:


#import "PGException.h"

@implementation PGException
+ (instancetype)exceptionWithConnection: (PGConnection*)connection
{
	return [[[self alloc] initWithConnection: connection] autorelease];
}

- initWithConnection: (PGConnection*)connection
{
	self = [super init];

	@try {
		_connection = [connection retain];
		_error = [[OFString alloc]
		    initWithCString: PQerrorMessage([_connection PG_connection])
			   encoding: [OFSystemInfo native8BitEncoding]];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_connection release];
	[_error release];

	[super dealloc];
}

- (OFString*)description
{
	return [OFString stringWithFormat: @"A PostgreSQL operation failed: %@",
					   _error];
}

- (PGConnection*)connection
{
	OF_GETTER(_connection, NO)
}
@end