コード例 #1
0
int main(int argc, char *argv[])
{
    DBHelper db;

    if (argc != 3) {
        std::string program_name = boost::regex_replace(std::string(argv[0]), boost::regex(".*/"), "");
        std::cerr << "Usage: " << program_name << " dsn query" << std::endl;
        return 1;
    }
    std::string dsn(argv[1]);
    std::string query(argv[2]);

    try
    {
        db.connect(dsn);

        cout << db.executeQuery(query) << endl;

        int num = db.numResultCols();
        cout << "Search Result has " << num << " columns" << endl;
        num = db.rowCount();
        cout << "Search Result has " << num << " rows" << endl;

        cout << db.describeColumn(1) << endl;
        ResultColumnPtr col1(new CharResultColumn(1024));

        cout << db.describeColumn(2) << endl;
        ResultColumnPtr col2(new CharResultColumn(1024));

        db.setStmtAttr(SQL_ROWSET_SIZE, (SQLPOINTER) 2, -6);
    
        cout << "pre fetch" << endl;
        while (db.fetch())
        {
            db.getData(1, col1);
            db.getData(2, col2);
            cout << col1 << "    ";
            cout << col2 << endl;
        }

        db.disconnect();
    }
    catch (std::exception& e)
    {
        cout << e.what() << endl;
    }
}
コード例 #2
0
int main()
{
    DBHelper db;

    try
    {
        db.connect("retstest");

        string query("SELECT ListingID,ListDate");
        query.append("  FROM data:Property:RES");
        query.append(" WHERE ListPrice > 0");

        cout << db.executeQuery(query) << endl;

        int num = db.numResultCols();
        cout << "Search Result has " << num << " columns" << endl;
        num = db.rowCount();
        cout << "Search Result has " << num << " rows" << endl;

        cout << db.describeColumn(1) << endl;

        ResultColumnPtr col1(new CharResultColumn(1024));
        db.bindColumn(1, col1);

        cout << db.describeColumn(2) << endl;

        ResultColumnPtr col2(new TimestampResultColumn());
        db.bindColumn(2, col2);
    
        cout << "pre fetch" << endl;
        while (db.fetch())
        {
            cout << col1 << "    ";
            cout << col2 << endl;
        }

        db.disconnect();
    }
    catch (std::exception& e)
    {
        cout << e.what() << endl;
    }
}
コード例 #3
0
int main()
{
    DBHelper db;
    try
    {

        db.connect("retstest");

        string query("SELECT *");
        query.append("  FROM data:Property:ResidentialProperty");

        cout << db.executeQuery(query) << endl;

        SQLSMALLINT numcol = db.numResultCols();
        cout << "Search Result has " << numcol << " columns" << endl;

        for (int i = 1 ; i <= numcol; i++)
        {
            cout << db.describeColumn(i) << endl;
        }
    
        if (db.fetch())
        {
            cout << "There was data, how can this be?" << endl;
        }
        else
        {
            cout << "No data as expected" << endl;
        }

        db.disconnect();
    }
    catch (std::exception& e)
    {
        cout << e.what() << endl;
    }
}