| 197 | } |
| 198 | |
| 199 | int |
| 200 | main(int argc, char **argv) |
| 201 | { |
| 202 | char *in_filename, |
| 203 | *out_filename; |
| 204 | char *database; |
| 205 | Oid lobjOid; |
| 206 | PGconn *conn; |
| 207 | PGresult *res; |
| 208 | |
| 209 | if (argc != 4) |
| 210 | { |
| 211 | fprintf(stderr, "Usage: %s database_name in_filename out_filename\n", |
| 212 | argv[0]); |
| 213 | exit(1); |
| 214 | } |
| 215 | |
| 216 | database = argv[1]; |
| 217 | in_filename = argv[2]; |
| 218 | out_filename = argv[3]; |
| 219 | |
| 220 | /* |
| 221 | * set up the connection |
| 222 | */ |
| 223 | conn = PQsetdb(NULL, NULL, NULL, NULL, database); |
| 224 | |
| 225 | /* check to see that the backend connection was successfully made */ |
| 226 | if (PQstatus(conn) != CONNECTION_OK) |
| 227 | { |
| 228 | fprintf(stderr, "%s", PQerrorMessage(conn)); |
| 229 | exit_nicely(conn); |
| 230 | } |
| 231 | |
| 232 | /* Set always-secure search path, so malicious users can't take control. */ |
| 233 | res = PQexec(conn, |
| 234 | "SELECT pg_catalog.set_config('search_path', '', false)"); |
| 235 | if (PQresultStatus(res) != PGRES_TUPLES_OK) |
| 236 | { |
| 237 | fprintf(stderr, "SET failed: %s", PQerrorMessage(conn)); |
| 238 | PQclear(res); |
| 239 | exit_nicely(conn); |
| 240 | } |
| 241 | PQclear(res); |
| 242 | |
| 243 | res = PQexec(conn, "begin"); |
| 244 | PQclear(res); |
| 245 | printf("importing file \"%s\" ...\n", in_filename); |
| 246 | /* lobjOid = importFile(conn, in_filename); */ |
| 247 | lobjOid = lo_import(conn, in_filename); |
| 248 | if (lobjOid == 0) |
| 249 | fprintf(stderr, "%s\n", PQerrorMessage(conn)); |
| 250 | else |
| 251 | { |
| 252 | printf("\tas large object %u.\n", lobjOid); |
| 253 | |
| 254 | printf("picking out bytes 1000-2000 of the large object\n"); |
| 255 | pickout(conn, lobjOid, 1000, 1000); |
| 256 |
nothing calls this directly
no test coverage detected