Remove -[PGConnection insertRow:]

It can be used in a way that leads to security issues, so it's better
not to have it at all.

FossilOrigin-Name: 30633656b050a8f3f41989bed97bb200a0a583bd47e69fd36f2ae450c4bad606
This commit is contained in:
Jonathan Schleifer 2024-08-11 17:22:05 +00:00
parent 8929ac1bbb
commit 7a728f9bd3
3 changed files with 0 additions and 75 deletions

View file

@ -41,9 +41,6 @@ typedef OFDictionary OF_GENERIC(OFString *, id) *PGRow;
- (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

View file

@ -164,73 +164,4 @@
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