All pastes #141495 Raw Edit

Stuff

public text v1 · immutable
#141495 ·published 2006-08-21 00:19 UTC
rendered paste body
#include "util.h"

#include <mysql++.h>

#include <iostream>
#include <iomanip>

using namespace std;

int
main(int argc, char *argv[])
{
    // Connect to the sample database.
    mysqlpp::Connection con(false);
    if (!connect_to_db(argc, argv, con)) {
        return 1;
    }

    // Retrieve a subset of the sample stock table set up by resetdb
    mysqlpp::Query query = con.query();
    query << "select item from stock";
    mysqlpp::Result res = query.store();

    // Display the result set
    cout << "We have:" << endl;
    if (res) {
        char buf[100];
        mysqlpp::Row row;
        mysqlpp::Row::size_type i;
        for (i = 0; row = res.at(i); ++i) {
            cout << '\t' << utf8trans(row.at(0), buf, sizeof(buf)) << endl;
        }
    }
    else {
        cerr << "Failed to get item list: " << query.error() << endl;
        return 1;
    }

    return 0;
}