Differences From Artifact [5e7a8f6854]:
- File src/PGConnection.m — part of check-in [e4c8de38e0] at 2024-08-11 17:45:27 on branch trunk — Add documentation (user: js, size: 4500) [annotate] [blame] [check-ins using]
To Artifact [40b1a4989d]:
- File
src/PGSQLConnection.m
— part of check-in
[77c26b4fce]
at
2024-08-11 18:00:52
on branch trunk
— Change prefix to PGSQL
Two letter prefixes are too risky to cause collisions. (user: js, size: 4548) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
12 13 14 15 16 17 18 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ | | | | | | | | | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ #import "PGSQLConnection.h" #import "PGSQLConnection+Private.h" #import "PGSQLResult.h" #import "PGSQLResult+Private.h" #import "PGSQLConnectionFailedException.h" #import "PGSQLExecuteCommandFailedException.h" @implementation PGSQLConnection @synthesize pg_connection = _connection, parameters = _parameters; - (instancetype)init { self = [super init]; @try { |
︙ | ︙ | |||
69 70 71 72 73 74 75 | @"%@=%@", key, object]; } if ((_connection = PQconnectdb(connectionInfo.UTF8String)) == NULL) @throw [OFOutOfMemoryException exception]; if (PQstatus(_connection) == CONNECTION_BAD) | | | | | | | | | 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | @"%@=%@", key, object]; } if ((_connection = PQconnectdb(connectionInfo.UTF8String)) == NULL) @throw [OFOutOfMemoryException exception]; if (PQstatus(_connection) == CONNECTION_BAD) @throw [PGSQLConnectionFailedException exceptionWithConnection: self]; objc_autoreleasePoolPop(pool); } - (void)reset { PQreset(_connection); } - (void)close { if (_connection != NULL) PQfinish(_connection); _connection = NULL; } - (PGSQLResult *)executeCommand: (OFConstantString *)command { PGresult *result = PQexec(_connection, command.UTF8String); if (PQresultStatus(result) == PGRES_FATAL_ERROR) { PQclear(result); @throw [PGSQLExecuteCommandFailedException exceptionWithConnection: self command: command]; } switch (PQresultStatus(result)) { case PGRES_TUPLES_OK: return [PGSQLResult pg_resultWithResult: result]; case PGRES_COMMAND_OK: PQclear(result); return nil; default: PQclear(result); @throw [PGSQLExecuteCommandFailedException exceptionWithConnection: self command: command]; } } - (PGSQLResult *)executeCommand: (OFConstantString *)command parameters: (id)parameter, ... { void *pool = objc_autoreleasePoolPush(); PGresult *result; const char **values; va_list args, args2; int argsCount; |
︙ | ︙ | |||
163 164 165 166 167 168 169 | OFFreeMemory(values); } objc_autoreleasePoolPop(pool); switch (PQresultStatus(result)) { case PGRES_TUPLES_OK: | | | | 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | OFFreeMemory(values); } objc_autoreleasePoolPop(pool); switch (PQresultStatus(result)) { case PGRES_TUPLES_OK: return [PGSQLResult pg_resultWithResult: result]; case PGRES_COMMAND_OK: PQclear(result); return nil; default: PQclear(result); @throw [PGSQLExecuteCommandFailedException exceptionWithConnection: self command: command]; } } @end |