// SqlTable.h #ifndef dset__SqlTable_H #define dset__SqlTable_H // Chitra Kannan // April 2004 // // Abstract class for running SQL queries. #include #include "dataset_sql/SqlQuery.h" #include "dataset_sql/SelectQuery.h" #include "dataset_sql/SqlResult.h" namespace dset { class SqlTable { public: // typedef // Creator. // Arguments are extracted from connection string name:params typedef SqlTable* (*Creator) (std::string name, std::string params); // Creator name. typedef std::string CreatorName; // List of class names. typedef std::vector CreatorList; // Callback function to receive notification when a creator is // registered. typedef void (*Callback) (std::string name); public: // static functions // Register a table. // The function pointed to by pfun will called when the an element // with name name is encountered. // Returns nonzero for error (e.g. same name already used for a // differenct function). static int register_creator(std::string name, Creator pfun); // Create a table using the appropriate function. // Caller is responsible for managing (deleting) the table. // Returns 0 if the element has an unknown name. static SqlTable* create(std::string name, std::string params); // Return the list of names for which functions have been registered. static const CreatorList& creators(); // Return if a specified name is registered. static bool has_creator(std::string name); // Register a function to be called whenever a creator is // registered. This makes if possible for SqlTable names to also be // used as catalog (repository, selection and replica) names. static int register_creator_callback(Callback pfun); public: // methods // Default constructor. SqlTable(); // Destructor. virtual ~SqlTable(); // Error. virtual int error() const =0; // Error message. virtual std::string error_string(int ecode) const =0; // Is this a valid table? virtual bool is_valid() const =0; // Fetch the table schema. virtual SqlResult get_schema() const =0; // 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. virtual std::string modify_time_column() const =0; // 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. virtual std::string create_time_column() const =0; // Fetch the total number of rows. virtual int get_row_count(SelectQuery query =SelectQuery()) const =0; // Fetch the total number of columns/fields. virtual int get_col_count(SelectQuery query =SelectQuery()) const =0; // Get result of executing Select sql query. // Argument carries the select clause (column names ) as well // as the constraint; not from clause. virtual SqlResult execute_select_query(SelectQuery query =SelectQuery()) const =0; // Get result of executing Insert sql query. // Argument carries the select clause (column names ) as well // as the constraint; not from clause. virtual int execute_insert_query(InsertQuery query) =0; // Get result of executing Update sql query. // Argument carries the select clause (column names ) as well // as the constraint; not from clause. virtual int execute_update_query(InsertQuery insquery, SelectQuery selquery) =0; // Get result of executing Delete sql query. // Argument carries the select clause (column names ) as well // as the constraint; not from clause. virtual int execute_delete_query(DeleteQuery query =DeleteQuery()) =0; }; } // end dset namespace #endif