Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit on batches with prepared statements #49

Open
paguan opened this issue Dec 7, 2014 · 4 comments
Open

Limit on batches with prepared statements #49

paguan opened this issue Dec 7, 2014 · 4 comments
Assignees

Comments

@paguan
Copy link

paguan commented Dec 7, 2014

Hey,

I'm playing around with your driver double checking if it fits our needs and just found out that when doing batches with preparedstatements and with more than 95 statements PHP crashes with "PHP Fatal error: Maximum function nesting level", this is coming from the recursive call to appendQueryToStack. This is working fine with normal statements though.
Is there any way you can remove that recursion? I don't really like the idea of tune php configuration to support as many recursive calls as my biggest batch.

Thanks

@evseevnn-zz
Copy link
Owner

Please, show me the queries in which an error occurs.

@evseevnn-zz evseevnn-zz self-assigned this Dec 8, 2014
@paguan
Copy link
Author

paguan commented Dec 8, 2014

This is a little example where this happens:

$connection = new Database($nodes); 
$connection->connect();
$connection->setKeyspace('tests');
$queryString = 'INSERT INTO test_table (tid, some_content) VALUES (:tid, :some_content)';
$connection->beginBatch();
for ($cont = 0; $cont < 100; $cont++) {
    $uuid = getUUID();
    $content = 'Random string with UUID: '.$uuid;
    echo 'Cont: '.$cont.' UUID: '.$uuid."\n";
    $connection->query($queryString, ['tid' => $uuid, 'some_content' => $content]);
}
$connection->applyBatch();

@teanooki
Copy link

teanooki commented Dec 8, 2014

There is a problem with the appendQueryToStack function in Database.php. Replacing the POSTFIX_DUPLICATE_QUERY_VARIABLE by an counter should work:

    /**
     * @var int
     */ 
    private $key_index = 0;

    private function appendQueryToStack($cql, array $values) {
        $valuesModified = false;
        foreach($values as $key => $value) {
            if (is_string($key) && isset($this->batchQueryData[$key])) {
                $newFieldName = $key . "_" . ++$this->key_index;
                $cql = str_replace(":{$key}", ":{$newFieldName}", $cql);
                unset($values[$key]);
                $values[$newFieldName] = $value;
                $valuesModified = true;
            }
        }

@paguan
Copy link
Author

paguan commented Dec 8, 2014

Yes, that fixed the issue.

Thanks guys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants