Skip to content

Commit

Permalink
Merge pull request #716 from FastReports/sync_branch_2025.1.0
Browse files Browse the repository at this point in the history
* sync 10/16/2024 version: 2025.1.0
  • Loading branch information
0legK authored Oct 16, 2024
2 parents 13318ff + 72fe158 commit 9cf67c6
Show file tree
Hide file tree
Showing 117 changed files with 4,418 additions and 779 deletions.
8 changes: 4 additions & 4 deletions Extras/Core/FastReport.Data/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Target Name="CleanObjAndBin">
<!-- Remove obj folder -->
<RemoveDir Directories="$(MSBuildProjectDirectory)\$(BaseIntermediateOutputPath)" />
<!-- Remove bin folder -->
<RemoveDir Directories="$(MSBuildProjectDirectory)\$(BaseOutputPath)" />
<!-- Remove obj folder -->
<RemoveDir ContinueOnError="WarnAndContinue" Directories="$(MSBuildProjectDirectory)\$(BaseIntermediateOutputPath)" />
<!-- Remove bin folder -->
<RemoveDir ContinueOnError="WarnAndContinue" Directories="$(MSBuildProjectDirectory)\$(BaseOutputPath)" />
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<ItemGroup>
<PackageReference Include="CassandraCSharpDriver" Version="3.17.1" />
<PackageReference Include="Newtonsoft.Json" Version="[13.0.3,)" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

Expand Down Expand Up @@ -83,6 +84,7 @@ public override DbDataAdapter GetAdapter(string selectCommand, DbConnection conn
clickHouseDataAdapter.SelectCommand = command;
return clickHouseDataAdapter;
}

private string PrepareSelectCommand(string selectCommand, string tableName, DbConnection connection)
{
if (String.IsNullOrEmpty(selectCommand))
Expand All @@ -91,6 +93,7 @@ private string PrepareSelectCommand(string selectCommand, string tableName, DbCo
}
return selectCommand;
}

private IEnumerable<DataColumn> GetColumns(ClickHouseDataReader reader)
{
for (int i = 0; i < reader.FieldCount; i++)
Expand All @@ -112,16 +115,24 @@ public override void FillTableSchema(DataTable table, string selectCommand, Comm
selectCommand = PrepareSelectCommand(selectCommand, table.TableName, clickHouseConnection);
/*To reduce size of traffic and size of answer from ClickHouse server.
Because FillSchema doesn't work in this ADO.NET library.
LIMIT 0 gets an empy set, but we still have list of desired columns
Prorably can be a better way.
LIMIT 0 gets an empty set, but we still have list of desired columns
Probably can be a better way.
*/
selectCommand += " LIMIT 0";
ClickHouseCommand clickHouseCommand = clickHouseConnection.CreateCommand();

foreach (CommandParameter p in parameters)
{
selectCommand = selectCommand.Replace($"@{p.Name}", $"{{{p.Name}:{(ClickHouseTypeCode)p.DataType}}}");
clickHouseCommand.AddParameter(p.Name, ((ClickHouseTypeCode)p.DataType).ToString(), p.Value);
if (p.Value is Variant value)
{
if (value.Type == typeof(string))
clickHouseCommand.AddParameter(p.Name, ((ClickHouseTypeCode)p.DataType).ToString(), VariantToClrType(value, (ClickHouseTypeCode)p.DataType));
else
clickHouseCommand.AddParameter(p.Name, ((ClickHouseTypeCode)p.DataType).ToString(), value.ToType(value.Type));
}
else
clickHouseCommand.AddParameter(p.Name, ((ClickHouseTypeCode)p.DataType).ToString(), p.Value);
}
clickHouseCommand.CommandText = selectCommand;
using (ClickHouseDataReader reader = clickHouseCommand.ExecuteReader() as ClickHouseDataReader)
Expand All @@ -135,5 +146,125 @@ Prorably can be a better way.
DisposeConnection(clickHouseConnection);
}
}

