AsyncDistributedSqlEngine:executeMany

This article is deprecated.

Start executing a list of queries.

Prototype

    void executeMany(Vector<String> *queries,
                Vector<ConnectionArgs> *args,
                Allocator *ret_allocator);

Arguments

queries
A vector of query strings.
args
A vector of ConnectionArgs structures.
ret_allocator
The allocator used to build the result set.

Description

This method starts executing a list of queries. Each query string is executed by an individual worker process and the method waitMany() collects the results of each query when finished. The vector args contains the arguments to be substituted into the query strings. On return, the argument ret_allocator contains the address of the allocator used to build the query results.

Returns

No value returned.

Example

The following snippet defines a vector of query strings and 9 arguments to be substituted into the queries, then calls executeMany() to process these queries in parallel:

    const size_t nWorkers = 4;
    const char *nodes[] =
    {
        "localhost:5001",
        "localhost:5002"
    };

    int main(int argc, char** argv)
    {
        try {

            McoSql::Allocator my_allocator;

            McoSql::AsyncDistributedSqlEngine engine(nWorkers);
            if (!engine.open(nodes, sizeof(nodes) / sizeof(nodes[0])))
            {
                printf("Open failed: %s\n", engine.getError()->cstr());
                return 1;
            }
            ...
            McoSql::Vector<McoSql::String> *queries =
                McoSql::Vector<McoSql::String>::create(&my_allocator, nWorkers);

            for (size_t i = 0; i < nWorkers; i++)
            {
                queries->items[i] = McoSql::String::create( &my_allocator,
                    "INSERT INTO MyTable(pk, value, u2, i1, i2, i4, i8, flt, dbl) "
                    "VALUES (%v, %v, %v, %v, %v, %v, %v, %v, %v)");
            }

            McoSql::Vector<McoSql::ConnectionArgs> *args =
                McoSql::Vector<McoSql::ConnectionArgs>::create(&my_allocator, nWorkers);
            for (size_t i = 0; i < nWorkers; i++)
            {
                McoSql::ConnectionArgs *ca = new McoSql::ConnectionArgs(&my_allocator, 9 /*nParams*/);
                ca->args[0] = McoSql::IntValue::create(&my_allocator, i*100);
                ca->args[1] = McoSql::String::format(&my_allocator, "str%d", i);
                ca->args[2] = McoSql::IntValue::create(&my_allocator, i);
                ca->args[3] = McoSql::IntValue::create(&my_allocator, i);
                ca->args[4] = McoSql::IntValue::create(&my_allocator, i);
                ca->args[5] = McoSql::IntValue::create(&my_allocator, i);
                ca->args[6] = McoSql::IntValue::create(&my_allocator, i);
                ca->args[7] = McoSql::RealValue::create(&my_allocator, i*100);
                ca->args[8] = McoSql::RealValue::create(&my_allocator, i*100);
                args->items[i] = ca;
            }
            McoSql::Allocator ret_allocator;

            engine.executeMany(queries, args, &ret_allocator);
            ...
        }
    }