ROSE
0.9.6a
|
In-memory representation of a database table. More...
#include <SqlDatabase.h>
Classes | |
struct | Renderers |
Functors for rendering column values. More... | |
struct | Tuple |
One row of a table. More... | |
Public Types | |
enum | { MAXCOLS =16 } |
typedef std::vector< Tuple > | Rows |
All rows of a table. More... | |
Public Member Functions | |
Table () | |
Creates a new, empty table. More... | |
Table (const StatementPtr &stmt) | |
Creates a new table and initializes it by running the specified database query. More... | |
size_t | size () const |
Return the number of rows in the table. More... | |
bool | empty () const |
Returns true if table has no rows. More... | |
void | clear () |
Clear the table by removing all rows. More... | |
void | insert (const StatementPtr &stmt) |
Insert more rows into a table by running the specified query. More... | |
template<typename T > | |
std::string | render (const Renderer< T > *r, const T &value, size_t width=0) const |
Render a single value. More... | |
std::vector< size_t > | colsizes () const |
Compute column widths. More... | |
void | print_headers (std::ostream &out, const std::vector< size_t > &widths) const |
Print the headers for a table. More... | |
void | print_rowsep (std::ostream &out, const std::vector< size_t > &widths) const |
Print the row separator that goes between the headers and the data. More... | |
void | print_row (std::ostream &out, const Tuple &t, const std::vector< size_t > &widths) const |
Print one row of a table. More... | |
void | print (std::ostream &out) const |
Print all rows of the table to the specified stream. More... | |
void | header (int colnum, const std::string &hdr) |
Headers to use when printing the table. More... | |
const std::string & | header (int colnum) const |
Headers to use when printing the table. More... | |
void | headers (const std::string &h0, const std::string &h1="", const std::string &h2="", const std::string &h3="", const std::string &h4="", const std::string &h5="", const std::string &h6="", const std::string &h7="", const std::string &h8="", const std::string &h9="", const std::string &h10="", const std::string &h11="", const std::string &h12="", const std::string &h13="", const std::string &h14="", const std::string &h15="") |
Headers to use when printing the table. More... | |
void | reprint_headers (size_t nrows) |
How often should headers be reprinted? More... | |
size_t | reprint_headers () const |
How often should headers be reprinted? More... | |
Renderers & | renderers () |
Accessor for value renderers. More... | |
const Renderers & | renderers () const |
Accessor for value renderers. More... | |
void | prepost (PrePostRow< Table > *pre, PrePostRow< Table > *post) |
Accessor for functors called before and after each row is printed. More... | |
std::pair< PrePostRow< Table > *, PrePostRow< Table > * > | prepost () const |
Accessor for functors called before and after each row is printed. More... | |
Tuple & | operator[] (size_t i) |
Return a reference to a particular row. More... | |
const Tuple & | operator[] (size_t i) const |
Return a reference to a particular row. More... | |
void | insert (const Tuple &tuple) |
Add a new row to the end of the table. More... | |
void | insert (const T00 &v00, const T01 &v01=T01(), const T02 &v02=T02(), const T03 &v03=T03(), const T04 &v04=T04(), const T05 &v05=T05(), const T06 &v06=T06(), const T07 &v07=T07(), const T08 &v08=T08(), const T09 &v09=T09(), const T10 &v10=T10(), const T11 &v11=T11(), const T12 &v12=T12(), const T13 &v13=T13(), const T14 &v14=T14(), const T15 &v15=T15()) |
Add a new row to the end of the table. More... | |
void | line_prefix (const std::string &s) |
String to print at the beginning of every line of output. More... | |
const std::string & | line_prefix () const |
String to print at the beginning of every line of output. More... | |
Private Attributes | |
std::vector< std::string > | headers_ |
Renderers | render_ |
Rows | rows_ |
std::string | colsep_ |
PrePostRow< Table > * | pre_row_ |
PrePostRow< Table > * | post_row_ |
size_t | reprint_headers_ |
std::string | prefix_ |
In-memory representation of a database table.
These can be used to hold results of a database table, to build a table in memory, or (mostly) for printing a table in an easy-to-read format. For instance, here's a very simple, no-frills way to print the results from a query:
Tables can also be used to operate on the results of a query. For instance, to calculate the average number of instructions and bytes per function, one could use a counting-loop-over-array paradigm, which is more comfortable to some programmers than iterators:
Tables can also accumulate the results from more than one query as long as those queries return the same number of columns and column types:
If you want headers at the top of a printed table, give the columns names like this:
It is also possible to specify a rendering for certain columns. For instance, the query above returns an address of type rose_addr_t for column #3 (column numbering is always zero-origin). If we want the address to be formatted as a zero-padded, eight character hexadecimal number with a "0x" prefix, then we could do that with code like this (building from the previous example):
If we want the headers to be printed again every 50th row, we can do that with a PrePostRow functor. These functors have row info available to them so they can do fancier things too, like printing separators between major portions of a table.
Definition at line 677 of file SqlDatabase.h.
typedef std::vector<Tuple> SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::Rows |
All rows of a table.
Definition at line 714 of file SqlDatabase.h.
anonymous enum |
Enumerator | |
---|---|
MAXCOLS |
Maximum number of columns allowed in a table. |
Definition at line 679 of file SqlDatabase.h.
|
inline |
Creates a new, empty table.
Definition at line 717 of file SqlDatabase.h.
|
inlineexplicit |
Creates a new table and initializes it by running the specified database query.
Definition at line 720 of file SqlDatabase.h.
|
inline |
Headers to use when printing the table.
Definition at line 727 of file SqlDatabase.h.
|
inline |
Headers to use when printing the table.
Definition at line 731 of file SqlDatabase.h.
|
inline |
Headers to use when printing the table.
Definition at line 735 of file SqlDatabase.h.
|
inline |
How often should headers be reprinted?
Definition at line 748 of file SqlDatabase.h.
|
inline |
How often should headers be reprinted?
Definition at line 749 of file SqlDatabase.h.
|
inline |
Accessor for value renderers.
Use these to change how values are displayed. For instance, if a column has values that are addresses and you want to display them with StringUtility::addrToString(), then use code like this:
The render pointer should not be deleted before the table is done being used.
Definition at line 768 of file SqlDatabase.h.
|
inline |
Accessor for value renderers.
Use these to change how values are displayed. For instance, if a column has values that are addresses and you want to display them with StringUtility::addrToString(), then use code like this:
The render pointer should not be deleted before the table is done being used.
Definition at line 769 of file SqlDatabase.h.
|
inline |
Accessor for functors called before and after each row is printed.
Definition at line 774 of file SqlDatabase.h.
|
inline |
Accessor for functors called before and after each row is printed.
Definition at line 778 of file SqlDatabase.h.
|
inline |
Return the number of rows in the table.
Definition at line 784 of file SqlDatabase.h.
|
inline |
Returns true if table has no rows.
Definition at line 787 of file SqlDatabase.h.
|
inline |
Clear the table by removing all rows.
Definition at line 790 of file SqlDatabase.h.
|
inline |
Return a reference to a particular row.
Definition at line 794 of file SqlDatabase.h.
|
inline |
Return a reference to a particular row.
Definition at line 795 of file SqlDatabase.h.
|
inline |
Add a new row to the end of the table.
Definition at line 801 of file SqlDatabase.h.
|
inline |
Add a new row to the end of the table.
Definition at line 802 of file SqlDatabase.h.
|
inline |
Insert more rows into a table by running the specified query.
The table is not cleared first.
Definition at line 811 of file SqlDatabase.h.
|
inline |
String to print at the beginning of every line of output.
Definition at line 822 of file SqlDatabase.h.
|
inline |
String to print at the beginning of every line of output.
Definition at line 823 of file SqlDatabase.h.
|
inline |
Render a single value.
Definition at line 828 of file SqlDatabase.h.
|
inline |
Compute column widths.
Column widths are computed by internally printing the rows of the table and measuring the maximum width for each column. The renderers are called with zero for the column widths.
Definition at line 840 of file SqlDatabase.h.
References max.
|
inline |
Print the headers for a table.
Definition at line 864 of file SqlDatabase.h.
|
inline |
Print the row separator that goes between the headers and the data.
Definition at line 885 of file SqlDatabase.h.
|
inline |
Print one row of a table.
Definition at line 915 of file SqlDatabase.h.
References SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::Tuple::v0, SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::Tuple::v1, SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::Tuple::v10, SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::Tuple::v11, SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::Tuple::v12, SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::Tuple::v13, SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::Tuple::v14, SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::Tuple::v15, SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::Tuple::v2, SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::Tuple::v3, SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::Tuple::v4, SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::Tuple::v5, SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::Tuple::v6, SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::Tuple::v7, SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::Tuple::v8, and SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::Tuple::v9.
|
inline |
Print all rows of the table to the specified stream.
Definition at line 937 of file SqlDatabase.h.
References max.
|
private |
Definition at line 976 of file SqlDatabase.h.
|
private |
Definition at line 977 of file SqlDatabase.h.
|
private |
Definition at line 978 of file SqlDatabase.h.
|
private |
Definition at line 979 of file SqlDatabase.h.
|
private |
Definition at line 980 of file SqlDatabase.h.
|
private |
Definition at line 980 of file SqlDatabase.h.
|
private |
Definition at line 981 of file SqlDatabase.h.
|
private |
Definition at line 982 of file SqlDatabase.h.