Skip to content

Commit

Permalink
Merge pull request #1 from janborup/main
Browse files Browse the repository at this point in the history
SqlToXml, New parameter: ExcludeEmtpyValues
  • Loading branch information
aelassas authored Nov 1, 2022
2 parents a8072a7 + 9e8d2a3 commit 190b9aa
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 10 deletions.
2 changes: 1 addition & 1 deletion samples/net/Wexflow/TasksSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"SpeechToText": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""} ],
"Sql": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "type", "Required": true, "Type": "list", "List": ["sqlserver", "access", "oracle", "mysql", "sqlite", "postgresql", "teradata", "odbc"], "DefaultValue": ""}, {"Name": "connectionString", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "sql", "Required": false, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "smbComputerName", "Required": false, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "smbDomain", "Required": false, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "smbUsername", "Required": false, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "smbPassword", "Required": false, "Type": "string", "List": [], "DefaultValue": ""} ],
"SqlToCsv": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "type", "Required": true, "Type": "list", "List": ["sqlserver", "access", "oracle", "mysql", "sqlite", "postgresql", "teradata", "odbc"], "DefaultValue": ""}, {"Name": "connectionString", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "sql", "Required": false, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "doNotGenerateFilesIfEmpty", "Required": false, "Type": "bool", "List": [], "DefaultValue": ""} ],
"SqlToXml": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "type", "Required": true, "Type": "list", "List": ["sqlserver", "access", "oracle", "mysql", "sqlite", "postgresql", "teradata", "odbc"], "DefaultValue": ""}, {"Name": "connectionString", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "sql", "Required": false, "Type": "string", "List": [], "DefaultValue": ""} ],
"SqlToXml": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "type", "Required": true, "Type": "list", "List": ["sqlserver", "access", "oracle", "mysql", "sqlite", "postgresql", "teradata", "odbc"], "DefaultValue": ""}, {"Name": "connectionString", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "sql", "Required": false, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "excludeEmptyValues", "Required": false, "Type": "bool", "List": [], "DefaultValue": ""} ],
"SshCmd": [ {"Name": "host", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "port", "Required": false, "Type": "int", "List": [], "DefaultValue": "22"}, {"Name": "username", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "password", "Required": true, "Type": "password", "List": [], "DefaultValue": ""}, {"Name": "cmd", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "timeout", "Required": false, "Type": "int", "List": [], "DefaultValue": "60"} ],
"SubWorkflow": [ {"Name": "id", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "mode", "Required": false, "Type": "list", "List": ["sync", "async"], "DefaultValue": "sync"}, {"Name": "action", "Required": false, "Type": "list", "List": ["start", "stop", "approve", "reject"], "DefaultValue": "start"} ],
"Tar": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "zipFileName", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "smbComputerName", "Required": false, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "smbDomain", "Required": false, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "smbUsername", "Required": false, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "smbPassword", "Required": false, "Type": "string", "List": [], "DefaultValue": ""} ],
Expand Down
2 changes: 1 addition & 1 deletion samples/netcore/linux/Wexflow/TasksSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"Slack": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "token", "Required": true, "Type": "string", "List": [], "DefaultValue": ""} ],
"Sql": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "type", "Required": true, "Type": "list", "List": ["sqlserver", "access", "oracle", "mysql", "sqlite", "postgresql", "teradata", "odbc"], "DefaultValue": ""}, {"Name": "connectionString", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "sql", "Required": false, "Type": "string", "List": [], "DefaultValue": ""} ],
"SqlToCsv": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "type", "Required": true, "Type": "list", "List": ["sqlserver", "access", "oracle", "mysql", "sqlite", "postgresql", "teradata", "odbc"], "DefaultValue": ""}, {"Name": "connectionString", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "sql", "Required": false, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "doNotGenerateFilesIfEmpty", "Required": false, "Type": "bool", "List": [], "DefaultValue": ""} ],
"SqlToXml": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "type", "Required": true, "Type": "list", "List": ["sqlserver", "access", "oracle", "mysql", "sqlite", "postgresql", "teradata", "odbc"], "DefaultValue": ""}, {"Name": "connectionString", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "sql", "Required": false, "Type": "string", "List": [], "DefaultValue": ""} ],
"SqlToXml": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "type", "Required": true, "Type": "list", "List": ["sqlserver", "access", "oracle", "mysql", "sqlite", "postgresql", "teradata", "odbc"], "DefaultValue": ""}, {"Name": "connectionString", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "sql", "Required": false, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "excludeEmptyValues", "Required": false, "Type": "bool", "List": [], "DefaultValue": ""} ],
"SshCmd": [ {"Name": "host", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name":"port", "Required": false, "Type": "int", "List": [], "DefaultValue": "22"}, {"Name": "username", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "password", "Required": true, "Type": "password", "List": [], "DefaultValue": ""}, {"Name": "cmd", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "timeout", "Required": false, "Type": "int", "List": [], "DefaultValue": "60"} ],
"SubWorkflow": [ {"Name": "id", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "mode", "Required": false, "Type": "list", "List": ["sync", "async"], "DefaultValue": "sync"}, {"Name": "action", "Required": false, "Type": "list", "List": ["start", "stop", "approve", "reject"], "DefaultValue": "start"} ],
"Tar": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "zipFileName", "Required": true, "Type": "string", "List": [], "DefaultValue": ""} ],
Expand Down
2 changes: 1 addition & 1 deletion samples/netcore/macos/Wexflow/TasksSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"Slack": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "token", "Required": true, "Type": "string", "List": [], "DefaultValue": ""} ],
"Sql": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "type", "Required": true, "Type": "list", "List": ["sqlserver", "access", "oracle", "mysql", "sqlite", "postgresql", "teradata", "odbc"], "DefaultValue": ""}, {"Name": "connectionString", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "sql", "Required": false, "Type": "string", "List": [], "DefaultValue": ""} ],
"SqlToCsv": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "type", "Required": true, "Type": "list", "List": ["sqlserver", "access", "oracle", "mysql", "sqlite", "postgresql", "teradata", "odbc"], "DefaultValue": ""}, {"Name": "connectionString", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "sql", "Required": false, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "doNotGenerateFilesIfEmpty", "Required": false, "Type": "bool", "List": [], "DefaultValue": ""} ],
"SqlToXml": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "type", "Required": true, "Type": "list", "List": ["sqlserver", "access", "oracle", "mysql", "sqlite", "postgresql", "teradata", "odbc"], "DefaultValue": ""}, {"Name": "connectionString", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "sql", "Required": false, "Type": "string", "List": [], "DefaultValue": ""} ],
"SqlToXml": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "type", "Required": true, "Type": "list", "List": ["sqlserver", "access", "oracle", "mysql", "sqlite", "postgresql", "teradata", "odbc"], "DefaultValue": ""}, {"Name": "connectionString", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "sql", "Required": false, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "excludeEmptyValues", "Required": false, "Type": "bool", "List": [], "DefaultValue": ""} ],
"SshCmd": [ {"Name": "host", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name":"port", "Required": false, "Type": "int", "List": [], "DefaultValue": "22"}, {"Name": "username", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "password", "Required": true, "Type": "password", "List": [], "DefaultValue": ""}, {"Name": "cmd", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "timeout", "Required": false, "Type": "int", "List": [], "DefaultValue": "60"} ],
"SubWorkflow": [ {"Name": "id", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "mode", "Required": false, "Type": "list", "List": ["sync", "async"], "DefaultValue": "sync"}, {"Name": "action", "Required": false, "Type": "list", "List": ["start", "stop", "approve", "reject"], "DefaultValue": "start"} ],
"Tar": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "zipFileName", "Required": true, "Type": "string", "List": [], "DefaultValue": ""} ],
Expand Down
2 changes: 1 addition & 1 deletion samples/netcore/windows/Wexflow/TasksSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"Slack": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "token", "Required": true, "Type": "string", "List": [], "DefaultValue": ""} ],
"Sql": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "type", "Required": true, "Type": "list", "List": ["sqlserver", "access", "oracle", "mysql", "sqlite", "postgresql", "teradata", "odbc"], "DefaultValue": ""}, {"Name": "connectionString", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "sql", "Required": false, "Type": "string", "List": [], "DefaultValue": ""} ],
"SqlToCsv": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "type", "Required": true, "Type": "list", "List": ["sqlserver", "access", "oracle", "mysql", "sqlite", "postgresql", "teradata", "odbc"], "DefaultValue": ""}, {"Name": "connectionString", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "sql", "Required": false, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "doNotGenerateFilesIfEmpty", "Required": false, "Type": "bool", "List": [], "DefaultValue": ""} ],
"SqlToXml": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "type", "Required": true, "Type": "list", "List": ["sqlserver", "access", "oracle", "mysql", "sqlite", "postgresql", "teradata", "odbc"], "DefaultValue": ""}, {"Name": "connectionString", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "sql", "Required": false, "Type": "string", "List": [], "DefaultValue": ""} ],
"SqlToXml": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "type", "Required": true, "Type": "list", "List": ["sqlserver", "access", "oracle", "mysql", "sqlite", "postgresql", "teradata", "odbc"], "DefaultValue": ""}, {"Name": "connectionString", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "sql", "Required": false, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "excludeEmptyValues", "Required": false, "Type": "bool", "List": [], "DefaultValue": ""} ],
"SshCmd": [ {"Name": "host", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name":"port", "Required": false, "Type": "int", "List": [], "DefaultValue": "22"}, {"Name": "username", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "password", "Required": true, "Type": "password", "List": [], "DefaultValue": ""}, {"Name": "cmd", "Required": true, "Type": "string", "List": [], "DefaultValue": ""}, {"Name": "timeout", "Required": false, "Type": "int", "List": [], "DefaultValue": "60"} ],
"SubWorkflow": [ {"Name": "id", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "mode", "Required": false, "Type": "list", "List": ["sync", "async"], "DefaultValue": "sync"}, {"Name": "action", "Required": false, "Type": "list", "List": ["start", "stop", "approve", "reject"], "DefaultValue": "start"} ],
"Tar": [ {"Name": "selectFiles", "Required": true, "Type": "int", "List": [], "DefaultValue": ""}, {"Name": "zipFileName", "Required": true, "Type": "string", "List": [], "DefaultValue": ""} ],
Expand Down
35 changes: 32 additions & 3 deletions src/net/Wexflow.Tasks.SqlToXml/SqlToXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
using Teradata.Client.Provider;
using Wexflow.Core;
using System.Data.Odbc;
using System.Text.RegularExpressions;
using System.Data.SqlTypes;

namespace Wexflow.Tasks.SqlToXml
{
Expand All @@ -38,6 +40,7 @@ public class SqlToXml : Task
public string SmbDomain { get; private set; }
public string SmbUsername { get; private set; }
public string SmbPassword { get; private set; }
public bool ExcludeEmptyValues { get; private set; }

public SqlToXml(XElement xe, Workflow wf) : base(xe, wf)
{
Expand All @@ -48,6 +51,7 @@ public SqlToXml(XElement xe, Workflow wf) : base(xe, wf)
SmbDomain = GetSetting("smbDomain");
SmbUsername = GetSetting("smbUsername");
SmbPassword = GetSetting("smbPassword");
ExcludeEmptyValues = bool.Parse(GetSetting("excludeEmptyValues", "false"));
}

public override TaskStatus Run()
Expand Down Expand Up @@ -231,17 +235,42 @@ private void ConvertToXml(DbConnection connection, DbCommand command)

foreach (var column in columns)
{
xobject.Add(new XElement("Cell"
, new XAttribute("column", SecurityElement.Escape(column))
, new XAttribute("value", SecurityElement.Escape(reader[column].ToString()))));
string xmlvalue = CleanInvalidXmlChars(reader[column].ToString());
var columntype = reader[column].GetType();
int number;
decimal decnumber;
if (
(columntype == typeof(Int32) && int.TryParse(xmlvalue, out number) && number == 0) ||
(columntype == typeof(Decimal) && decimal.TryParse(xmlvalue, out decnumber) && decnumber == 0) ||
(columntype == typeof(DateTime) && (Convert.ToDateTime(xmlvalue) == SqlDateTime.MinValue || xmlvalue == "01-01-1900 00:00:00"))
)
{
xmlvalue = "";
}
if (!ExcludeEmptyValues || !string.IsNullOrEmpty(xmlvalue))
{
xobject.Add(new XElement("Cell"
, new XAttribute("column", SecurityElement.Escape(column))
, new XAttribute("value", SecurityElement.Escape(xmlvalue))));
}
}
xobjects.Add(xobject);
}

xdoc.Add(xobjects);
xdoc.Save(destPath);
Files.Add(new FileInf(destPath, Id));
InfoFormat("XML file generated: {0}", destPath);
}
}

public static string CleanInvalidXmlChars(string text)
{
// From xml spec valid chars:
// #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
// any Unicode character, excluding the surrogate blocks, FFFE, and FFFF.
string re = @"[^\x09\x0A\x0D\x20-\xD7FF\xE000-\xFFFD\x10000-x10FFFF]";
return Regex.Replace(text, re, "");
}
}
}
4 changes: 3 additions & 1 deletion src/net/Wexflow.Tasks.SqlToXml/SqlToXml.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
<Setting name="connectionString" value="$string" />
<!-- Optional. It is possible to execute an SQL script through this option.-->
<Setting name="sql" value="$string" />

<!-- Optional and defaults to false. If set to true value i empty or zero, dont include node. If set to false, all nodes is included.-->
<Setting name="excludeEmptyValues" value="$bool" />

<!-- Optional. Samba computer name. -->
<Setting name="smbComputerName" value="$string" />
<!-- Optional. Samba domain name. -->
Expand Down
Loading

0 comments on commit 190b9aa

Please sign in to comment.