Sybase utility library - Example program


#include <iostream>
#include <memory>

#include "dtable.h"
#include "sybint.h"

int main(int, char**)
{
	try {
		SybInt si;
		si.connect("SYBASE", "sa", "secret");
		si.useDB("pubs2");

		// List tables in database pubs2
		std::auto_ptr<DTable> dt(si.runSQL(
			"select o.name 'table name', "
			"(select max(colid) from syscolumns where id = o.id) 'num columns' "
			"from sysobjects o "
			"where type = 'U'"));
		std::cout << dt->asHTML();

		return 0;
	}
	catch (const std::string& s) {
		std::cerr << s;
	}
}

And here is the output from running the program:
table namenum columns
authors9
publishers4
roysched4
sales3
salesdetail5
titleauthor4
titles10
stores8
discounts5
au_pix6
blurbs2


Notes:
The SybInt object will automatically close the Sybase connection when it destructs.
The library returns quite verbose error messages, including any SQL that was executed, so it is not always necessary to put separate try/catch blocks around each database call.