ObjPgSQL  Diff

Differences From Artifact [12a5dca2c4]:

To Artifact [b625cd9199]:


1



2
3
4
5
6
7
8
#import "PGConnection.h"




#import "PGConnectionFailedException.h"
#import "PGCommandFailedException.h"

@implementation PGConnection
@synthesize parameters = _parameters;


>
>
>







1
2
3
4
5
6
7
8
9
10
11
#import "PGConnection.h"
#import "PGConnection+Private.h"
#import "PGResult.h"
#import "PGResult+Private.h"

#import "PGConnectionFailedException.h"
#import "PGCommandFailedException.h"

@implementation PGConnection
@synthesize parameters = _parameters;

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
		if (connectionInfo != nil)
			[connectionInfo appendFormat: @" %@=%@", key, object];
		else
			connectionInfo = [OFMutableString stringWithFormat:
			    @"%@=%@", key, object];
	}

	if ((_connnection = PQconnectdb([connectionInfo UTF8String])) == NULL)
		@throw [OFOutOfMemoryException exception];

	if (PQstatus(_connnection) == CONNECTION_BAD)
		@throw [PGConnectionFailedException
		    exceptionWithConnection: self];

	objc_autoreleasePoolPop(pool);
}

- (void)reset
{
	PQreset(_connnection);
}

- (void)close
{
	if (_connnection != NULL)
		PQfinish(_connnection);

	_connnection = NULL;
}

- (PGResult *)executeCommand: (OFConstantString *)command
{
	PGresult *result = PQexec(_connnection, [command UTF8String]);

	if (PQresultStatus(result) == PGRES_FATAL_ERROR) {
		PQclear(result);
		@throw [PGCommandFailedException
		    exceptionWithConnection: self
				    command: command];
	}







|


|








|




|
|

|




|







33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
		if (connectionInfo != nil)
			[connectionInfo appendFormat: @" %@=%@", key, object];
		else
			connectionInfo = [OFMutableString stringWithFormat:
			    @"%@=%@", key, object];
	}

	if ((_connection = PQconnectdb([connectionInfo UTF8String])) == NULL)
		@throw [OFOutOfMemoryException exception];

	if (PQstatus(_connection) == CONNECTION_BAD)
		@throw [PGConnectionFailedException
		    exceptionWithConnection: self];

	objc_autoreleasePoolPop(pool);
}

- (void)reset
{
	PQreset(_connection);
}

- (void)close
{
	if (_connection != NULL)
		PQfinish(_connection);

	_connection = NULL;
}

- (PGResult *)executeCommand: (OFConstantString *)command
{
	PGresult *result = PQexec(_connection, [command UTF8String]);

	if (PQresultStatus(result) == PGRES_FATAL_ERROR) {
		PQclear(result);
		@throw [PGCommandFailedException
		    exceptionWithConnection: self
				    command: command];
	}
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
			} else if ([parameter isKindOfClass: [OFNull class]])
				values[i++] = NULL;
			else
				values[i++] = [[parameter description]
				    UTF8String];
		} while ((parameter = va_arg(args, id)) != nil);

		result = PQexecParams(_connnection, [command UTF8String],
		    argsCount, NULL, values, NULL, NULL, 0);
	} @finally {
		[self freeMemory: values];
	}

	objc_autoreleasePoolPop(pool);








|







125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
			} else if ([parameter isKindOfClass: [OFNull class]])
				values[i++] = NULL;
			else
				values[i++] = [[parameter description]
				    UTF8String];
		} while ((parameter = va_arg(args, id)) != nil);

		result = PQexecParams(_connection, [command UTF8String],
		    argsCount, NULL, values, NULL, NULL, 0);
	} @finally {
		[self freeMemory: values];
	}

	objc_autoreleasePoolPop(pool);

190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
			values[i] = [value UTF8String];

			[command appendFormat: @"$%zd", ++i];
		}

		[command appendString: @")"];

		result = PQexecParams(_connnection, [command UTF8String],
		    (int)count, NULL, values, NULL, NULL, 0);
	} @finally {
		[self freeMemory: values];
	}

	objc_autoreleasePoolPop(pool);








|







193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
			values[i] = [value UTF8String];

			[command appendFormat: @"$%zd", ++i];
		}

		[command appendString: @")"];

		result = PQexecParams(_connection, [command UTF8String],
		    (int)count, NULL, values, NULL, NULL, 0);
	} @finally {
		[self freeMemory: values];
	}

	objc_autoreleasePoolPop(pool);

218
219
220
221
222
223
224
225
226
227
	for (OFDictionary *row in rows)
		[self insertRow: row
		      intoTable: table];
}

- (PGconn *)PG_connection
{
	return _connnection;
}
@end







|


221
222
223
224
225
226
227
228
229
230
	for (OFDictionary *row in rows)
		[self insertRow: row
		      intoTable: table];
}

- (PGconn *)PG_connection
{
	return _connection;
}
@end