Index: src/PGConnection.h ================================================================== --- src/PGConnection.h +++ src/PGConnection.h @@ -39,11 +39,8 @@ - (void)reset; - (void)close; - (nullable PGResult *)executeCommand: (OFConstantString *)command; - (nullable PGResult *)executeCommand: (OFConstantString *)command parameters: (id)firstParameter, ... OF_SENTINEL; -- (void)insertRow: (PGRow)row intoTable: (OFString *)table; -- (void)insertRows: (OFArray OF_GENERIC(PGRow) *)rows - intoTable: (OFString *)table; @end OF_ASSUME_NONNULL_END Index: src/PGConnection.m ================================================================== --- src/PGConnection.m +++ src/PGConnection.m @@ -162,75 +162,6 @@ @throw [PGCommandFailedException exceptionWithConnection: self command: command]; } } - -- (void)insertRow: (PGRow)row intoTable: (OFString *)table -{ - void *pool = objc_autoreleasePoolPush(); - 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 = OFAllocMemory(count, sizeof(*values)); - @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(_connection, command.UTF8String, - (int)count, NULL, values, NULL, NULL, 0); - } @finally { - OFFreeMemory(values); - } - - objc_autoreleasePoolPop(pool); - - if (PQresultStatus(result) != PGRES_COMMAND_OK) { - PQclear(result); - @throw [PGCommandFailedException - exceptionWithConnection: self - command: command]; - } - - PQclear(result); -} - -- (void)insertRows: (OFArray OF_GENERIC(PGRow) *)rows - intoTable: (OFString *)table -{ - for (OFDictionary *row in rows) - [self insertRow: row intoTable: table]; -} @end Index: tests/Tests.m ================================================================== --- tests/Tests.m +++ tests/Tests.m @@ -57,13 +57,10 @@ [_connection executeCommand: @"INSERT INTO test (id, content, success) " @"VALUES ($1, $2, $3)" parameters: [OFNumber numberWithInt: 2], [OFNumber numberWithInt: 2], [OFNumber numberWithBool: true], nil]; - [_connection insertRow: [OFDictionary dictionaryWithKeysAndObjects: - @"content", @"Hallo!", @"name", @"foo", nil] - intoTable: @"test"]; result = [_connection executeCommand: @"SELECT * FROM test"]; OFLog(@"%@", result); OFLog(@"JSON: %@", [result JSONRepresentation]);