private object VariantToClrType(Variant value, ClickHouseTypeCode type)
{
if (value.ToString() == "" && type != ClickHouseTypeCode.Nothing)
return null;

switch (type)
{
case ClickHouseTypeCode.Enum8:
case ClickHouseTypeCode.Int8:
{
sbyte val = 0;
sbyte.TryParse(value.ToString(), out val);
return val;
}
case ClickHouseTypeCode.Enum16:
case ClickHouseTypeCode.Int16:
{
short val = 0;
short.TryParse(value.ToString(), out val);
return val;
}
case ClickHouseTypeCode.Int32:
{
int val = 0;
int.TryParse(value.ToString(), out val);
return val;
}
case ClickHouseTypeCode.Int64:
{
long val = 0;
long.TryParse(value.ToString(), out val);
return val;
}
case ClickHouseTypeCode.UInt8:
{
byte val = 0;
byte.TryParse(value.ToString(), out val);
return val;
}
case ClickHouseTypeCode.UInt16:
{
ushort val = 0;
ushort.TryParse(value.ToString(), out val);
return val;
}
case ClickHouseTypeCode.UInt32:
{
uint val = 0;
uint.TryParse(value.ToString(), out val);
return val;
}
case ClickHouseTypeCode.UInt64:
{
ulong val = 0;
ulong.TryParse(value.ToString(), out val);
return val;
}
case ClickHouseTypeCode.Date:
{
DateTime val = DateTime.Now;
DateTime.TryParse(value.ToString(), out val);
return val;
}
case ClickHouseTypeCode.DateTime:
case ClickHouseTypeCode.DateTime64:
{
DateTimeOffset val = DateTimeOffset.Now;
DateTimeOffset.TryParse(value.ToString(), out val);
return val;
}
case ClickHouseTypeCode.Decimal:
{
decimal val = 0;
decimal.TryParse(value.ToString(), out val);
return val;
}
case ClickHouseTypeCode.Float32:
{
float val = 0;
float.TryParse(value.ToString(), out val);
return val;
}
case ClickHouseTypeCode.Float64:
{
double val = 0;
double.TryParse(value.ToString(), out val);
return val;
}
case ClickHouseTypeCode.UUID:
{
Guid val = Guid.Empty;
Guid.TryParse(value.ToString(), out val);
return val;
}
case ClickHouseTypeCode.IPv6:
case ClickHouseTypeCode.IPv4:
{
try
{
return IPAddress.Parse(value.ToString());
}
catch
{
return IPAddress.None;
}
}
case ClickHouseTypeCode.Nothing:
return DBNull.Value;
case ClickHouseTypeCode.Array:
case ClickHouseTypeCode.Nested:
case ClickHouseTypeCode.Tuple:
case ClickHouseTypeCode.Nullable:
case ClickHouseTypeCode.LowCardinality:
throw new NotImplementedException();

default:
return value.ToString();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ClickHouse.Client" Version="3.0.0.357" />
<PackageReference Include="ClickHouse.Client" Version="3.2.0.421" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="2.11.3" />
<PackageReference Include="SpreadsheetLight" Version="3.5.0" />
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Import Project="..\Connections.props" />

<ItemGroup>
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Data.Common;
using MySqlConnector;
using System.Data;
using System.Globalization;

namespace FastReport.Data
{
Expand Down Expand Up @@ -64,7 +65,7 @@ public override DbDataAdapter GetAdapter(string selectCommand, DbConnection conn
{
MySqlDataAdapter adapter = new MySqlDataAdapter(selectCommand, connection as MySqlConnection);
foreach (CommandParameter p in parameters)
{
{
MySqlParameter parameter = adapter.SelectCommand.Parameters.Add(p.Name, (MySqlDbType)p.DataType, p.Size);

if (p.Value is Variant value)
Expand All @@ -83,7 +84,7 @@ public override DbDataAdapter GetAdapter(string selectCommand, DbConnection conn

private object VariantToClrType(Variant value, MySqlDbType type)
{
if (value.ToString() == "")
if (value.ToString() == "" && type != MySqlDbType.Null)
return null;

switch (type)
Expand Down Expand Up @@ -116,19 +117,16 @@ private object VariantToClrType(Variant value, MySqlDbType type)
return val;
}
case MySqlDbType.DateTime:
case MySqlDbType.Timestamp:
case MySqlDbType.Date:
case MySqlDbType.Newdate:
case MySqlDbType.Time:
{
DateTime val = DateTime.Now;
DateTime.TryParse(value.ToString(), out val);
return val;
}
case MySqlDbType.Time:
case MySqlDbType.Timestamp:
{
TimeSpan val = TimeSpan.Zero;
TimeSpan.TryParse(value.ToString(), out val);
return val;
}
case MySqlDbType.NewDecimal:
case MySqlDbType.Decimal:
{
decimal val = 0;
Expand All @@ -142,13 +140,13 @@ private object VariantToClrType(Variant value, MySqlDbType type)
return val;
}
case MySqlDbType.Int24:
case MySqlDbType.UInt24:
case MySqlDbType.Int32:
{
int val = 0;
int.TryParse(value.ToString(), out val);
return val;
}
case MySqlDbType.UInt24:
case MySqlDbType.UInt32:
{
uint val = 0;
Expand All @@ -174,12 +172,41 @@ private object VariantToClrType(Variant value, MySqlDbType type)
return val;
}
case MySqlDbType.Byte:
{
sbyte val = 0;
sbyte.TryParse(value.ToString(), out val);
return val;
}
case MySqlDbType.UByte:
{
byte val = 0;
byte.TryParse(value.ToString(), out val);
return val;
}
case MySqlDbType.Blob:
case MySqlDbType.TinyBlob:
case MySqlDbType.MediumBlob:
case MySqlDbType.LongBlob:
case MySqlDbType.Binary:
case MySqlDbType.VarBinary:
{
string val = value.ToString();
if (val.Length % 2 != 0)
{
throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "The binary key cannot have an odd number of digits: {0}", val));
}

byte[] data = new byte[val.Length / 2];
for (int index = 0; index < data.Length; index++)
{
string byteValue = val.Substring(index * 2, 2);
data[index] = byte.Parse(byteValue, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
}

return data;
}
case MySqlDbType.Null:
return DBNull.Value;
default:
return value.ToString();
}
Expand Down
Loading

0 comments on commit 9cf67c6

Please sign in to comment.