Sybase utility library - API


class SybInt

This class is responsible for handling the interface to Sybase. Normal usage is to create an instance of this class, call connect() and useDB(), and then execute some SQL. The destructor of the class automatically disconnects from the Sybase database. All methods throw a string exception if an error occurs.

SybInt()
Class constructor. Does not attempt to connect to Sybase server.

~SybInt()
The destructor will automatically disconnect from the Sybase server if currently connected.

void connect(const string& server, const string& username, const string& password)
Connect to a Sybase server with supplied username and password. If already connected, disconnect() will be called first.

void useDB(const string& dbname)
Select a database to use

long cmdSQL(const string& sql)
Execute some SQL. The return value is not currently used. See also runSQL() below.

DTable* runSQL(const string& sql)
Execute some SQL. The results of the SQL are returned in a DTable*. Note that you get ownership of the DTable*, i.e. it is your responsibility to delete it when you have finished with it. The DTable API is described below.

int getReturnStatus()
Get the return status of the last stored procedure that was executed.

int getRowsAffected()
Get the number of rows affected by the last SQL command.

void disconnect()
Manually disconnect from the Sybase server. There is normally no need to call this method as the class destructor will disconnect automatically.


class DTable

This class was designed to hold the results of Sybase queries, although it can be used on its own to store data. Have a look at the example files in the tarball on the download page. A DTable can have an arbitrary number of rows and columns. Each column can have a name, and be designated to contain strings, ints or doubles; similar to a database table. Errors result in a string exception being thrown.

DTable()
Construct an empty DTable

~DTable()
DTable destructor

uint addRow()
Add a new row to a DTable. The return value is the index of the new row (rows are numbered from 0).

uint addColumn(DT::ColType coltype, const string& colname="")
Add a new column to a DTable to contain items of type coltype. Valid column types are DT::STR, DT::INT, DT::DBL; for STL string, integer and double respectively. The return value is the index of the new column (columns are numbered from 0).

string colName(uint column) const
Returns the name of column with index column.

uint colNum(const string& name) const
Returns the index of column with name name.

DT::ColType colType(uint column) const
Returns the type of data stored in column with index column.

void clear()
Delete all columns in DTable.

uint rows() const
Return number of rows in DTable.

uint columns() const
Return number of columns in DTable.

string asText() const
Return contents of DTable as a string. Lines are separated with '\n', columns are separated with tab.

string asHTML() const
Return contents of DTable as a string, formatted as an HTML table.

string getString(uint col, uint row) const
Return the string stored in column col and row row. If this is not a string column, the result will be converted to a string.

int getInt(uint col, uint row) const
Return the integer stored in column col and row row. If this is not an integer column, an exception is thrown.

double getDouble(uint col, uint row) const
Return the double stored in column col and row row. If this is not a double column, an exception is thrown.

string getString(const string& colname, uint row) const
int getInt(const string& colname, uint row) const
double getDouble(const string& colname, uint row) const
The above three methods are identical to the previous three, except the column is specified by name instead of index.

void setString(uint col, uint row, const string& s)
Set the string stored in column col and row row to s. If this is not a string column, an attempt will be made to convert the string s into an integer/double.

void setInt(uint col, uint row, int i)
Set the integer stored in column col and row row to i. If this is not an integer column, an exception is thrown.

void setDouble(uint col, uint row, double d)
Set the double stored in column col and row row to d. If this is not a double column, an exception is thrown.