public void TestInterprete_Fun_SqlULPad() { var log = new BdoLog(); string fluentScript = DbFluent.LeftPadding(DbFluent.Field("RegionalDirectorateId"), 10, DbFluent.Text("A")); var scriptVariableSet = new ScriptVariableSet(); scriptVariableSet.SetValue(VarSetDb.__DbBuilder, DbQueryFactory.CreateQueryBuilder <DbQueryBuilder_PostgreSql>(GlobalVariables.AppHost)); string result = GlobalVariables.AppHost.Scope.Interpreter.Evaluate(fluentScript, DataExpressionKind.Script, scriptVariableSet, log: log)?.ToString(); string expectedResult = @"lpad(""RegionalDirectorateId"", 10, 'A')"; string xml = ""; if (log.HasErrorsOrExceptions()) { xml = ". Result was '" + log.ToXml(); } Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml); }
public void SimpleInsertWithValues() { var log = new BdoLog(); string expectedResult = @"insert into ""Mdm"".""Employee"" (""Code"", ""ByteArrayField"", ""DoubleField"", ""DateTimeField"", ""LongField"") " + "(values ('" + _employee.Code.Replace("'", "''") + "'" + ", '" + _employee.ByteArrayField.ToString(DataValueTypes.ByteArray).Replace("'", "''") + "'" + ", " + _employee.DoubleField.ToString(DataValueTypes.Number) + ", '" + _employee.DateTimeField.ToString(DataValueTypes.Date) + "'" + ", " + _employee.LongField.ToString(DataValueTypes.Long) + @"))" + @" returning ""Mdm"".""Employee"".""EmployeeId"""; string result = _dbConnector.CreateCommandText(_model.InsertEmployee1(_employee), log: log); string xml = ""; if (log.HasErrorsOrExceptions()) { xml = ". Result was '" + log.ToXml(); } Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml); }
public void TestInterprete_Fun_SqlIf() { string value = null; string script1 = DbFluent.If(DbFluent.IsNull(value), DbFluent.Field("RegionalDirectorateId"), DbFluent.Field("RegionalDirectorateId2")); string expectedResult = @"case when (null is null) then ""RegionalDirectorateId"" else ""RegionalDirectorateId2"" end"; var log = new BdoLog(); var scriptVariableSet = new ScriptVariableSet(); scriptVariableSet.SetValue(VarSetDb.__DbBuilder, DbQueryFactory.CreateQueryBuilder <DbQueryBuilder_PostgreSql>(GlobalVariables.AppHost)); string result = GlobalVariables.AppHost.Scope.Interpreter.Evaluate(script1, DataExpressionKind.Script, scriptVariableSet, log: log)?.ToString(); string xml = ""; if (log.HasErrorsOrExceptions()) { xml = ". Result was '" + log.ToXml(); } Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml); }
public void TestInterprete_Fun_SqlEncode() { string script = DbFluent.EncodeBase64(DbFluent.Text("ABCDE")); string expectedResult = @"encode('ABCDE', 'base64')"; var log = new BdoLog(); var scriptVariableSet = new ScriptVariableSet(); scriptVariableSet.SetValue(VarSetDb.__DbBuilder, DbQueryFactory.CreateQueryBuilder <DbQueryBuilder_PostgreSql>(GlobalVariables.AppHost)); string result = GlobalVariables.AppHost.Scope.Interpreter.Evaluate(script, DataExpressionKind.Script, scriptVariableSet, log: log)?.ToString(); string xml = ""; if (log.HasErrorsOrExceptions()) { xml = ". Result was '" + log.ToXml(); } Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml); script = DbFluent.DecodeBase64(DbFluent.Field("ABCDE")); expectedResult = @"decode(""ABCDE"", 'base64')"; log = new BdoLog(); scriptVariableSet = new ScriptVariableSet(); scriptVariableSet.SetValue(VarSetDb.__DbBuilder, DbQueryFactory.CreateQueryBuilder <DbQueryBuilder_PostgreSql>(GlobalVariables.AppHost)); result = GlobalVariables.AppHost.Scope.Interpreter.Evaluate(script, DataExpressionKind.Script, scriptVariableSet, log: log)?.ToString(); xml = ""; if (log.HasErrorsOrExceptions()) { xml = ". Result was '" + log.ToXml(); } Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml); }
public void TestSqlIfNull() { var expression = DbFluent.Eq( DbFluent.Field("fieldA"), DbFluent.IfNull( DbFluent.Parameter("myText"), DbFluent.Field("fieldA"))); var log = new BdoLog(); string expectedResult = @"""fieldA""=coalesce(|*|p:myText|*|, ""fieldA"")"; var result = _appHost.Interpreter.Evaluate <string>( expression, new ScriptVariableSet().SetDbBuilder(new DbQueryBuilder_PostgreSql()), log: log); var xml = ""; if (log.HasErrorsOrExceptions()) { xml = ". Result was '" + log.ToXml(); } Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml); }