Node.js driver for SqlAnywhere - Prepared statements exceeded

I am using the node.js driver for SqlAnywhere.

I am getting the "Resource governor for 'prepared statements' exceeded" error.

Initially, I was executing my queries like this:

connection.exec(myQuery, myArgs, myCallback);

where myQuery would look like this:

"SELECT * FROM some_procedure(?, ?, ?);"

I then changed it to:

connection.exec(myQuery, myCallback);

with myQuery now looking like this:

"SELECT * FROM some_procedure(%s);"

and then formatting the query using util.format :

myQuery = util.format(query, args.join(','));

... but I still get the same error. Why is this happening?

How can I prevent the connection from creating a bunch of prepared statements?

Thanks!

Edit: I am aware that there is a limit of 50 (default value) prepared statements for a connection.

I think that there is a bug in the sqlanywhere api. I checked their code and it seems that they don't drop the statement when you pass a callback to the query

if( callback_required ) {
    Local<Function> callback = Local<Function>::Cast(args[cbfunc_arg]);
    baton->callback = Persistent<Function>::New( callback );

    int status;
    status = uv_queue_work( uv_default_loop(), req, executeWork, (uv_after_work_cb)executeAfter );
    assert(status == 0);

    return scope.Close( Undefined() );
    }

The stmt drop code is executed only after this callback if

if( baton->sqlany_stmt != NULL ) {
    api.sqlany_free_stmt( baton->sqlany_stmt );
    }

Anyway as work around I suggest you to create a statement for each query and then drop it after executed.

Also would be interesting to report this bug in their github.