f3-factory / fatfree-core

Fat-Free Framework core library
GNU General Public License v3.0
208 stars 88 forks source link

PDO: near "FROM": syntax error #376

Closed landall closed 6 months ago

landall commented 6 months ago

It seems to generate a empty fields list when using sqlite mapper. PHP 7.4.33 sqlite 3.26.0 2018-12-01 Linux 4.18.0-372.19.1.el8_6.x86_64

[13-Apr-2024 11:47:47 UTC] SELECT * FROM pragma_table_info('Accounts') JOIN (SELECT sql FROM sqlite_master WHERE (type='table' OR type='view')  AND name='Accounts')
[13-Apr-2024 11:47:47 UTC] SELECT * FROM pragma_table_info('Accounts') JOIN (SELECT sql FROM sqlite_master WHERE (type='table' OR type='view')  AND name='Accounts')
[13-Apr-2024 11:47:47 UTC] Calling DB.SQL.Mapper.find with
[13-Apr-2024 11:47:47 UTC] $filter:
[13-Apr-2024 11:47:47 UTC] Array
(
    [0] => akey=?
    [1] => cst@g.com
)

[13-Apr-2024 11:47:47 UTC] $options
[13-Apr-2024 11:47:47 UTC]
[13-Apr-2024 11:47:47 UTC] $ttl
[13-Apr-2024 11:47:47 UTC] 0
[13-Apr-2024 11:47:47 UTC] >> $this->engine:
[13-Apr-2024 11:47:47 UTC] sqlite
[13-Apr-2024 11:47:47 UTC] >> $this->adhoc
[13-Apr-2024 11:47:47 UTC] Array
(
)

[13-Apr-2024 11:47:47 UTC] >> print_r(implode(',',array_map([$this->db,'quotekey'],array_keys($this->fields))),true)
[13-Apr-2024 11:47:47 UTC]
[13-Apr-2024 11:47:47 UTC] Calling DB.SQL.Mapper.select with
[13-Apr-2024 11:47:47 UTC] $fields:
[13-Apr-2024 11:47:47 UTC]
[13-Apr-2024 11:47:47 UTC] $filter:
[13-Apr-2024 11:47:47 UTC] Array
(
    [0] => akey=?
    [1] => cst@g.com
)

[13-Apr-2024 11:47:47 UTC] $options:
[13-Apr-2024 11:47:47 UTC] Array
(
    [group] =>
    [order] =>
    [limit] => 0
    [offset] => 0
)

[13-Apr-2024 11:47:47 UTC] $ttl:
[13-Apr-2024 11:47:47 UTC] 0
[13-Apr-2024 11:47:47 UTC] SELECT  FROM `Accounts` WHERE akey=?
[13-Apr-2024 11:47:47 UTC] SELECT  FROM `Accounts` WHERE akey=?
[13-Apr-2024 11:47:47 UTC] PDO: near "FROM": syntax error
[13-Apr-2024 11:47:47 UTC] [vendor/bcosca/fatfree-core/db/sql.php:270]
[13-Apr-2024 11:47:47 UTC] [vendor/bcosca/fatfree-core/db/sql/mapper.php:317] DB\SQL->exec()
[13-Apr-2024 11:47:47 UTC] [vendor/bcosca/fatfree-core/db/sql/mapper.php:367] DB\SQL\Mapper->select()
[13-Apr-2024 11:47:47 UTC] [vendor/bcosca/fatfree-core/db/cursor.php:179] DB\SQL\Mapper->find()
[13-Apr-2024 11:47:47 UTC] [oauth.php:31] DB\Cursor->load()
[13-Apr-2024 11:47:47 UTC] [oauth.php:85] Base->run()

The test code runs as expect.

[13-Apr-2024 19:48:09 PRC] SELECT * FROM pragma_table_info('Accounts') JOIN (SELECT sql FROM sqlite_master WHERE (type='table' OR type='view')  AND name='Accounts')
[13-Apr-2024 19:48:09 PRC] SELECT * FROM pragma_table_info('Accounts') JOIN (SELECT sql FROM sqlite_master WHERE (type='table' OR type='view')  AND name='Accounts')
[13-Apr-2024 19:48:09 PRC] Calling DB.SQL.Mapper.find with
[13-Apr-2024 19:48:09 PRC] $filter:
[13-Apr-2024 19:48:09 PRC]
[13-Apr-2024 19:48:09 PRC] $options
[13-Apr-2024 19:48:09 PRC]
[13-Apr-2024 19:48:09 PRC] $ttl
[13-Apr-2024 19:48:09 PRC] 0
[13-Apr-2024 19:48:09 PRC] >> $this->engine:
[13-Apr-2024 19:48:09 PRC] sqlite
[13-Apr-2024 19:48:09 PRC] >> $this->adhoc
[13-Apr-2024 19:48:09 PRC] Array
(
)

