public
Description: A simple Nu/Objective-C interface to PostgreSQL databases.
Homepage: http://programming.nu
Clone URL: git://github.com/timburks/nupostgresql.git
Cache prepared queries for reuse.
timburks (author)
Thu Aug 14 23:00:42 -0700 2008
commit  af2368094754c5813344c2cb4693454d5c6fc184
tree    dc3e130d517a2c9c9981a20a34c46d6689de50b1
parent  d287cbd4a1ac4d670532948e1459382b5380888e
...
174
175
176
 
177
178
179
...
198
199
200
 
201
202
203
204
205
206
 
207
208
209
...
254
255
256
257
258
 
 
 
 
 
 
 
 
 
 
 
259
260
261
...
268
269
270
271
 
272
273
274
...
174
175
176
177
178
179
180
...
199
200
201
202
203
204
205
206
207
208
209
210
211
212
...
257
258
259
 
 
260
261
262
263
264
265
266
267
268
269
270
271
272
273
...
280
281
282
 
283
284
285
286
0
@@ -174,6 +174,7 @@ const char *nameOfType(enum ECPGttype code)
0
 {
0
     PGconn *connection;
0
     NSMutableDictionary *connectionInfo;
0
+ NSMutableSet *queries;
0
 }
0
 
0
 @end
0
@@ -198,12 +199,14 @@ void notice_processor(void *arg, const char *message)
0
 {
0
     [super init];
0
     connectionInfo = [[NSMutableDictionary alloc] init];
0
+ queries = [[NSMutableSet alloc] init];
0
     return self;
0
 }
0
 
0
 - (void) dealloc
0
 {
0
     [connectionInfo release];
0
+ [queries release];
0
     [super dealloc];
0
 }
0
 
0
@@ -254,8 +257,17 @@ void notice_processor(void *arg, const char *message)
0
         NSLog(@"There is no connection to a database.");
0
         return nil;
0
     }
0
- PGresult *preparationResult = PQprepare(connection, "", [query cStringUsingEncoding:NSUTF8StringEncoding], 0, 0);
0
- PGresult *descriptionResult = PQdescribePrepared(connection, "");
0
+ const char *cquery = [query cStringUsingEncoding:NSUTF8StringEncoding];
0
+ if (![queries containsObject:query]) {
0
+ PGresult *preparationResult = PQprepare(connection, cquery, cquery, 0, 0);
0
+ [queries addObject:query];
0
+ }
0
+ /*
0
+ else {
0
+ NSLog(@"reusing query %@", query);
0
+ }
0
+ */
0
+ //PGresult *descriptionResult = PQdescribePrepared(connection, cquery);
0
     /*
0
     NSLog(@"prepared query expects %d arguments", PQnparams(descriptionResult));
0
     for (int i = 0; i < PQnparams(descriptionResult); i++) {
0
@@ -268,7 +280,7 @@ void notice_processor(void *arg, const char *message)
0
         NSString *stringValue = [[arguments objectAtIndex:i] stringValue];
0
         paramValues[i] = strdup([stringValue cStringUsingEncoding:NSUTF8StringEncoding]);
0
     }
0
- PGresult *result = PQexecPrepared(connection, "", paramCount, (const char **) paramValues, 0, 0, 0);
0
+ PGresult *result = PQexecPrepared(connection, cquery, paramCount, (const char **) paramValues, 0, 0, 0);
0
     for (int i = 0; i < paramCount; i++) {
0
         free(paramValues[i]);
0
     }

Comments

    No one has commented yet.