easydb: How to run CREATE TABLE queries? (run and query methods fail)

I have the following setup:

$db = Factory::create('sqlite:memory.db');
$db->run($sql);
// respectively
$db->query($sql);

The following CREATE TABLE query:

CREATE TABLE IF NOT EXISTS predicate (
    id      INTEGER PRIMARY KEY AUTOINCREMENT,
    value   TEXT,
    UNIQUE(value)
);

fails to run using run and query method.

run method

Error:

TypeError: Argument 1 passed to ParagonIE\EasyDB\EasyDB::getResultsStrictTyped() 
must be an instance of PDOStatement, boolean given, called in 
.../vendor/paragonie/easydb/src/EasyDB.php on line 759

.../vendor/paragonie/easydb/src/EasyDB.php:1042
...vendor/paragonie/easydb/src/EasyDB.php:759
.../vendor/paragonie/easydb/src/EasyDB.php:722
.../Adapter/SQliteMemory/Store.php:81
.../Adapter/SQliteMemory/StoreTest.php:14

query method

TypeError: Return value of ParagonIE\EasyDB\EasyDB::query() must be an instance of 
PDOStatement, boolean returned

.../vendor/paragonie/easydb/src/EasyDB.php:1197
.../src/beardfulldb/Adapter/SQliteMemory/Store.php:81

What did i wrong?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19 (6 by maintainers)

Most upvoted comments

I think we should add a check when calling prepare() to ensure the query string isn’t empty, then throw our own exception. That should prevent anyone from spending a lot of time on troubleshooting.

This will be fixed in the next release. #94 contained the proposed fix.

@k00ni Yes, You are right.I’m a novice.I know a little about SQLite, I use ‘ATUO_INCREMENT’ in mysql.I learned new knowledeg because of your reply.Thanks.