// SqlResultTable.h #ifndef dset__SqlResultTable_H #define dset__SqlResultTable_H // Chitra Kannan // April 2004 // Modified by David Adams // November 2004 // // This is a concrete subclass of the Abstract class SqlTable // which is used primarily for testing the classes that use the // abstract class SqlTable. // // This table may be written to disk by calling the method write(fname). // // It may be accessed from SqlTable::Create("SQLRESULT", params) // where params holds name of such a file. #include "dataset_util/FileStatus.h" #include "dataset_sql/SqlQuery.h" #include "dataset_sql/InsertQuery.h" #include "dataset_sql/DeleteQuery.h" #include "dataset_sql/SqlResult.h" #include "dataset_sql/SqlTable.h" namespace dset { class SqlResultTable : public SqlTable { private: // Data. mutable SqlResult m_res; mutable int m_error; mutable std::string m_filename; std::string m_mcol; std::string m_ccol; private: // private functions // Write the table to its file. // Returns 0 for success. int write() const ; // Read the table from its file. // Returns 0 for success. int read() const ; public: // inherited methods // Constructor from a result. // mcol = modify time column // mcol = create time column explicit SqlResultTable(SqlResult& res); // Constructor from a file name. // Result is read from this file for each operation and // written back after each change. // Use with caution: file loking is *not* implemented. explicit SqlResultTable(std::string fname); // Destructor. ~SqlResultTable(); // Is this a valid ResultTable? bool is_valid() const; // Return the error code. int error() const; // Return a string describing an error. std::string error_string(int ecode) const; // Fetch the ResultTable schema. SqlResult get_schema() const; // Fetch the description of the column holding the modification time. // The returned time must be in unix format (seconds since 1970). // E.g. "modtime" or "unix_timestamp(modtime)". // Blank if there is no such column. std::string modify_time_column() const { return m_mcol; } // Fetch the description of the column holding the creation time. // The returned time must be in unix format (seconds since 1970). // E.g. "createtime" or "unix_timestamp(createtime)". // Blank if there is no such column. std::string create_time_column() const { return m_ccol; } // Fetch the total number of rows in the ResultTable. int get_row_count(SelectQuery query =SelectQuery()) const; // Fetch the total number of columns/fields in the ResultTable. int get_col_count(SelectQuery query =SelectQuery()) const; // Get result of executing Select sql query. // Argument carries the select clause (column names ) as well // as the constraint; not from clause. SqlResult execute_select_query(SelectQuery query =SelectQuery()) const; // Set the modify time column. void set_modify_time_column(std::string col) { m_mcol = col; } // Set the create time column. void set_create_time_column(std::string col) { m_ccol = col; } // Get result of executing Insert sql query. // Argument carries the column names as well as the values. int execute_insert_query(InsertQuery query); // Get result of executing Update sql query. // Argument carries the column names as well as the values. int execute_update_query(InsertQuery insquery, SelectQuery selquery); // Get result of executing Delete sql query. // Argument carries the constraint; not from clause. int execute_delete_query(DeleteQuery query =DeleteQuery()); // Write the table to a file. // File may not exist. // Returns 0 for success. int write(std::string fname) const ; }; } // end dset namespace #endif