Database Reference
In-Depth Information
You will now be shown the irst part of the code examples we were referring to.
In the imp_exp.c example, we irst connected to the PostgreSQL database; after
a successful connection, we imported the imp.jpg ile into the database using
lo_import , and then we exported it as exp.jpg from the database using the OID
returned in lo_export . How to connect and play with the PostgreSQL database
through libpq is explained in detail later in the chapter. So for now, you need not be
worried of how things are working here. As said earlier, to grasp it irmly, revisit the
code examples after reading the next chapter.
The irst part of the code example is as follows:
/*----------------------------------------------------------------
*
*imp_exp.c
*Accessing large objects using lo_export and lo_import
*
*IDENTIFICATION
*imp_exp.c
*
*----------------------------------------------------------------
*/
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
#include <limits.h>
#include "libpq-fe.h"
#include "libpq/libpq-fs.h"
#define FILE_TO_EXPORT "exp.jpg"
#define FILE_TO_IMPORT "imp.jpg"
int main(int argc, char **argv)
{
PGconn *conn;
PGresult *res;
int lo_oid;
/* Connect to Database testdb */
conn = PQsetdb(NULL, NULL, NULL, NULL, "testdb");
if (PQstatus(conn) == CONNECTION_BAD)
{
fprintf(stderr, "connection to database failed\n");
fprintf(stderr, "%s", PQerrorMessage(conn));
return -1;
}
 
Search WWH ::




Custom Search