Skip to content

Example doesn't work #10

@nervaccio

Description

@nervaccio

I don't know if the title fits and if it's only my problem, so sorry in advance.
(for who have read the first version of the issue, I had a problem to run tests, was my issue)

After a fresh, composer require clue/reactphp-sqlite:dev-master, I had an error with the example of the documentation. I think could be the same reason that makes fail the tests.

Someone could give me a hint about where to look to resolve?

<?php
require __DIR__.'/vendor/autoload.php';

$loop = React\EventLoop\Factory::create();

$name = 'Alice';
Clue\React\SQLite\Database::open($loop, 'users.db')->then(
    function (Clue\React\SQLite\Database $db) use ($name) {
        $db->exec('CREATE TABLE IF NOT EXISTS foo (id INTEGER PRIMARY KEY AUTOINCREMENT, bar STRING)');

        $db->query('INSERT INTO foo (bar) VALUES (?)', array($name))->then(
            function (Clue\React\SQLite\Result $result) use ($name) {
                echo 'New ID for ' . $name . ': ' . $result->insertId . PHP_EOL;
            }
        );

        $db->quit();
    },
    function (Exception $e) {
        echo 'Error: ' . $e->getMessage() . PHP_EOL;
    }
);

$loop->run();

This is the error:

╰─$ php insert.php
RuntimeException: Database closed in /home/giovanni/projects/test-react/vendor/clue/reactphp-sqlite/src/Database.php:358
Stack trace:
#0 /home/giovanni/projects/test-react/vendor/clue/reactphp-sqlite/src/Database.php(180): Clue\React\SQLite\Database->close()
#1 /home/giovanni/projects/test-react/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(123): Clue\React\SQLite\Database->Clue\React\SQLite\{closure}()
#2 /home/giovanni/projects/test-react/vendor/clue/ndjson-react/src/Decoder.php(65): Evenement\EventEmitter->emit('close')
#3 /home/giovanni/projects/test-react/vendor/clue/ndjson-react/src/Decoder.php(128): Clue\React\NDJson\Decoder->close()
#4 /home/giovanni/projects/test-react/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(123): Clue\React\NDJson\Decoder->handleEnd()
#5 /home/giovanni/projects/test-react/vendor/react/stream/src/ReadableResourceStream.php(149): Evenement\EventEmitter->emit('end')
#6 /home/giovanni/projects/test-react/vendor/react/event-loop/src/StreamSelectLoop.php(244): React\Stream\ReadableResourceStream->handleData(Resource id #24)
#7 /home/giovanni/projects/test-react/vendor/react/event-loop/src/StreamSelectLoop.php(211): React\EventLoop\StreamSelectLoop->waitForStreamActivity(NULL)
#8 /home/giovanni/projects/test-react/insert.php(24): React\EventLoop\StreamSelectLoop->run()
#9 {main}%

PHP module

╰─$ php -m | grep sqlite    
pdo_sqlite    
sqlite3    

Thank you in advance!
Cheer

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions