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

Fix #1534 #1566

Merged
merged 4 commits into from Nov 18, 2013
Merged

Fix #1534 #1566

merged 4 commits into from Nov 18, 2013

Conversation

ghost
Copy link

@ghost ghost commented Nov 18, 2013

See #1534

phalcon pushed a commit that referenced this pull request Nov 18, 2013
@phalcon phalcon merged commit 6589765 into phalcon:1.3.0 Nov 18, 2013
@phalcon
Copy link
Collaborator

phalcon commented Nov 18, 2013

Thanks, could you please submit a fix for 2.0?

@ghost ghost deleted the issue-1534 branch November 19, 2013 06:11
@ghost
Copy link
Author

ghost commented Nov 19, 2013

I get a compiler error from zephir:

CompilerException: Cannot operate variable('int') with 'double' in /home/vladimir/workspace/cphalcon/phalcon/image/adapter/gd.zep on line 131

            let reduction_width  = round(width  * 1.1);
        ---------------------------------------------^

at Library/Operators/Arithmetical/BaseOperator.php(248)
#0 Library/Expression.php(1052): ArithmeticalBaseOperator->compile(Array, Object(CompilationContext))
#1 Library/Call.php(171): Expression->compile(Object(CompilationContext))
#2 Library/Call.php(296): Call->getResolvedParamsAsExpr(Array, Object(CompilationContext), Array, true)
#3 Library/FunctionCall.php(281): Call->getReadOnlyResolvedParams(Array, Object(CompilationContext), Array)
#4 Library/FunctionCall.php(514): FunctionCall->_callNormal(Array, Object(CompilationContext))
#5 Library/Expression.php(948): FunctionCall->compile(Object(Expression), Object(CompilationContext))
#6 Library/Statements/LetStatement.php(2085): Expression->compile(Object(CompilationContext))
#7 Library/StatementsBlock.php(95): LetStatement->compile(Object(CompilationContext))
#8 Library/Statements/IfStatement.php(77): StatementsBlock->compile(Object(CompilationContext), false)
#9 Library/StatementsBlock.php(107): IfStatement->compile(Object(CompilationContext))
#10 Library/Statements/IfStatement.php(77): StatementsBlock->compile(Object(CompilationContext), false)
#11 Library/StatementsBlock.php(107): IfStatement->compile(Object(CompilationContext))
#12 Library/ClassMethod.php(934): StatementsBlock->compile(Object(CompilationContext))
#13 Library/ClassDefinition.php(708): ClassMethod->compile(Object(CompilationContext))
#14 Library/CompilerFile.php(110): ClassDefinition->compile(Object(CompilationContext))
#15 Library/CompilerFile.php(551): CompilerFile->compileClass(Object(CompilationContext), 'Phalcon\Image\A...', Array)
#16 Library/Compiler.php(400): CompilerFile->compile(Object(Compiler), Object(StringsManager))
#17 Library/Compiler.php(419): Compiler->generate(Object(CommandCompile))
#18 Library/Commands/Abstract.php(83): Compiler->compile(Object(CommandCompile))
#19 Library/Bootstrap.php(155): CommandAbstract->execute(Object(Config), Object(Logger))
#20 compiler.php(76): Bootstrap::boot()
#21 {main}

@ghost
Copy link
Author

ghost commented Nov 19, 2013

This is the patch for 2.0:

diff --git a/phalcon/mvc/model.zep b/phalcon/mvc/model.zep
index 4d057b6..6e387e0 100644
--- a/phalcon/mvc/model.zep
+++ b/phalcon/mvc/model.zep
@@ -880,7 +880,7 @@ abstract class Model implements Phalcon\Mvc\ModelInterface, Phalcon\Mvc\Model\Re
                int numberEmpty, numberPrimary;
                var uniqueParams, uniqueTypes, uniqueKey, columnMap, primaryKeys,
                        wherePk, field, attributeField, value, bindDataTypes,
-                       joinWhere, num, type, schema, source;
+                       joinWhere, num, type, schema, source, v, seen_rawvalue;

                let uniqueParams = null,
                        uniqueTypes = null;
@@ -938,19 +938,24 @@ abstract class Model implements Phalcon\Mvc\ModelInterface, Phalcon\Mvc\Model\Re
                                        if empty value {
                                                let numberEmpty++;
                                        }
-                                       let uniqueParams[] = value;
-
+                                       let v = value;
                                } else {
-                                       let uniqueParams[] = null,
-                                               numberEmpty++;
+                                       let v = null;
+                                       let numberEmpty++;
                                }

                                if !fetch type, bindDataTypes[field] {
                                        throw new Phalcon\Mvc\Model\Exception("Column '" . field . "' isn't part of the table columns");
                                }
-
-                               let uniqueTypes[] = type,
-                                       wherePk[] = connection->escapeIdentifier(field) . " = ?";
+                               
+                               if is_object(v) && v instanceof "Phalcon\Db\RawValue" {
+                                       let wherePk[] = connection->escapeIdentifier(field) . " = " . v;
+                                       let seen_rawvalue = 1;
+                               }
+                               else {
+                                       let uniqueTypes[] = type,
+                                               wherePk[] = connection->escapeIdentifier(field) . " = ?";
+                               }
                        }

                        /**
@@ -965,8 +970,11 @@ abstract class Model implements Phalcon\Mvc\ModelInterface, Phalcon\Mvc\Model\Re
                        /**
                         * The unique key is composed of 3 parts _uniqueKey, uniqueParams, uniqueTypes
                         */
-                       let this->_uniqueKey = joinWhere,
-                               this->_uniqueParams = uniqueParams,
+                       if !seen_rawvalue {
+                               let this->_uniqueKey = joinWhere;
+                       }
+
+                       let this->_uniqueParams = uniqueParams,
                                this->_uniqueTypes = uniqueTypes,
                                uniqueKey = joinWhere;
                }

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

Successfully merging this pull request may close these issues.

2 participants