MCS  0.3.3-alpha7
mcs::Table Class Reference

A class to directly set and retrieve value from a database table. More...

#include <mcs.hh>

+ Inheritance diagram for mcs::Table:

Public Member Functions

void insert ()
 Insert a new record. More...
 
void loadTable ()
 Reload the table. More...
 
RecordnewRec ()
 Return a reference to a Record object for insert. More...
 
Tableoperator= (const Table &)
 Declared to avoid using of default assignment operator. More...
 
void replace ()
 Insert (or replace) a new record. More...
 
 Table (const Table &)
 Declared to avoid using of default copy constructor. More...
 
 Table (DBConn *db, string table, string fieldkey)
 Constructor. More...
 
void update ()
 Update the current record. More...
 
 ~Table ()
 Destructor. More...
 
- Public Member Functions inherited from mcs::Query
void close ()
 Close the statement and frees anything has been allocated. More...
 
void customFillBuffer (char *buf, unsigned int &chunksize, bool firstTime)
 Fills a buffer with a result-set. More...
 
void execute (bool StoreResult=false)
 Execute the prepared statement. More...
 
vector< string > ExecutionDetails (string pre="")
 Returns a vector of strings containing details of query execution. More...
 
bool gotRecordSet ()
 
long long int last_id ()
 Returns the last value generated for an AUTO_INCREMENT column. More...
 
Datalookup (string field, string table, string where="")
 Returns the current record set. More...
 
unsigned int nAffectedRows ()
 Returns number of affected records by the last execute() call. More...
 
Queryoperator= (const Query &)
 Declared to avoid using of default assignment operator. More...
 
Recordparam ()
 Returns a reference to a Record object containing all the input parameters. More...
 
void prepare (string SQL="")
 Prepare the SQL statement. More...
 
void prepare_with_parameters (int op, string fields, string table, string where="", int nrec=1)
 Prepare a query with input parameters. More...
 
void prepare_with_parameters (int op, char **fields, int nfields, string table, string where="", int nrec=1)
 Wrapper around prepare_with_parameters(int, string, string, string). More...
 
 Query (const Query &)
 Declared to avoid using of default copy constructor. More...
 
 Query (DBConn *lconn, bool call_newDBConn=false)
 Constructor. More...
 
void query (string SQL, bool StoreResult=false)
 Wrapper aropund prepare() and execute(). More...
 
void readTableList ()
 Reads the list of tables in the current database. More...
 
void Result2Ascii (string fn)
 Writes a table into an ASCII file using the customFillBuffer() method. More...
 
vector< string > simpleQuery (string SQL, unsigned int &nrows, unsigned int &nfields)
 Execute a query and return result in a vector of strings. More...
 
vector< string > simpleQuery (string SQL)
 Wrapper for simpleQuery(string, unsigned int&, unsigned int&). More...
 
vector< string > tableInfo (string tbl)
 Retrieve information about a table. More...
 
 ~Query ()
 
- Public Member Functions inherited from mcs::RecordSet
bool alwaysSameStructure ()
 
void dump (string fn)
 
bool eof ()
 
void insert (Record *rec)
 Insert a new record in the set. More...
 
void insert (Record &rec)
 Copy a new record in the set. More...
 
bool know_nRows ()
 
Recordmetarec ()
 
int nFields ()
 Returns number of fields. More...
 
unsigned int nRows ()
 
RecordSetoperator= (const RecordSet &)
 Declared to avoid using of default assignment operator. More...
 
unsigned int pos ()
 
RecordprepRecToSend ()
 
Recordrec ()
 
 RecordSet (const RecordSet &)
 Declared to avoid using of default copy constructor. More...
 
 RecordSet ()
 Build an empty record set. More...
 
void setFieldMap (string s="")
 Set up a field map for each record in the recordset. More...
 
bool setFirst ()
 Set the record pointer to the first position. More...
 
bool setLast ()
 Set the record pointer to the last position. More...
 
bool setNext ()
 Set the record pointer to the next position. More...
 
bool setPos (unsigned int i)
 Set the record pointer to the i-th position. More...
 
