Create a compound statement to initialize returning parameters.
| 10019 | |
| 10020 | // Create a compound statement to initialize returning parameters. |
| 10021 | static StmtNode* dsqlNullifyReturning(DsqlCompilerScratch* dsqlScratch, StmtNode* input) |
| 10022 | { |
| 10023 | if (dsqlScratch->isPsql()) |
| 10024 | return input; |
| 10025 | |
| 10026 | auto& pool = dsqlScratch->getPool(); |
| 10027 | ReturningClause* returning; |
| 10028 | |
| 10029 | if (auto eraseNode = nodeAs<EraseNode>(input)) |
| 10030 | returning = eraseNode->dsqlReturning; |
| 10031 | else if (auto modifyNode = nodeAs<ModifyNode>(input)) |
| 10032 | returning = modifyNode->dsqlReturning; |
| 10033 | else if (auto storeNode = nodeAs<StoreNode>(input)) |
| 10034 | returning = storeNode->dsqlReturning; |
| 10035 | else |
| 10036 | { |
| 10037 | fb_assert(false); |
| 10038 | returning = nullptr; |
| 10039 | } |
| 10040 | |
| 10041 | if (!returning) |
| 10042 | return input; |
| 10043 | |
| 10044 | // If this is a RETURNING in DSQL, we need to initialize the output |
| 10045 | // parameters with NULL, to return in case of empty resultset in some |
| 10046 | // circumstances (for example WHERE CURRENT OF ... RETURNING). |
| 10047 | |
| 10048 | const auto nullAssign = FB_NEW_POOL(pool) CompoundStmtNode(pool); |
| 10049 | auto nullPtr = nullAssign->statements.getBuffer(returning->first->items.getCount()); |
| 10050 | |
| 10051 | for (auto& retPtr : returning->second->items) |
| 10052 | { |
| 10053 | AssignmentNode* assign = FB_NEW_POOL(pool) AssignmentNode(pool); |
| 10054 | assign->asgnFrom = NullNode::instance(); |
| 10055 | assign->asgnTo = retPtr; |
| 10056 | *nullPtr++ = assign; |
| 10057 | } |
| 10058 | |
| 10059 | // Return a compound statement with the initialization and the original statement. |
| 10060 | const auto list = FB_NEW_POOL(pool) CompoundStmtNode(pool); |
| 10061 | list->statements.add(nullAssign); |
| 10062 | list->statements.add(input); |
| 10063 | return list; |
| 10064 | } |
| 10065 | |
| 10066 | // Check that a field is named only once in INSERT or UPDATE statements. |
| 10067 | static void dsqlFieldAppearsOnce(const Array<NestConst<ValueExprNode> >& values, const char* command) |
no test coverage detected