Browse Source

HPCC-12854 Support variables in EMBED attributes

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday 10 năm trước cách đây
mục cha
commit
8c289dfe69

+ 24 - 10
ecl/hqlcpp/hqlcpp.cpp

@@ -11627,6 +11627,8 @@ void HqlCppTranslator::buildScriptFunctionDefinition(BuildCtx &funcctx, IHqlExpr
     bool isImport = bodyCode->hasAttribute(importAtom);
 
     funcctx.addQuotedCompound(proto);
+    funcctx.associateExpr(codeContextMarkerExpr, codeContextMarkerExpr);
+    funcctx.associateExpr(globalContextMarkerExpr, globalContextMarkerExpr);
 
     HqlExprArray noargs;
     OwnedHqlExpr getPlugin = bindFunctionCall(language, noargs);
@@ -11639,24 +11641,36 @@ void HqlCppTranslator::buildScriptFunctionDefinition(BuildCtx &funcctx, IHqlExpr
         createParam.append("|EFnoreturn");
     if (formals->numChildren()==0)
         createParam.append("|EFnoparams");
-    StringBuffer attrParam;
+
+    HqlExprArray attrArgs;
     ForEachChild(idx, bodyCode)
     {
         IHqlExpression *child = bodyCode->queryChild(idx);
         if (child->isAttribute() && child->queryName() != languageAtom && child->queryName() != importAtom)
         {
-            attrParam.append(",");
+            StringBuffer attrParam;
+            if (attrArgs.ordinality())
+                attrParam.append(",");
             attrParam.append(child->queryName());
-            StringBuffer attrValue;
-            if (getStringValue(attrValue, child->queryChild(0)).length())
-            {
-                attrParam.append('=');
-                appendStringAsCPP(attrParam, attrValue.length(), attrValue.str(), true);
-            }
+
+            IHqlExpression * value = child->queryChild(0);
+            if (value)
+                attrParam.append("=");
+            attrArgs.append(*createConstant(attrParam));
+            if (value)
+                attrArgs.append(*ensureExprType(value, unknownStringType));
         }
     }
-    if (attrParam.length())
-        createParam.append(",\"").append(attrParam.str()+1).append('"');
+    if (attrArgs.length())
+    {
+        OwnedHqlExpr concat = createUnbalanced(no_concat, unknownStringType, attrArgs);
+        OwnedHqlExpr cast = ensureExprType(concat, unknownVarStringType);
+        OwnedHqlExpr folded = foldHqlExpression(cast);
+        CHqlBoundExpr bound;
+        buildExpr(funcctx, folded, bound);
+        createParam.append(",");
+        generateExprCpp(createParam, bound.expr);
+    }
     else
         createParam.append(",NULL");
     createParam.append(");");

+ 2 - 0
ecl/hqlcpp/hqlttcpp.cpp

@@ -6033,6 +6033,7 @@ IHqlExpression * WorkflowTransformer::transformInternalFunction(IHqlExpression *
     bodyArgs.append(*createExprAttribute(entrypointAtom, LINK(funcNameExpr)));
     OwnedHqlExpr newBody = body->clone(bodyArgs);
     inheritDependencies(newBody);
+    copyDependencies(queryBodyExtra(ecl), queryBodyExtra(newBody));
 
     HqlExprArray funcdefArgs;
     funcdefArgs.append(*LINK(newBody));
@@ -6058,6 +6059,7 @@ IHqlExpression * WorkflowTransformer::transformInternalCall(IHqlExpression * tra
     unwindChildren(paramters, transformed);
     OwnedHqlExpr rebound = createReboundFunction(newFuncDef, paramters);
     inheritDependencies(rebound);
+    copyDependencies(queryBodyExtra(newFuncDef), queryBodyExtra(rebound));
     return rebound.getClear();
 }
 

+ 12 - 0
ecl/regress/issue12854.ecl

@@ -0,0 +1,12 @@
+myuser := 'user' : STORED('db_user'); // DOESN'T WORK
+mypass := 'pass';
+mydb := 'db';
+myserver := 'server';
+
+statusRec := { unsigned id; string status; };
+dataset(statusRec) getAllStatus() := EMBED(mysql : user(myuser),password(mypass),database(mydb),server(myserver))
+	SELECT doc_id, status FROM etl_status;
+ENDEMBED;
+
+
+getAllStatus();

+ 6 - 3
testing/regress/ecl/mysqlembed.ecl

@@ -19,6 +19,9 @@
 
 IMPORT mysql;
 
+myUser := 'rchapman' : stored('myUser');
+myDb := 'test' : stored('myDb');
+
 childrec := RECORD
    string name,
    integer4 value { default(99999) },
@@ -50,15 +53,15 @@ create() := EMBED(mysql : user('rchapman'),database('test'))
   CREATE TABLE tbl1 ( name VARCHAR(20), value INT, boolval TINYINT, r8 DOUBLE, r4 FLOAT, d BLOB, ddd DECIMAL(10,2), u1 VARCHAR(10), u2 VARCHAR(10) );
 ENDEMBED;
 
-initialize(dataset(childrec) values) := EMBED(mysql : user('rchapman'),database('test'))
+initialize(dataset(childrec) values) := EMBED(mysql : user(myUser),database(myDb))
   INSERT INTO tbl1 values (?, ?, ?, ?, ?, ?, ?, ?, ?);
 ENDEMBED;
 
-initializeNulls() := EMBED(mysql : user('rchapman'),database('test'))
+initializeNulls() := EMBED(mysql : user('rchapman'),database(myDb))
   INSERT INTO tbl1 (name) values ('nulls');
 ENDEMBED;
 
-initializeUtf8() := EMBED(mysql : user('rchapman'),database('test'))
+initializeUtf8() := EMBED(mysql : user(myUser),database('test'))
   INSERT INTO tbl1 values ('utf8test', 1, 1, 1.2, 3.4, 'aa55aa55', 1234567.89, 'Straße', 'Straße');
 ENDEMBED;