Initial import.
FossilOrigin-Name: de46b0e10c5d9f516acbbf2ea01d84d0d5ac126412949d459265279262a1b87e
This commit is contained in:
commit
dbfce3528e
15 changed files with 586 additions and 0 deletions
19
exceptions/PGCommandFailedException.h
Normal file
19
exceptions/PGCommandFailedException.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#import "PGException.h"
|
||||
|
||||
@interface PGCommandFailedException: PGException
|
||||
{
|
||||
OFString *command;
|
||||
}
|
||||
|
||||
#ifdef OF_HAVE_PROPERTIES
|
||||
@property (readonly, copy, nonatomic) OFString *command;
|
||||
#endif
|
||||
|
||||
+ exceptionWithClass: (Class)class_
|
||||
connection: (PGConnection*)connection
|
||||
command: (OFString*)command;
|
||||
- initWithClass: (Class)class_
|
||||
connection: (PGConnection*)connection
|
||||
command: (OFString*)command;
|
||||
- (OFString*)command;
|
||||
@end
|
53
exceptions/PGCommandFailedException.m
Normal file
53
exceptions/PGCommandFailedException.m
Normal file
|
@ -0,0 +1,53 @@
|
|||
#import "PGCommandFailedException.h"
|
||||
|
||||
@implementation PGCommandFailedException
|
||||
+ exceptionWithClass: (Class)class
|
||||
connection: (PGConnection*)connection
|
||||
command: (OFString*)command
|
||||
{
|
||||
return [[[self alloc] initWithClass: class
|
||||
connection: connection
|
||||
command: command] autorelease];
|
||||
}
|
||||
|
||||
- initWithClass: (Class)class_
|
||||
connection: (PGConnection*)connection_
|
||||
command: (OFString*)command_
|
||||
{
|
||||
self = [super initWithClass: class_
|
||||
connection: connection_];
|
||||
|
||||
@try {
|
||||
command = [command_ copy];
|
||||
} @catch (id e) {
|
||||
[self release];
|
||||
@throw e;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[command release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (OFString*)description
|
||||
{
|
||||
if (description != nil)
|
||||
return description;
|
||||
|
||||
description = [[OFString alloc] initWithFormat:
|
||||
@"A PostgreSQL command in class %@ failed: %s\nCommand: %@",
|
||||
inClass, PQerrorMessage([connection PG_connection]), command];
|
||||
|
||||
return description;
|
||||
}
|
||||
|
||||
- (OFString*)command
|
||||
{
|
||||
OF_GETTER(command, NO)
|
||||
}
|
||||
@end
|
4
exceptions/PGConnectionFailedException.h
Normal file
4
exceptions/PGConnectionFailedException.h
Normal file
|
@ -0,0 +1,4 @@
|
|||
#import "PGException.h"
|
||||
|
||||
@interface PGConnectionFailedException: PGException
|
||||
@end
|
21
exceptions/PGConnectionFailedException.m
Normal file
21
exceptions/PGConnectionFailedException.m
Normal file
|
@ -0,0 +1,21 @@
|
|||
#import "PGConnectionFailedException.h"
|
||||
|
||||
@implementation PGConnectionFailedException
|
||||
- (OFString*)description
|
||||
{
|
||||
OFAutoreleasePool *pool;
|
||||
|
||||
if (description != nil)
|
||||
return description;
|
||||
|
||||
pool = [[OFAutoreleasePool alloc] init];
|
||||
description = [[OFString alloc] initWithFormat:
|
||||
@"Establishing a PostgreSQL connection in class %@ failed:\n%s\n"
|
||||
"Parameters: %@", inClass,
|
||||
PQerrorMessage([connection PG_connection]),
|
||||
[connection parameters]];
|
||||
[pool release];
|
||||
|
||||
return description;
|
||||
}
|
||||
@end
|
19
exceptions/PGException.h
Normal file
19
exceptions/PGException.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#import <ObjFW/ObjFW.h>
|
||||
|
||||
#import "PGConnection.h"
|
||||
|
||||
@interface PGException: OFException
|
||||
{
|
||||
PGConnection *connection;
|
||||
}
|
||||
|
||||
#ifdef OF_HAVE_PROPERTIES
|
||||
@property (readonly, retain, nonatomic) PGConnection *connection;
|
||||
#endif
|
||||
|
||||
+ exceptionWithClass: (Class)class_
|
||||
connection: (PGConnection*)connection;
|
||||
- initWithClass: (Class)class_
|
||||
connection: (PGConnection*)connection;
|
||||
- (PGConnection*)connection;
|
||||
@end
|
44
exceptions/PGException.m
Normal file
44
exceptions/PGException.m
Normal file
|
@ -0,0 +1,44 @@
|
|||
#import "PGException.h"
|
||||
|
||||
@implementation PGException
|
||||
+ exceptionWithClass: (Class)class
|
||||
connection: (PGConnection*)connection
|
||||
{
|
||||
return [[[self alloc] initWithClass: class
|
||||
connection: connection] autorelease];
|
||||
}
|
||||
|
||||
- initWithClass: (Class)class_
|
||||
connection: (PGConnection*)connection_
|
||||
{
|
||||
self = [super initWithClass: class_];
|
||||
|
||||
connection = [connection_ retain];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[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;
|
||||
}
|
||||
|
||||
- (PGConnection*)connection
|
||||
{
|
||||
OF_GETTER(connection, NO)
|
||||
}
|
||||
@end
|
Loading…
Add table
Add a link
Reference in a new issue