{"record":{"id":"427c8c2f2a1f0471","repo":"phalcon/cphalcon","slug":"invalid-sql-expression","errorCode":null,"errorMessage":"Invalid SQL expression","messagePattern":"Invalid SQL expression","errorType":"exception","errorClass":"InvalidSqlExpression","httpStatus":null,"severity":"error","filePath":"phalcon/Db/Dialect.zep","lineNumber":270,"sourceCode":"         */\n        if fetch columnAlias, columnExpression[\"sqlAlias\"] || fetch columnAlias, columnExpression[\"alias\"] {\n            return this->prepareColumnAlias(column, columnAlias, escapeChar);\n        }\n\n        return this->prepareColumnAlias(column, null, escapeChar);\n    }\n\n    /**\n     * Transforms an intermediate representation for an expression into a database system valid expression\n     */\n    public function getSqlExpression( array expression, string escapeChar = null,  array bindCounts = []) -> string\n    {\n        int i;\n        var type, times, postTimes, rawValue, value, nestedDefinition;\n        array placeholders;\n\n        if unlikely !fetch type, expression[\"type\"] {\n            throw new InvalidSqlExpression();\n        }\n\n        switch type {\n            /**\n             * Resolve scalar column expressions\n             */\n            case \"scalar\":\n                return this->getSqlExpressionScalar(\n                    expression,\n                    escapeChar,\n                    bindCounts\n                );\n\n            /**\n             * Resolve object expressions\n             */\n            case \"object\":\n                return this->getSqlExpressionObject(","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Db/Dialect.zep#L252-L288","documentation":"Phalcon\\Db\\Dialect::getSqlExpression() compiles intermediate-representation (IR) expression arrays - the nodes the PHQL compiler produces - into SQL. Every node must carry a 'type' discriminator naming its shape ('scalar', 'binary-op', 'functionCall', ...). An array without 'type' cannot be compiled and throws InvalidSqlExpression.","triggerScenarios":"Calling $dialect->getSqlExpression(['value' => 'x']) directly with no 'type' key; hand-built IR fed to the dialect or select builders; nested expression arrays where a sub-node lacks 'type'; middleware that mutates expression arrays and drops the key.","commonSituations":"Advanced usage extending the dialect or hand-building IR for expressions; debugging PHQL by inspecting and re-feeding compiled arrays; custom query builders that construct nodes without a type-first discipline.","solutions":["Give the node a valid 'type' key matching one of the cases in Dialect::getSqlExpression().","Prefer Phalcon\\Db\\RawValue or PHQL itself instead of hand-crafting IR arrays.","If you must build IR, wrap node construction in a helper that always sets 'type' first."],"exampleFix":"// before\n$sql = $dialect->getSqlExpression(['value' => 'robots.name']); // throws InvalidSqlExpression\n\n// after\n$sql = $dialect->getSqlExpression([\n    'type'   => 'qualified',\n    'name'   => 'name',\n    'domain' => 'robots',\n]);","handlingStrategy":"validation","validationCode":"if (!isset($expression['type'])) {\n    throw new InvalidArgumentException('IR expression node requires a \"type\" discriminator');\n}\n$sql = $dialect->getSqlExpression($expression);","typeGuard":"function isTypedExpressionNode(array $node): bool\n{\n    return isset($node['type']) && is_string($node['type']);\n}","tryCatchPattern":null,"preventionTips":["Avoid calling getSqlExpression directly - use PHQL or Phalcon\\Db\\RawValue.","When debugging IR, dump the array and verify every nested node has 'type'.","Centralize IR construction in tested helpers that set 'type' first."],"tags":["dialect","phql","expression","internal-api","phalcon-db"],"backgroundTag":"invalid-query-expression","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}