ObjPgSQL  Check-in [fc8e42990e]

Overview
Comment:Adjust to recent ObjFW changes
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: fc8e42990e7f6476b8b806521222620bbac0496c61a91b20f9e3787fc20fdbb4
User & Date: js on 2017-05-09 23:19:20
Other Links: manifest | tags
Context
2017-05-10
23:46
Move private methods to separate headers check-in: 6307a38198 user: js tags: trunk
2017-05-09
23:19
Adjust to recent ObjFW changes check-in: fc8e42990e user: js tags: trunk
2017-01-22
04:47
Adjust to ObjFW changes check-in: 959a1e5652 user: js tags: trunk
Changes

Modified src/PGConnection.h from [68ece51d08] to [89f43193e6].

1
2
3
4
5


6
7
8
9
10

11
12
13


14
15
16
17
18
19
20
21
22
23
24

25
26


1
2
3
4
5
6
7
8
9
10
11

12
13
14

15
16
17
18
19
20
21
22
23
24
25
26

27
28
29
30
31





+
+




-
+


-
+
+










-
+


+
+
#include <libpq-fe.h>

#import <ObjFW/ObjFW.h>

#import "PGResult.h"

OF_ASSUME_NONNULL_BEGIN

@interface PGConnection: OFObject
{
	PGconn *_connnection;
	OFDictionary *_parameters;
	OFDictionary OF_GENERIC(OFString *, OFString *) *_parameters;
}

@property (copy) OFDictionary *parameters;
@property (nonatomic, copy)
    OFDictionary OF_GENERIC(OFString *, OFString *) *parameters;

- (void)connect;
- (void)reset;
- (void)close;
- (PGResult*)executeCommand: (OFConstantString*)command;
- (PGResult*)executeCommand: (OFConstantString*)command
		 parameters: (id)firstParameter, ... OF_SENTINEL;
- (PGconn*)PG_connection;
- (void)insertRow: (OFDictionary*)row
	intoTable: (OFString*)table;
- (void)insertRows: (OFArray*)rows
- (void)insertRows: (OFArray OF_GENERIC(OFDictionary *) *)rows
	 intoTable: (OFString*)table;
@end

OF_ASSUME_NONNULL_END

Modified src/PGConnection.m from [66118a42be] to [12a5dca2c4].

13
14
15
16
17
18
19
20
21
22





23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

43
44
45
46
47
48
49
13
14
15
16
17
18
19



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51







-
-
-
+
+
+
+
+



















-
+







	[self close];

	[super dealloc];
}

- (void)connect
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFEnumerator *keyEnumerator = [_parameters keyEnumerator];
	OFEnumerator *objectEnumerator = [_parameters objectEnumerator];
	void *pool = objc_autoreleasePoolPush();
	OFEnumerator OF_GENERIC(OFString *) *keyEnumerator =
	    [_parameters keyEnumerator];
	OFEnumerator OF_GENERIC(OFString *) *objectEnumerator =
	    [_parameters objectEnumerator];
	OFMutableString *connectionInfo = nil;
	OFString *key, *object;

	while ((key = [keyEnumerator nextObject]) != nil &&
	    (object = [objectEnumerator nextObject]) != nil) {
		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];

	[pool release];
	objc_autoreleasePoolPop(pool);
}

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

79
80
81
82
83
84
85
86

87
88
89
90
91
92
93
81
82
83
84
85
86
87

88
89
90
91
92
93
94
95







-
+







				    command: command];
	}
}

- (PGResult*)executeCommand: (OFConstantString*)command
		 parameters: (id)parameter, ...
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	void *pool = objc_autoreleasePoolPush();
	PGresult *result;
	const char **values;
	va_list args, args2;
	int argsCount;

	va_start(args, parameter);
	va_copy(args2, args);
126
127
128
129
130
131
132
133

134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152

153
154
155
156
157
158
159
128
129
130
131
132
133
134

135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153

154
155
156
157
158
159
160
161







-
+


















-
+








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

	[pool release];
	objc_autoreleasePoolPop(pool);

	switch (PQresultStatus(result)) {
	case PGRES_TUPLES_OK:
		return [PGResult PG_resultWithResult: result];
	case PGRES_COMMAND_OK:
		PQclear(result);
		return nil;
	default:
		PQclear(result);
		@throw [PGCommandFailedException
		    exceptionWithConnection: self
				    command: command];
	}
}

- (void)insertRow: (OFDictionary*)row
	intoTable: (OFString*)table
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	void *pool = objc_autoreleasePoolPush();
	OFMutableString *command;
	OFEnumerator *enumerator;
	const char **values;
	PGresult *result;
	OFString *key, *value;
	size_t i, count;

