cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

[Improvement] Db Adapter Pdo

Open kornerita opened this issue 9 years ago • 1 comments

Hi,

I use ORACLE as Database, I took the Oracle Adapter and Oracle Dialect from the incubator, tweak it a little and I got it running, all was smooth.

Issues with my implementation

I started using CLOB fields and binding them as \Phalcon\Db\Column::BIND_PARAM_STR works fine for stings less than 1024 bytes. But for stings larger than that, pdo_oci does not work with PDOStatement::bindValue as used in Db\Adapter\Pdo, it throws an "ORA-01461: can bind a LONG value only for insert into a LONG column" error.

Resolution of my issues

I overwritten the executePrepared method on the Oracle Adapter by using PDOStatement::bindParam instead, specifying the length of the bind.

The main difference between bindValue and bindParam is that the last one binds data by reference, and bindValue binds it by value, it also has some differences in usage like statement->bindValue(':1', data) vs statement->bindParam(1, data) and statement->bindValue('param', data) vs statement->bindParam(':param', data); additionally you have an optional last parameter for the size of the bind (which is needed to get it working with "large clobs").

Conclusion that leads to improvement

The Improvement request comes from the fact that whatever engine database you are using, bindValue copies all data from a variable and sends it to the \PDOStatement object while bindParam does not.

Looking for a "worst case scenario":

  • You are using any of the supported database engines with the "db.force_casting" database configuration.
  • You are using any field that casts to string or otherwise with large data.

This will consume tree times the required amount of memory to execute the statement, without force casting, will require two times.

Suggestions:

  1. Use of bindParam in favor of bindValue to reduce amount of memory required.
  2. Check the type of the variable before force casting when "db.force_casting" is enabled.

Thanks for your time, Federico.

kornerita avatar Aug 04 '17 15:08 kornerita

Thank you for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please feel free to either reopen this issue or open a new one. We will be more than happy to look at it again! You can read more here: https://blog.phalconphp.com/post/github-closing-old-issues

stale[bot] avatar Apr 16 '18 17:04 stale[bot]