Overview
Comment: | Add -[insertRows:intoTable:]. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
7b335b3af81d4506f284274867154107 |
User & Date: | js 2012-10-06 21:02:02 |
Context
2012-10-07
| ||
22:45 | Convert types using the result of PQftypes(). check-in: 4a2b1fff7e user: js tags: trunk | |
2012-10-06
| ||
21:02 | Add -[insertRows:intoTable:]. check-in: 7b335b3af8 user: js tags: trunk | |
2012-10-05
| ||
21:26 | Install all headers into one place. check-in: 86adc6aab9 user: js tags: trunk | |
Changes
Changes to ObjPgSQL.xcodeproj/project.pbxproj.
︙ | |||
17 18 19 20 21 22 23 | 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 52 53 54 55 56 57 58 59 60 | - + - + + - | 4BCC744B161F82560074ED30 /* PGResultRow.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BCC7444161F82560074ED30 /* PGResultRow.m */; }; 4BCC7453161F82820074ED30 /* PGCommandFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BCC744D161F82820074ED30 /* PGCommandFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4BCC7454161F82820074ED30 /* PGCommandFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BCC744E161F82820074ED30 /* PGCommandFailedException.m */; }; 4BCC7455161F82820074ED30 /* PGConnectionFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BCC744F161F82820074ED30 /* PGConnectionFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4BCC7456161F82820074ED30 /* PGConnectionFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BCC7450161F82820074ED30 /* PGConnectionFailedException.m */; }; 4BCC7457161F82820074ED30 /* PGException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BCC7451161F82820074ED30 /* PGException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4BCC7458161F82820074ED30 /* PGException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BCC7452161F82820074ED30 /* PGException.m */; }; |
︙ | |||
111 112 113 114 115 116 117 | 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | - + | ); name = Exceptions; sourceTree = "<group>"; }; 4BCC7461161F843F0074ED30 /* Libraries */ = { isa = PBXGroup; children = ( |
︙ | |||
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | + + + + + + + + | buildSettings = { COMBINE_HIDPI_IMAGES = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; FRAMEWORK_VERSION = A; GCC_PRECOMPILE_PREFIX_HEADER = NO; INFOPLIST_FILE = Info.plist; LIBRARY_SEARCH_PATHS = ( "$(inherited)", /usr/local/lib, ); PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = framework; }; name = Debug; }; 4BCC743B161F81760074ED30 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { COMBINE_HIDPI_IMAGES = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; FRAMEWORK_VERSION = A; GCC_PRECOMPILE_PREFIX_HEADER = NO; INFOPLIST_FILE = Info.plist; LIBRARY_SEARCH_PATHS = ( "$(inherited)", /usr/local/lib, ); PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = framework; }; name = Release; }; /* End XCBuildConfiguration section */ |
︙ |
Changes to PGConnection.h.
︙ | |||
18 19 20 21 22 23 24 25 | 18 19 20 21 22 23 24 25 26 27 28 29 | + + + + | - (OFDictionary*)parameters; - (void)connect; - (void)reset; - (PGResult*)executeCommand: (OFString*)command; - (PGResult*)executeCommand: (OFString*)command parameters: (id)firstParameter, ...; - (PGconn*)PG_connection; - (void)insertRow: (OFDictionary*)row intoTable: (OFString*)table; - (void)insertRows: (OFArray*)rows intoTable: (OFString*)table; @end |
Changes to PGConnection.m.
︙ | |||
121 122 123 124 125 126 127 128 129 130 131 132 133 | 121 122 123 124 125 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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | if (PQresultStatus(result) == PGRES_TUPLES_OK) return [PGResult PG_resultWithResult: result]; PQclear(result); return nil; } - (void)insertRow: (OFDictionary*)row intoTable: (OFString*)table { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFMutableString *command; OFEnumerator *enumerator; const char **values; PGresult *result; OFString *key, *value; size_t i, count; command = [OFMutableString stringWithString: @"INSERT INTO "]; [command appendString: table]; [command appendString: @" ("]; count = [row count]; i = 0; enumerator = [row keyEnumerator]; while ((key = [enumerator nextObject]) != nil) { if (i > 0) [command appendString: @", "]; [command appendString: key]; i++; } [command appendString: @") VALUES ("]; values = [self allocMemoryWithSize: sizeof(*values) count: count]; @try { i = 0; enumerator = [row objectEnumerator]; while ((value = [enumerator nextObject]) != nil) { if (i > 0) [command appendString: @", "]; values[i] = [value UTF8String]; [command appendFormat: @"$%zd", ++i]; } [command appendString: @")"]; result = PQexecParams(conn, [command UTF8String], (int)count, NULL, values, NULL, NULL, 0); } @finally { [self freeMemory: values]; } [pool release]; if (PQresultStatus(result) != PGRES_COMMAND_OK) { PQclear(result); @throw [PGCommandFailedException exceptionWithClass: [self class] connection: self command: command]; } PQclear(result); } - (void)insertRows: (OFArray*)rows intoTable: (OFString*)table { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFEnumerator *enumerator = [rows objectEnumerator]; OFDictionary *row; while ((row = [enumerator nextObject]) != nil) [self insertRow: row intoTable: table]; [pool release]; } - (PGconn*)PG_connection { return conn; } @end |
Changes to test.m.
︙ | |||
30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | + + | @")"]; [connection executeCommand: @"INSERT INTO test (id, name, content) " @"VALUES($1, $2, $3)" parameters: @"1", @"foo", @"Hallo Welt!", nil]; [connection executeCommand: @"INSERT INTO test (id, content) " @"VALUES($1, $2)" parameters: @"2", @"Blup!!", nil]; [connection insertRow: @{ @"content": @"Hallo!", @"name": @"foo" } intoTable: @"test"]; result = [connection executeCommand: @"SELECT * FROM test"]; of_log(@"%@", result); of_log(@"JSON: %@", [result JSONRepresentation]); result = [connection executeCommand: @"SELECT COUNT(*) FROM test"]; of_log(@"%@", result); |
︙ |