bool setPrev ()
 Set the record pointer to the previous position in the set. More...
 
bool setWhere (int i, string equalTo)
 Set the record pointer to the position which satisfies a string condition. More...
 
bool setWhere (int field, int equalTo)
 Set the record pointer to the position which satisfies an integer condition. More...
 
virtual ~RecordSet ()
 Destructor. More...
 

Private Member Functions

void insert_or_update (int op)
 

Private Attributes

string lfieldkey
 Name of the index field. More...
 
string ltable
 Table name. More...
 
 MCS_DEBUG_ALLOC
 
Record newrec
 Array of values for insert. More...
 
unsigned int posfieldkey
 Position of the index field. More...
 

Additional Inherited Members

- Public Attributes inherited from mcs::Query
vector< string > tableList
 A vector<string> containing the table list. More...
 
- Protected Member Functions inherited from mcs::RecordSet
virtual void hk_dump (string fn)
 Virtual method to provide dump facility to a file. More...
 
void init (unsigned char code, unsigned int nrows=0, Record *meta=NULL, short int id=0)
 Initailize the Record set. More...
 
void startFetch ()
 Must be called when record fetching is possible. More...
 

Detailed Description

A class to directly set and retrieve value from a database table.

This class gives you direct access to the value of a table. Direct access means that you can use setFirst(), setLast(), setWhere() method of Query to find a specific record. While you can retrieve the values from the table with the usual rec() method you can also update the table. To update you need to move the record pointer to the record you want to update, then insert the new values using the rec() method, and call the update() method. Finally you can insert new records setting values in the internal array of Data through the newRec() method, and call insert();

Warning
For this class to work correctly the table must have a unique key on one integer field.

Definition at line 5999 of file mcs.hh.

Constructor & Destructor Documentation

◆ Table() [1/2]

mcs::Table::Table ( const Table )

Declared to avoid using of default copy constructor.

Warning
This constructor is declared but not implemented. If you try to use it you will get a compilation error.

◆ Table() [2/2]

mcs::Table::Table ( DBConn db,
string  table,
string  fieldkey 
)

Constructor.

Parameters
dbDBConn object used to connect to db server;
tableTable name;
fieldkeyField index which is a unique key in the table.

Definition at line 931 of file Db.cc.

◆ ~Table()

mcs::Table::~Table ( )

Destructor.

Definition at line 943 of file Db.cc.

Member Function Documentation

◆ insert()

void mcs::Table::insert ( )

Insert a new record.

Values are those set with the newRec() methods.

Definition at line 966 of file Db.cc.

◆ loadTable()

void mcs::Table::loadTable ( )

Reload the table.

Definition at line 947 of file Db.cc.

◆ newRec()

Record & mcs::Table::newRec ( )

Return a reference to a Record object for insert.

Definition at line 959 of file Db.cc.

◆ operator=()

Table& mcs::Table::operator= ( const Table )

Declared to avoid using of default assignment operator.

Warning
This operator is declared but not implemented. If you try to use it you will get a compilation error.

◆ replace()

void mcs::Table::replace ( )

Insert (or replace) a new record.

Values are those set with the newRec() methods.

Definition at line 979 of file Db.cc.

◆ update()

void mcs::Table::update ( )

Update the current record.

Values are those actually found in the Record returned by the rec() method.

Definition at line 973 of file Db.cc.

Member Data Documentation

◆ lfieldkey

string mcs::Table::lfieldkey
private

Name of the index field.

Definition at line 6008 of file mcs.hh.

◆ ltable

string mcs::Table::ltable
private

Table name.

Definition at line 6005 of file mcs.hh.

◆ newrec

Record mcs::Table::newrec
private

Array of values for insert.

Definition at line 6014 of file mcs.hh.

◆ posfieldkey

unsigned int mcs::Table::posfieldkey
private

Position of the index field.

Definition at line 6011 of file mcs.hh.


The documentation for this class was generated from the following files:

mcslogo

MCS (My Customizable Server) ver. 0.3.3-alpha7
Documentation generated on Mon May 28 07:39:41 UTC 2018