RDM::DB::QUERY::inner_join_by_referencing< table_id, ref_id, NEXT > Class Template Reference

Inner join by referencing. More...

#include "rdm_db_query.h"

Inheritance diagram for RDM::DB::QUERY::inner_join_by_referencing< table_id, ref_id, NEXT >:
Inheritance graph
Collaboration diagram for RDM::DB::QUERY::inner_join_by_referencing< table_id, ref_id, NEXT >:
Collaboration graph

Public Member Functions

inner_join_by_referencing ()
- Public Member Functions inherited from RDM::DB::QUERY::join_rows< table_id, NEXT >
uint8_t * serialize (uint8_t *buffer)
uint8_t * unserialize (uint8_t *buffer)
join_rows ()
~join_rows ()
uint32_t init_tables_to_write_lock (RDM_TABLE_ID *tables)
IDs of the tables where rows are inserted. More...
uint32_t init_tables_to_read_lock (RDM_TABLE_ID *tables)
IDs of the tables where rows are read. More...
RDM_RETCODE init (RDM_DB p_db)
Initialize this object. More...
void reset (void)
Reset this object. More...
RDM_RETCODE fetch_first ()
Fetch the first. More...
RDM_RETCODE fetch_prev ()
Fetch the previous. More...
RDM_RETCODE fetch_next ()
Fetch the next. More...
RDM_RETCODE fetch_last ()
Fetch the last. More...
template<class TARGET_ROW_T >
RDM_RETCODE bind_row (TARGET_ROW_T *target_row, bool *target_all_columns_null=NULL)
Bind a row. More...

Additional Inherited Members

- Static Public Member Functions inherited from RDM::DB::QUERY::join_rows< table_id, NEXT >
constexpr static int get_serialize_size (void)
Get the size of a buffer for serialization to hold its state. More...
constexpr static int number_of_tables_to_write_lock (void)
Number of tables where rows are inserted. More...
constexpr static int number_of_tables_to_read_lock (void)
Number of tables where rows are read. More...
- Data Fields inherited from RDM::DB::QUERY::join_rows< table_id, NEXT >
NEXT next
- Protected Attributes inherited from RDM::DB::QUERY::join_rows< table_id, NEXT >
RDM_DB db
RDM_CURSOR cursor
void * target_row
uint32_t target_size
bool * target_all_columns_null
bool outer_join
bool keyed_join
position pos

Detailed Description

template<RDM_TABLE_ID table_id, RDM_REF_ID ref_id, class NEXT>
class RDM::DB::QUERY::inner_join_by_referencing< table_id, ref_id, NEXT >

Inner join by referencing.

Use this template class in combination with other classes for doing an inner join. In its simplest form, the NEXT class is a read_row class, in which case this class implements a join between two tables.

Assuming the following schema:

CREATE TABLE T1
(
i1 int,
i2 int primary key
);
CREATE TABLE T2
(
i2 int references T1,
i3 int primary key
);

where we want to compute the natural join between T1 and T2, it can be set up as follows:

using READ_ROW = read_row <TABLE_T1>;
using JOIN = inner_join_by_referencing <TABLE_T2, REF_T2_I2, READ_ROW>;
JOIN join;

We have a chain of two classes above. The first class in the chain is a static instanse of the inner_join_by_referencing template class (join), and the next (and last) class in the chain is a static instance of the read_row template class (join.next). Note that for the query to work as intended, the reference has to be from T2.i2 to T1.i2.

Use the init() methode on the first class to initialize these classes with a database handle. Then bind a row for each class by calling bind_row() on both.

This join can be fetched by repeatedly calling fetch_next() until sENDOFCURSOR is returned. For each call, the rows that have been bound will be populated with the actual row data.

The NEXT class can instead be an instance of any of the join template classes, in which case this class implements a join between the result of another join and the table specified here.

Note that there is asymmetry between the arguments of the join. One argument is the computation done by the next class while the other argument is just specified by a table ID. It means this class is not able to implement a join of two row sets where each set itself is a join.

Also note that a join as specified by the SQL standard has a left and a right argument. The two arguments here are the next class in the chain and the table specified. Which argument represents the left and the right argument is up to the application. However, if it is an outer join, it is the next class that represents the outer argument.

Template Parameters
table_id The ID of the table we join with. This is one argument of the join.
ref_id The ID of the reference
NEXT The next class in the chain of classes. This represents one arguments of the join.

Constructor & Destructor Documentation

inner_join_by_referencing()

template<RDM_TABLE_ID table_id, RDM_REF_ID ref_id, class NEXT >
RDM::DB::QUERY::inner_join_by_referencing< table_id, ref_id, NEXT >::inner_join_by_referencing ( )
inline
1459 {
1460 this->outer_join = false;
1461 }

References RDM::DB::QUERY::join_rows< table_id, NEXT >::outer_join.


The documentation for this class was generated from the following file:
bool outer_join
Definition: rdm_db_query.h:149