194
195
196
197
198
199
200
201

202
203
204
205
206
207
208
209
210
211
212
213

214
215
216
217
218

219
220
221
222
223
224
225
226
227
228
229
230
231
196
197
198
199
200
201
202

203
204
205
206
207
208
209
210
211
212
213
214

215
216
217



218


219
220


221
222
223
224
225
226
227







-
+











-
+


-
-
-
+
-
-


-
-








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

	[pool release];
	objc_autoreleasePoolPop(pool);

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

	PQclear(result);
}

- (void)insertRows: (OFArray*)rows
- (void)insertRows: (OFArray OF_GENERIC(OFDictionary *) *)rows
	 intoTable: (OFString*)table
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFEnumerator *enumerator = [rows objectEnumerator];
	OFDictionary *row;
	for (OFDictionary *row in rows)

	while ((row = [enumerator nextObject]) != nil)
		[self insertRow: row
		      intoTable: table];

	[pool release];
}

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

Modified src/PGResult.h from [6294089c40] to [b70e0a8f15].

1
2
3
4




5

6
7
8
9
10
11


12
13


1
2
3
4
5
6
7
8

9
10
11
12
13


14
15
16
17
18
19




+
+
+
+
-
+




-
-
+
+


+
+
#include <libpq-fe.h>

#import <ObjFW/ObjFW.h>

OF_ASSUME_NONNULL_BEGIN

@class PGResultRow;

@interface PGResult: OFArray
@interface PGResult: OFArray OF_GENERIC(PGResultRow *)
{
	PGresult *_result;
}

+ PG_resultWithResult: (PGresult*)result;
- PG_initWithResult: (PGresult*)result;
+ (instancetype)PG_resultWithResult: (PGresult *)result;
- PG_initWithResult: (PGresult *)result OF_METHOD_FAMILY(init);
- (PGresult*)PG_result;
@end

OF_ASSUME_NONNULL_END

Modified src/PGResult.m from [a066a8eda5] to [1b1566e654].

whitespace changes only

Modified src/PGResultRow.h from [f714b4a0e3] to [4c4b6ee6a8].

1
2
3
4
5


6
7
8
9
10
11
12
13
14
15
16
17
18


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22





+
+













+
+
#include <libpq-fe.h>

#import <ObjFW/ObjFW.h>

#import "PGResult.h"

OF_ASSUME_NONNULL_BEGIN

@interface PGResultRow: OFDictionary
{
	PGResult *_result;
	PGresult *_res;
	int _row;
}

+ rowWithResult: (PGResult*)result
	    row: (int)row;
- initWithResult: (PGResult*)result
	     row: (int)row;
@end

OF_ASSUME_NONNULL_END

Modified src/PGResultRow.m from [1fee8156f8] to [2a3cc24231].

whitespace changes only

Modified src/exceptions/PGCommandFailedException.h from [c0757cbfd8] to [aa497f3805].

1


2
3
4
5
6
7
8

9
10
11
12
13
14


1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18

+
+






-
+






+
+
#import "PGException.h"

OF_ASSUME_NONNULL_BEGIN

@interface PGCommandFailedException: PGException
{
	OFString *_command;
}

@property (readonly, copy) OFString *command;
@property (readonly, nonatomic) OFString *command;

+ (instancetype)exceptionWithConnection: (PGConnection*)connection
				command: (OFString*)command;
- initWithConnection: (PGConnection*)connection
	     command: (OFString*)command;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/PGCommandFailedException.m from [7e22faf8ff] to [39366017cc].

whitespace changes only

Modified src/exceptions/PGConnectionFailedException.h from [bfb4590c76] to [57af5c1f34].

1


2
3
4


1
2
3
4
5
6
7
8

+
+



+
+
#import "PGException.h"

OF_ASSUME_NONNULL_BEGIN

@interface PGConnectionFailedException: PGException
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/PGConnectionFailedException.m from [b1115b7f5a] to [386de510d2].

whitespace changes only

Modified src/exceptions/PGException.h from [f5eecc1954] to [5ee22db605].

1
2
3


4
5
6
7
8
9
10
11

12
13
14
15


1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19



+
+







-
+




+
+
#import <ObjFW/ObjFW.h>

#import "PGConnection.h"

OF_ASSUME_NONNULL_BEGIN

@interface PGException: OFException
{
	PGConnection *_connection;
	OFString *_error;
}

@property (readonly, retain) PGConnection *connection;
@property (readonly, nonatomic) PGConnection *connection;

+ (instancetype)exceptionWithConnection: (PGConnection*)connection;
- initWithConnection: (PGConnection*)connection;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/PGException.m from [0be804aea6] to [f39a379181].

whitespace changes only