Skip to content

Commit

Permalink
v2023.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kubekin2 committed Dec 8, 2022
1 parent 39b177d commit b8a52b2
Show file tree
Hide file tree
Showing 29 changed files with 362 additions and 237 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Stimulsoft.Reports.JS
Version: 2022.4.5
Build date: 2022.11.17
Version: 2023.1.1
Build date: 2022.12.07
License: https://www.stimulsoft.com/en/licensing/reports
*/

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Stimulsoft.Reports.JS
Version: 2022.4.5
Build date: 2022.11.17
Version: 2023.1.1
Build date: 2022.12.07
License: https://www.stimulsoft.com/en/licensing/reports
*/

Expand All @@ -27,8 +27,8 @@

public class JSDataAdapter {

public static final String handlerVersion = "2022.4.5";
public static final String adapterVersion = "2022.4.5";
public static final String handlerVersion = "2023.1.1";
public static final String adapterVersion = "2023.1.1";
public static final boolean checkVersion = true;

private static final List<String> USERS_KEYS = Arrays.asList(
Expand Down
60 changes: 10 additions & 50 deletions NetCoreDataAdapters/DataAdaptersController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Stimulsoft.Reports.JS
Version: 2022.4.5
Build date: 2022.11.17
Version: 2023.1.1
Build date: 2022.12.07
License: https://www.stimulsoft.com/en/licensing/reports
*/
using FirebirdSql.Data.FirebirdClient;
Expand Down Expand Up @@ -61,9 +61,15 @@ public class ParameterJson
{
public string Name { get; set; }

public string Value { get; set; }
public object Value { get; set; }

public string TypeGroup { get; set; }

public string TypeName { get; set; }

public int TypeValue { get; set; }

public int Size { get; set; }
}

[Route("/DataAdapters")]
Expand Down Expand Up @@ -114,8 +120,6 @@ private async Task ProcessRequest()
}
else
{
command.QueryString = ApplyQueryParameters(command.QueryString, command.Parameters, command.EscapeQueryParameters);

switch (command.Database)
{
case "MySQL": result = SQLAdapter.Process(command, new MySqlConnection(command.ConnectionString)); break;
Expand All @@ -137,7 +141,7 @@ private async Task ProcessRequest()
result.Notice = e.Message;
}

result.HandlerVersion = "2022.4.5";
result.HandlerVersion = "2023.1.1";
result.CheckVersion = true;

var contentType = "application/json";
Expand All @@ -156,50 +160,6 @@ private async Task ProcessRequest()
await Response.CompleteAsync();
}

private string ApplyQueryParameters(string baseSqlCommand, ParameterJson[] parameters, bool escapeQueryParameters)
{
if (baseSqlCommand == null || baseSqlCommand.IndexOf("@") < 0) return baseSqlCommand;

var result = "";
while (baseSqlCommand.IndexOf("@") >= 0 && parameters != null && parameters.Length > 0)
{
result += baseSqlCommand.Substring(0, baseSqlCommand.IndexOf("@"));
baseSqlCommand = baseSqlCommand.Substring(baseSqlCommand.IndexOf("@") + 1);

var parameterName = "";

var regex = new Regex(@"[a-zA-Z0-9_-]");
while (baseSqlCommand.Length > 0)
{
string chr = baseSqlCommand[0].ToString();
if (regex.IsMatch(chr))
{
parameterName += chr;
baseSqlCommand = baseSqlCommand.Substring(1);
}
else break;
}

var parameter = parameters.ToList().Find(p => p.Name.ToLowerInvariant() == parameterName.ToLowerInvariant());
if (parameter != null)
{
if (parameter.TypeGroup != "number")
{
if (escapeQueryParameters)
result += "'" + parameter.Value.Replace("\\", "\\\\").Replace("'", "\\'").Replace("\"", "\\\"") + "'";
else
result += "'" + parameter.Value + "'";
}
else
result += parameter.Value;
}
else
result += "@" + parameterName;
}

return result + baseSqlCommand;
}

private static string ROT13(string input)
{
return string.Join("", input.Select(x => char.IsLetter(x) ? (x >= 65 && x <= 77) || (x >= 97 && x <= 109) ? (char)(x + 13) : (char)(x - 13) : x));
Expand Down
7 changes: 3 additions & 4 deletions NetCoreDataAdapters/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
Expand All @@ -9,18 +9,17 @@
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"commandName": "IISExpress",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"NetCoreDataAdapters": {
"commandName": "Project",
"dotnetRunMessages": "true",
"applicationUrl": "https://localhost:44355;http://localhost:17186",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
}
45 changes: 37 additions & 8 deletions NetCoreDataAdapters/SQLAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Stimulsoft.Reports.JS
Version: 2022.4.5
Build date: 2022.11.17
Version: 2023.1.1
Build date: 2022.12.07
License: https://www.stimulsoft.com/en/licensing/reports
*/
using FirebirdSql.Data.FirebirdClient;
Expand All @@ -13,6 +13,8 @@
using System.Data.Common;
using Microsoft.Data.SqlClient;
using System.IO;
using System.Data;
using System.Text.Json;

namespace NetCoreDataAdapters
{
Expand All @@ -24,7 +26,7 @@ public class SQLAdapter

private static Result End(Result result)
{
result.AdapterVersion = "2022.4.5";
result.AdapterVersion = "2023.1.1";
try
{
if (reader != null) reader.Close();
Expand Down Expand Up @@ -58,17 +60,28 @@ private static Result Connect()

private static Result OnConnect()
{
if (!String.IsNullOrEmpty(command.QueryString)) return Query(command.QueryString);
if (!String.IsNullOrEmpty(command.QueryString)) return Query();
else return End(new Result { Success = true });
}

private static Result Query(string queryString)
private static Result Query()
{
try
{
var sqlCommand = connection.CreateCommand();
sqlCommand.CommandText = queryString;
sqlCommand.CommandType = command.Command == "Execute" ? CommandType.StoredProcedure : CommandType.Text;
sqlCommand.CommandText = command.QueryString;

foreach (var parameter in command.Parameters)
{
var sqlParameter = sqlCommand.CreateParameter();
sqlParameter.ParameterName = parameter.Name;
sqlParameter.DbType = (DbType)parameter.TypeValue;
sqlParameter.Size = parameter.Size;
if (sqlParameter.DbType == DbType.Decimal) sqlParameter.Precision = (byte)parameter.Size;
sqlParameter.Value = GetValue((JsonElement)parameter.Value, parameter.TypeGroup);
sqlCommand.Parameters.Add(sqlParameter);
}
reader = sqlCommand.ExecuteReader();
return OnQuery();
}
Expand Down Expand Up @@ -108,8 +121,8 @@ private static Result OnQuery()
value = reader.GetValue(index);
}
}
catch
{
catch
{
value = null;
}

Expand Down Expand Up @@ -356,6 +369,22 @@ private static string GetType(string dbType)
return "string";
}

private static object GetValue(JsonElement json, string type)
{
try
{
switch (type)
{
case "string": return json.GetString();
case "number": return json.GetDecimal();
}
}
catch
{
}
return json.GetString();
}

public static Result Process(CommandJson command, DbConnection connection)
{
SQLAdapter.connection = connection;
Expand Down
63 changes: 13 additions & 50 deletions NetDataAdapters/Handler.ashx.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Stimulsoft.Reports.JS
Version: 2022.4.5
Build date: 2022.11.17
Version: 2023.1.1
Build date: 2022.12.07
License: https://www.stimulsoft.com/en/licensing/reports
*/
using System;
Expand Down Expand Up @@ -85,10 +85,19 @@ public class ParameterJson
public string Name { get; set; }

[DataMember(Name = "value")]
public string Value { get; set; }
public object Value { get; set; }

[DataMember(Name = "typeGroup")]
public string TypeGroup { get; set; }

[DataMember(Name = "typeName")]
public string TypeName { get; set; }

[DataMember(Name = "typeValue")]
public int TypeValue { get; set; }

[DataMember(Name = "size")]
public int Size { get; set; }
}
#endregion

Expand Down Expand Up @@ -134,8 +143,6 @@ public void ProcessRequest(HttpContext context)
}
else
{
command.QueryString = ApplyQueryParameters(command.QueryString, command.Parameters, command.EscapeQueryParameters);

switch (command.Database)
{
case "MySQL": result = SQLAdapter.Process(command, new MySqlConnection(command.ConnectionString)); break;
Expand All @@ -158,7 +165,7 @@ public void ProcessRequest(HttpContext context)
inputStream.Close();
}

result.HandlerVersion = "2022.4.5";
result.HandlerVersion = "2023.1.1";
result.CheckVersion = true;

context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
Expand All @@ -185,50 +192,6 @@ public void ProcessRequest(HttpContext context)
context.Response.End();
}

public string ApplyQueryParameters(string baseSqlCommand, ParameterJson[] parameters, bool escapeQueryParameters)
{
if (baseSqlCommand == null || baseSqlCommand.IndexOf("@") < 0) return baseSqlCommand;

var result = "";
while (baseSqlCommand.IndexOf("@") >= 0 && parameters != null && parameters.Length > 0)
{
result += baseSqlCommand.Substring(0, baseSqlCommand.IndexOf("@"));
baseSqlCommand = baseSqlCommand.Substring(baseSqlCommand.IndexOf("@") + 1);

var parameterName = "";

var regex = new Regex(@"[a-zA-Z0-9_-]");
while (baseSqlCommand.Length > 0)
{
string chr = baseSqlCommand[0].ToString();
if (regex.IsMatch(chr))
{
parameterName += chr;
baseSqlCommand = baseSqlCommand.Substring(1);
}
else break;
}

var parameter = parameters.ToList().Find(p => p.Name.ToLowerInvariant() == parameterName.ToLowerInvariant());
if (parameter != null)
{
if (parameter.TypeGroup != "number")
{
if (escapeQueryParameters)
result += "'" + parameter.Value.Replace("\\", "\\\\").Replace("'", "\\'").Replace("\"", "\\\"") + "'";
else
result += "'" + parameter.Value + "'";
}
else
result += parameter.Value;
}
else
result += "@" + parameterName;
}

return result + baseSqlCommand;
}

public bool IsReusable
{
get
Expand Down
Loading

0 comments on commit b8a52b2

Please sign in to comment.