// Collection of code snippets by Arne VajhÃ¸j 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
#include <iostream>

using namespace std;

#include "sqlplus.hh"

int main()
{
    try
    {
        //
        // åben connection til:
        //   database = "Test"
        //   server = "localhost"
        //   username = "root"
        //   password = ""
        //
        Connection con("Test", "localhost", "root", "");
        // udfør query
        Query q = con.query(); 
        q << "SELECT * FROM t1";
        Result res = q.store(); 
        // print resultat af query
        for (Result::iterator it = res.begin(); it != res.end(); it++)
        {
            Row r = *it;
            for(int i = 0; i < res.columns(); i++)
            {
                cout << " " << (!r[i].is_null() ? r[i] : "NULL"); 
            }
            cout << endl;
        }
    }
    catch(BadQuery er)
    {
        cerr << "MySQL error: " << er.error << endl;
    }
    return 0;
}
