The SqlAggregator is a class that acts like a distributed connection, but within a single process. In order to use the SqlAggregator the C++ application creates an array of SqlEngine objects to run as shards. Then it starts all of the SqlEngine objects and passes the array to the SqlAggregator constructor.
For example:
const int n_engines = 3; McoSql::SqlEngine *engines[n_engines]; ... for (i=0; I < n_engines; i++ ) { engine.open( db_name, persondb_get_dictionary(), DATABASE_SIZE, MEMORY_PAGE_SIZE); } ... McoSql::SqlAggregator aggregator(engines, n_engines);Once the
aggregator
has been created and initialized it can be used exactly as the SqlEngine. For example:McoSql::QueryResult result( aggregator.executeQuery( "select pk,value from MyTable" ) );When no longer required, the
aggregator
must be closed through theSqlAggregator close()
method. All engines passed into the aggregator must explicitly be closed as well. For example:printf ("Closing aggregator.\n"); aggregator.close(); printf ("Closing engines.\n"); for (i = 0; i < n_engines; i++) { engines[i]->close(); }Note that class SqlAggregator directly uses the SqlEngine objects passed to the constructor. So these SqlEngine objects should not be used in other application code during the lifetime of the SqlAggregator object. This would cause simultaneous usage of these objects in different program threads: the application's thread and in a thread internally created by SqlAggregator to serve the SqlEngines.
SQL String Length
Whereas for the
executeStatement()
and theexecuteQuery()
methods of the SqlEngine class there is no limit to the length of the statement string argument, for the SqlAggregator class the statement string length is limited by thebufferSize
argument passed to the constructor. The default value is 64 Kb. Please refer to the SQL Statement Strings page for further details.