gabordemooij / redbean

ORM layer that creates models, config and database on the fly
https://www.redbeanphp.com
2.31k stars 279 forks source link

different handling of bind parameters in fluid or freeze #584

Closed flip111 closed 7 years ago

flip111 commented 7 years ago

I have this query (output by symfony/var-dumper, so it contains literal \n)

"""
\n
            SELECT s.*, (COALESCE(s.name, '') || '_' || COALESCE(s.interface, '') || '_' || COALESCE(s.interface_extra, '')) AS full_name\n
            FROM standard AS s\n
            WHERE full_name IN (?,?,?,?)
"""

array:4 [▼
  0 => "G_8261_E1_1"
  1 => "G_8261_DS1_"
  2 => "G_823_E1_traf"
  3 => "G_824_DS1_traf"
]

This is the php run

R::getAll($standards_sql, $data['Standard']);

This is the error

RedBeanPHP\RedException\SQL: SQLSTATE[HY000]: General error: 25 bind or column index out of range (uncaught exception) at /var/www/html/tie/vendor/gabordemooij/redbean/RedBeanPHP/Driver/RPDO.php line 187 {"exception":"[object] (RedBeanPHP\\RedException\\SQL(code: 0): SQLSTATE[HY000]: General error: 25 bind or column index out of range at /var/www/html/tie/vendor/gabordemooij/redbean/RedBeanPHP/Driver/RPDO.php:187)"}

I believe the cause of this is The keys from input_parameters must match the ones declared in the SQL. Before PHP 5.2.0 this was silently ignored.. The fix is easy, just use array_values()

R::getAll($standards_sql, array_values($data['Standard']));

My question: why is this error only happening when freeze is active? I develop without freeze and i didn't see this error, can a check be added for this when not using freeze? So that when freeze is active it's still going right? I thought if your schema is in place it's always safe to switch to freeze mode ... i guess not ... Should the guarantee be there that it's safe to switch to freeze when the schema is already in place? Otherwise i will also have to test in freeze which would be annoying because then i have to test everything twice.

gabordemooij commented 7 years ago

Interesting issue, I'll have to test that myself...

krisives commented 7 years ago

Is this RedBean 4.x or 5.x?

gabordemooij commented 7 years ago

From the looks of the error I assume you use SQLite. Error handling in SQLite was rather crude. However I'll improved it in just now. Latest beta, can you try? It should now ignore only no-column/no-table errors in fluid mode, nothing else. In frozen mode, it does not ignore any errors at all. It should therefore behave just like the other drivers.

https://redbeanphp.com/index.php?p=/download#beta https://github.com/gabordemooij/redbean/commit/44229acdf493e2229c1e33e3add211f23c05ee4d

flip111 commented 7 years ago

Yes sorry i forgot to report ... I was running PHP 7.1.9 SQLite on this version of redbean: https://github.com/gabordemooij/redbean/tree/935cc77ed8bd0f6589b0e296d644ef50c384cf68

thx for this fix.