Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can read but not save binary data (e.g. BYTEA) in version 1.1.11 #1181

Closed
karmakaze opened this issue Aug 9, 2012 · 0 comments
Closed

Can read but not save binary data (e.g. BYTEA) in version 1.1.11 #1181

karmakaze opened this issue Aug 9, 2012 · 0 comments
Assignees
Milestone

Comments

@karmakaze
Copy link

When reading a BYTEA column, it is a PHP 'resource' type which can be read like a file.

When saving such a column, an escaped value (such as '\x9f319004ad45' can be set in the case of PostgreSQL) and it will be translated to a resource for PDO to write. When it goes to write it however, it gets cast to a string somewhere along the line and ends up writing data like 'Resource #68' to the bytea column instead of the intended binary data.

The following is a patch to CDbConnection.php (diff on tag 1.1.11) which corrects the problem:


diff --git a/framework/db/CDbConnection.php b/framework/db/CDbConnection.php
index beff103..7ba01de 100644
--- a/framework/db/CDbConnection.php
+++ b/framework/db/CDbConnection.php
@@ -587,6 +587,7 @@ class CDbConnection extends CApplicationComponent
                        'boolean'=>PDO::PARAM_BOOL,
                        'integer'=>PDO::PARAM_INT,
                        'string'=>PDO::PARAM_STR,
+                       'resource'=>PDO::PARAM_LOB,
                        'NULL'=>PDO::PARAM_NULL,
                );
                return isset($map[$type]) ? $map[$type] : PDO::PARAM_STR;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants