// SqlResult.h #ifndef SqlResult_H #define SqlResult_H #include "dataset_sql/SqlQuery.h" #include "dataset_sql/SelectQuery.h" #include "dataset_sql/InsertQuery.h" #include "dataset_sql/DeleteQuery.h" #include #include // Chitra Kannan and Vinay Sambamurthy // June 2004 // // Class to describe the result of an SQL query. // The result is invalid if the input query is invalid namespace dset { class SqlResult { public: // Typedefs. typedef std::vector NameList; typedef SqlRow Row; typedef std::vector Result; typedef Result::size_type size_type; private: // Data members. NameList m_names; Result m_result; mutable bool m_valid; public: // Methods. // Constructor. SqlResult(); // Constructor. SqlResult(NameList& names); // Copy Constructor. SqlResult(const SqlResult& res); // Destructor. ~SqlResult(); // Validity. bool is_valid() const; // Check validity of columns bool check_valid_cols(NameList& cols) const; // Insert a new row. // Returns 0 on success. int insert_row(const Row& row); // Return the number of rows. size_type num_rows() const; // Return the number of columns. int num_cols() const; // Return the names of columns. NameList get_col_names() const; // Return the vector of rows. Result get_rows() const; // Return the specified row. // Return an empty row if invalid index. const Row& fetch_row(unsigned int index) const; // Return the SqlResult after execution of a SELECT SqlQuery. SqlResult execute_select_query(const SelectQuery query) const; // Return the SqlResult after execution of a INSERT SqlQuery. int execute_insert_query(const InsertQuery query); // Return the SqlResult after execution of a UPDATE SqlQuery. int execute_update_query(const InsertQuery query, const SelectQuery selquery); // Return the SqlResult after execution of a DELETE SqlQuery. int execute_delete_query(const DeleteQuery query); // Output stream. std::ostream& ostr(std::ostream& str) const; }; } // end dset namespace. // Output stream. std::ostream& operator<<(std::ostream& lhs, const dset::SqlResult& rhs); #endif