Chapter 10. The PostgreSQL C++ API ”libpq++You can build PostgreSQL client applications using a variety of programming languages. In Chapter 8, "The PostgreSQL C API ”libpq (Client Applications)," and Chapter 9, "A Simpler C API ”libpgeasy," you looked at two of the APIs that you can conveniently use from a C program (libpq and libpgeasy). This chapter introduces you to the libpq++ API. libpq++ is an API designed for use from within a C++ client application. To demonstrate the capabilities provided by libpq++, you'll build a number of client applications in this chapter:
I mentioned in the previous chapter that the libpgeasy API is a wrapper around libpq. The same is true for libpq++ ”libpq++ is implemented using libpq. When you use the libpq or libpgeasy APIs, you use a collection of data types ( PGresult * , PGconn * , and so on) and functions ( PQconnectdb() , PQexec() , and so on) to perform server operations and obtain results. In contrast, when you use the libpq++ API, you use a small collection of classes. The difference between the two approaches can affect the way you think about solving a particular problem. In a function+data type architecture (such as libpq or libpgeasy), you are working with data types that are somewhat independent from the functions that operate on those types. When you use a class- (or more precisely object-) oriented architecture, you define a set of classes that contain both state and behavior. An object is an instance of a class. Its data members represent the state of an object and the behavior is supplied by its member functions [1] .
|