2.7. The Rowtype Class

The Rowtype class provides a convenient container for Nullable-derived objects that are defined based on the columns in an executed SELECT statement.


Figure 2-7. class Rowtype

namespace Oracle
{
    class Rowtype
    {
        public:
            // constructors/destructor
            Rowtype();
            Rowtype(const Select_Stmt&);
            virtual ~Rowtype();

            // implementors
            void add(Nullable*, const string&);
            void set_null();
            Nullable& operator[](const int);
            Nullable& operator[](const string&);

            // accessors
            int ncols() const;
            string colname(const int) const;
            const Nullable& operator[](const int) const;
            const Nullable& operator[](const string&) const;
    };

    ostream& operator<<(ostream&, const Rowtype&);
}

2.7.1. Public Member Functions

2.7.1.1. Constructor

Rowtype(const Select_Stmt& executed_select_stmt);

The Rowtype is created with Nullable objects, the type and length of which are determined by the columns in the executed Select_Stmt object.

2.7.1.2. colname()

string& colname(const int column_number);

This method returns the name of the column at (zero-based) position column_number in the SELECT list.

2.7.1.3. ncols()

int ncols(void);

This method returns the number of columns in the object.

2.7.1.4. operator[]()

const Nullable& operator[](const int column_position);

const Nullable& operator[](const string& column_name);

These methods provide access to the individual Nullable objects, either by column name or zero-based column position.

2.7.1.5. set_null()

void set_null(void);

This method sets to NULL all objects in its collection.

2.7.2. Non-Member Functions

2.7.2.1. operator<<()

ostream& operator<<(ostream& output_stream, const Rowtype& rowtype_object);

This method provides a convenient way to dump the contents of a particular row. For example, if the row contained a Varchar column named "NAME" set to "Fred," a Number column named "SCORE" set to 100 and a Varchar column named "MEMO" set to null, the output would look like this:

NAME=Fred, SCORE=100, MEMO=NULL