MySQL Connector/C++
MySQL connector library for C and C++ applications
Public Member Functions | Protected Member Functions | List of all members
Table Class Reference

Represents a table in a schema. More...

Public Member Functions

bool isView ()
 Check if this table object corresponds to a view. More...
 
uint64_t count ()
 Get the number of rows in the table.
 
TableInsert insert ()
 Return an operation which inserts rows into the full table without restricting the columns. More...
 
template<class... T>
TableInsert insert (const T &... t)
 Return an operation which inserts rows into the table restricting the columns. More...
 
template<typename ... PROJ>
TableSelect select (const PROJ &...proj)
 Return an operation which selects rows from the table. More...
 
TableRemove remove ()
 Return an operation which removes rows from the table. More...
 
TableUpdate update ()
 Return an operation which updates rows in the table. More...
 

Protected Member Functions

const stringgetName () const
 Get database object name.
 
SessiongetSession ()
 Get Session object.
 
const SchemagetSchema () const
 Get schema object.
 

Detailed Description

Represents a table in a schema.

A Table object can be obtained from Schema::getTable() method:

Schema db;
Table myTable;
myTable= db.getTable("My Table");

or directly constructed as follows:

Schema db;
Table myTable(db, "My Table");

A Table object can refer to a plain table or to a view. In the latter case method isView() called on the object returns true.

When creating a Table object, by default no checks are made that it actually exists in the database. An operation that is executed on the server and involves such a non-existent table throws an error. Call existsInDatabase() to check the existence of the table.

Note
A Table object should be used by at most one thread at a time. It is not safe to call its methods by several threads simultaneously. It is responsibility of the user to ensure this using a synchronization mechanism such as mutexes.

Member Function Documentation

◆ isView()

bool isView ( )
inline

Check if this table object corresponds to a view.

Note
This check might involve communication with the server.

◆ insert() [1/2]

TableInsert insert ( )
inline

Return an operation which inserts rows into the full table without restricting the columns.

Specify rows to be inserted using methods of TableInsert class chained on the returned operation object. Call execute() to execute the operation and insert the specified rows.

Each specified row must have the same number of values as the number of columns of the table. If the value count and the table column count do not match, server reports error when operation is executed.

Note
Any errors related to the operation are reported when the operation is executed, not when it is created.
See also
TableInsert

◆ insert() [2/2]

TableInsert insert ( const T &...  t)
inline

Return an operation which inserts rows into the table restricting the columns.

Specify column names as method arguments. Values are inserted only into the specified columns, other columns are set to null or to column's default value (depending on the definition of the table). Specify rows to be inserted using methods of TableInsert class chained on the returned operation object. Call execute() to execute the operation and insert the specified values.

Each specified row must have the same number of values as the number of columns listed here. If the value count and the column count do not match, server reports error when operation is executed.

Note
Any errors related to the operation are reported when the operation is executed, not when it is created.
See also
TableInsert

◆ select()

TableSelect select ( const PROJ &...  proj)
inline

Return an operation which selects rows from the table.

Call execute() on the returned operation object to execute it and get a RowResult object that gives access to the rows. Specify query parameters, such as selection criteria and ordering of the rows, using chained methods of TableSelect class before making the final call to execute(). To project selected rows before returning them in the result, specify a list of expressions as arguments of this method. These expressions are evaluated to form a row in the result. An expression can be optionally followed by "AS <name>" suffix to give a name to the corresponding column in the result. If no expressions are given, rows are returned as is, without any projection.

Note
Any errors related to the operation are reported when the operation is executed, not when it is created.
See also
TableSelect

◆ remove()

TableRemove remove ( )
inline

Return an operation which removes rows from the table.

Use chained methods of TableRemove class on the returned operation object to specify the rows to be removed. Call execute() to execute the operation and remove the rows.

Note
Any errors related to the operation are reported when the operation is executed, not when it is created.
See also
TableRemove

◆ update()

TableUpdate update ( )
inline

Return an operation which updates rows in the table.

Use chained methods of TableUpdate class on the returned operation object to specify which rows should be updated and what modifications to apply to each of them. Call execute() to execute the operation and remove the rows.

Note
Any errors related to the operation are reported when the operation is executed, not when it is created.
See also
TableUpdate

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