#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 name | num columns |
---|---|
authors | 9 |
publishers | 4 |
roysched | 4 |
sales | 3 |
salesdetail | 5 |
titleauthor | 4 |
titles | 10 |
stores | 8 |
discounts | 5 |
au_pix | 6 |
blurbs | 2 |
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.