3.4. The Select_Stmt Class

Refer to Section 3.3 for the public data members and member functions which are inherited by Select_Stmt.


Figure 3-5. class Select_Stmt

namespace Oracle
{
    class Select_Stmt: public Stmt
    {
        public:
            // constructors/destructor
            Select_Stmt(Connection&);
            Select_Stmt(Connection&, const string&);
            virtual ~Select_Stmt();

            // implementors
            virtual void exec();
            virtual void bind_col(Nullable&);
            virtual void bind_col(Nullable* ...);
            virtual void bind_col(Rowtype&);
            virtual bool fetch();
            virtual void close();
            Nullable& operator[](const int);
            Nullable& operator[](const string&);

            // accessors
            const Nullable& operator[](const int) const;
            const Nullable& operator[](const string&) const;
            virtual string colname(const int) const;
            virtual stmt_t type() const;
            virtual int ncols() const;

        friend class Connection;
        friend class Rowtype;
    };
}

3.4.1. Public Member Functions

3.4.1.1. Constructors

Select_Stmt(Connection& connection_to_use);

Select_Stmt(Connection& connection_to_use, const string& statement_text);

The first form allows the use of the Select_Stmt object as an output stream to write the statement text. The second form specifies the entire statement text at construction time; it cannot be added to by using the stream feature.

3.4.1.2. bind_col()

void bind_col(Nullable& output_object);

void bind_col(Rowtype& output_collection);

void bind_col(Nullable* output_object, ...);

This method associates a Nullable object or collection with columns in the SELECT list. (Note: The OCI documentation calls this step "defining;" it uses the term "binding" only for placeholders.) Each call of the first version associates a Nullable-derived object with the next column.

The second version requires only a single call. It associates a Rowtype object to the columns. If the Rowtype object is uninitialized, the call creates appropriate objects within the collection. If it is already initialized, the corresponding objects must be type-compatible.

The third version allows binding of multiple objects to the columns with a single call. The number of arguments must be the same as the number of columns in the SELECT list.

3.4.1.3. 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.

3.4.1.4. fetch()

bool fetch(void);

This method fetches the next row into the objects that were bound by bind_col, or into the internal Rowtype object if no columns were bound.

3.4.1.5. ncols()

int ncols(void);

This method returns the number of columns in the query.

3.4.1.6. operator[]()

Nullable& operator[](const int column_number);

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

This method returns the Nullable-derived object contained within the Rowtype data member. This function throws State_Error if columns were previously bound by bind_col().