[13-Apr-2024 19:48:09 PRC] >> print_r(implode(',',array_map([$this->db,'quotekey'],array_keys($this->fields))),true)
[13-Apr-2024 19:48:09 PRC] `id`,`akey`,`apassword`,`aupdate_time`,`aroles`
[13-Apr-2024 19:48:09 PRC] Calling DB.SQL.Mapper.select with
[13-Apr-2024 19:48:09 PRC] $fields:
[13-Apr-2024 19:48:09 PRC] `id`,`akey`,`apassword`,`aupdate_time`,`aroles`
[13-Apr-2024 19:48:09 PRC] $filter:
[13-Apr-2024 19:48:09 PRC]
[13-Apr-2024 19:48:09 PRC] $options:
[13-Apr-2024 19:48:09 PRC] Array
(
    [group] =>
    [order] =>
    [limit] => 0
    [offset] => 0
)

[13-Apr-2024 19:48:09 PRC] $ttl:
[13-Apr-2024 19:48:09 PRC] 0
[13-Apr-2024 19:48:09 PRC] SELECT `id`,`akey`,`apassword`,`aupdate_time`,`aroles` FROM `Accounts`
[13-Apr-2024 19:48:09 PRC] SELECT `id`,`akey`,`apassword`,`aupdate_time`,`aroles` FROM `Accounts`
[13-Apr-2024 19:48:09 PRC] Calling DB.SQL.Mapper.find with
[13-Apr-2024 19:48:09 PRC] $filter:
[13-Apr-2024 19:48:09 PRC] Array
(
    [0] => akey=?
    [1] => cst@g.com
)

[13-Apr-2024 19:48:09 PRC] $options
[13-Apr-2024 19:48:09 PRC]
[13-Apr-2024 19:48:09 PRC] $ttl
[13-Apr-2024 19:48:09 PRC] 0
[13-Apr-2024 19:48:09 PRC] >> $this->engine:
[13-Apr-2024 19:48:09 PRC] sqlite
[13-Apr-2024 19:48:09 PRC] >> $this->adhoc
[13-Apr-2024 19:48:09 PRC] Array
(
)

[13-Apr-2024 19:48:09 PRC] >> print_r(implode(',',array_map([$this->db,'quotekey'],array_keys($this->fields))),true)
[13-Apr-2024 19:48:09 PRC] `id`,`akey`,`apassword`,`aupdate_time`,`aroles`
[13-Apr-2024 19:48:09 PRC] Calling DB.SQL.Mapper.select with
[13-Apr-2024 19:48:09 PRC] $fields:
[13-Apr-2024 19:48:09 PRC] `id`,`akey`,`apassword`,`aupdate_time`,`aroles`
[13-Apr-2024 19:48:09 PRC] $filter:
[13-Apr-2024 19:48:09 PRC] Array
(
    [0] => akey=?
    [1] => cst@g.com
)

[13-Apr-2024 19:48:09 PRC] $options:
[13-Apr-2024 19:48:09 PRC] Array
(
    [group] =>
    [order] =>
    [limit] => 0
    [offset] => 0
)

[13-Apr-2024 19:48:09 PRC] $ttl:
[13-Apr-2024 19:48:09 PRC] 0
[13-Apr-2024 19:48:09 PRC] SELECT `id`,`akey`,`apassword`,`aupdate_time`,`aroles` FROM `Accounts` WHERE akey=?
[13-Apr-2024 19:48:09 PRC] SELECT `id`,`akey`,`apassword`,`aupdate_time`,`aroles` FROM `Accounts` WHERE akey=?
landall commented 6 months ago

It is my mistake. I open a database in $f3->route callback function, but use a variable out of the function. So the SQLite engine open the database with a empty filename.