Skip to content

Commit

Permalink
Merge pull request #150 from HicServices/feature/updateci
Browse files Browse the repository at this point in the history
Target .Net Standard 2.1, update CI
  • Loading branch information
tznind committed Aug 29, 2022
2 parents 1a26fb4 + 073102a commit f4a8c37
Show file tree
Hide file tree
Showing 25 changed files with 492 additions and 480 deletions.
37 changes: 16 additions & 21 deletions .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:
jobs:
build:

runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
services:
postgres:
image: postgres:latest
Expand All @@ -26,36 +26,31 @@ jobs:
- 5432:5432

steps:
- name: Disable write flush for CI runs
run: sudo apt-get install -y libeatmydata1 apt-transport-https curl
- uses: actions/checkout@v3
- name: Setup .NET Core
uses: actions/setup-dotnet@v2
with:
dotnet-version: 3.1.301
- name: Add MSFT code signing key
run: wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
- name: Add MSFT package repo
run: sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list)"
dotnet-version: 6.0.x
- name: Install Sql Server
run: |
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)"
sudo apt-get install -y --no-install-recommends postgresql mssql-tools mssql-server
sudo -E /opt/mssql/bin/mssql-conf -n setup accept-eula
- name: MySQL
run: |
sed -i'' -e 's/Password=;/Password=pgpass4291;/' Tests/FAnsiTests/TestDatabases.xml
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
sudo mysqld_safe --port=3306 --skip-grant-tables &
- name: Install Sql Server
run: sudo apt-get install -y --no-install-recommends postgresql mssql-tools mssql-server
- name: Configure Sql Server
run: sudo -E /opt/mssql/bin/mssql-conf -n setup accept-eula
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
sed -i'' -e 's|</TestDatabases>|<TestDatabase><DatabaseType>PostgreSql</DatabaseType><ConnectionString>User ID=postgres;Password=pgpass4291;Host=127.0.0.1;Port=5432</ConnectionString></TestDatabase></TestDatabases>|' Tests/FAnsiTests/TestDatabases.xml
sed -i'' -e 's/Pwd=;SslMode=None/Pwd=root;AllowPublicKeyRetrieval=true/' Tests/FAnsiTests/TestDatabases.xml
sudo systemctl start mysql.service
- name: Test
run: dotnet test --no-restore --verbosity normal
run: dotnet test --logger "console;verbosity=minimal" --nologo
- name: Pack
run: |
mkdir -p NuGet/bin
ln -sf Release/netstandard2.0 NuGet/bin/
dotnet pack NuGet/FAnsi.NuGet.csproj -c Release --include-source --include-symbols --nologo -p:NuspecFile=`pwd`/NuGet/FAnsi.NuGet.nuspec -p:NuspecProperties=Version=$(fgrep AssemblyInformationalVersion SharedAssemblyInfo.cs|cut -d'"' -f2)\;configuration=Release -p:SymbolPackageFormat=snupkg
ln -sf Release/netstandard2.1 NuGet/bin/
dotnet pack NuGet/FAnsi.NuGet.csproj -c Release --include-source --include-symbols --nologo -p:NuspecFile=`pwd`/NuGet/FAnsi.NuGet.nuspec -p:NuspecProperties=Version=$(fgrep AssemblyInformationalVersion SharedAssemblyInfo.cs|cut -d'"' -f2) -p:SymbolPackageFormat=snupkg
- name: Nuget push
if: contains(github.ref,'refs/tags/')
run: dotnet nuget push NuGet/bin/Release/HIC.FAnsiSql.*.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_KEY }} --skip-duplicate
Expand Down
2 changes: 1 addition & 1 deletion FAnsiSql/FAnsi.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyTitle>HIC.FAnsiSql</AssemblyTitle>
<Company>Health Informatics Centre, University of Dundee</Company>
<Product>HIC.FAnsiSql</Product>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyTitle>SqlServerImplementation</AssemblyTitle>
<Product>SqlServerImplementation</Product>
<Copyright>Copyright © 2019</Copyright>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,14 @@ dt DATE

public override string GetDatePartOfColumn(AxisIncrement increment, string columnSql)
{
switch (increment)
return increment switch
{
case AxisIncrement.Day:
return "DATE(" + columnSql + ")";
case AxisIncrement.Month:
return "DATE_FORMAT("+columnSql+",'%Y-%m')";
case AxisIncrement.Year:
return "YEAR(" + columnSql + ")";
case AxisIncrement.Quarter:
return "CONCAT(YEAR(" + columnSql + "),'Q',QUARTER(" + columnSql + "))";
default:
throw new ArgumentOutOfRangeException("increment");
}
AxisIncrement.Day => $"DATE({columnSql})",
AxisIncrement.Month => $"DATE_FORMAT({columnSql},'%Y-%m')",
AxisIncrement.Year => $"YEAR({columnSql})",
AxisIncrement.Quarter => $"CONCAT(YEAR({columnSql}),'Q',QUARTER({columnSql}))",
_ => throw new ArgumentOutOfRangeException(nameof(increment))
};
}


Expand Down Expand Up @@ -173,15 +168,15 @@ ORDER BY
query.SyntaxHelper.Escape(GetDatePartOfColumn(query.Axis.AxisIncrement,axisColumnWithoutAlias)),

//the order by (should be count so that heavy populated columns come first)
query.SyntaxHelper.Escape(string.Join(Environment.NewLine, query.Lines.Where(c => c.LocationToInsert >= QueryComponent.FROM && c.LocationToInsert <= QueryComponent.WHERE)))
string.Join(Environment.NewLine, query.Lines.Where(c => c.LocationToInsert >= QueryComponent.FROM && c.LocationToInsert <= QueryComponent.WHERE).Select(x=> query.SyntaxHelper.Escape(x.Text)))
);
}

protected override string BuildPivotOnlyAggregate(AggregateCustomLineCollection query, CustomLine nonPivotColumn)
{
string part1 = GetPivotPart1(query);

string nonPivotColumnSql = nonPivotColumn.GetTextWithoutAlias(query.SyntaxHelper);
string joinAlias = nonPivotColumn.GetAliasFromText(query.SyntaxHelper);

return string.Format(@"
{0}
Expand Down Expand Up @@ -213,7 +208,7 @@ ORDER BY
//everything inclusive of FROM but stopping before GROUP BY
query.SyntaxHelper.Escape(string.Join(Environment.NewLine, query.Lines.Where(c => c.LocationToInsert >= QueryComponent.FROM && c.LocationToInsert < QueryComponent.GroupBy))),

nonPivotColumnSql,
joinAlias,

//any HAVING SQL
query.SyntaxHelper.Escape(string.Join(Environment.NewLine, query.Lines.Where(c => c.LocationToInsert == QueryComponent.Having)))
Expand Down Expand Up @@ -249,11 +244,11 @@ private static string GetPivotPart1(AggregateCustomLineCollection query)
var axisColumnWithoutAlias = query.AxisSelect.GetTextWithoutAlias(query.SyntaxHelper);

whereDateColumnNotNull += query.Lines.Any(l => l.LocationToInsert == QueryComponent.WHERE) ? "AND " : "WHERE ";
whereDateColumnNotNull += axisColumnWithoutAlias + " IS NOT NULL";
whereDateColumnNotNull += $"{axisColumnWithoutAlias} IS NOT NULL";
}

//work out how to order the pivot columns
string orderBy = countSqlWithoutAlias + " desc"; //default, order by the count(*) / sum(*) etc column desc
string orderBy = $"{countSqlWithoutAlias} desc"; //default, order by the count(*) / sum(*) etc column desc

//theres an explicit topX so order by it verbatim instead
var topXOrderByLine =
Expand Down Expand Up @@ -288,12 +283,12 @@ order by
{5}
);
/* Build case when x='fish' then 1 end as 'fish', case when x='cammel' then 1 end as 'cammel' etc*/
/* Build case when x='fish' then 1 else null end as 'fish', case when x='cammel' then 1 end as 'cammel' etc*/
SET @columnsSelectCases = NULL;
SELECT
GROUP_CONCAT(
CONCAT(
'{0}(case when {1} = ''', REPLACE(pivotValues.piv,'\'','\\\''), ''' then {2} end) AS `', pivotValues.piv,'`'
'{0}(case when {1} = ', QUOTE(pivotValues.piv), ' then {2} else null end) AS `', pivotValues.piv,'`'
)
) INTO @columnsSelectCases
FROM
Expand Down Expand Up @@ -371,9 +366,9 @@ order by
//SELECT
// GROUP_CONCAT(DISTINCT
// CONCAT(
// 'count(case when `test`.`biochemistry`.`hb_extract` = ''',
// 'count(case when `test`.`biochemistry`.`hb_extract` = \'',
// b.`Pivot`,
// ''' then 1 end) AS `',
// \'' then 1 else null end) AS `',
// b.`Pivot`,'`'
// ) order by b.`CountName` desc
// ) INTO @columns
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyTitle>FAnsi.Implementations.MySql</AssemblyTitle>
<Product>FAnsi.Implementations.MySql</Product>
<Copyright>Copyright © 2019</Copyright>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
using FAnsi.Discovery;
using FAnsi.Discovery.QuerySyntax;
using FAnsi.Implementations.MySql.Aggregation;
Expand Down Expand Up @@ -31,7 +32,7 @@ public override bool SupportsEmbeddedParameters()

public override string EnsureWrappedImpl(string databaseOrTableName)
{
return "`" + GetRuntimeNameWithDoubledBackticks(databaseOrTableName) + "`";
return $"`{GetRuntimeNameWithDoubledBackticks(databaseOrTableName)}`";
}

/// <summary>
Expand Down Expand Up @@ -60,49 +61,52 @@ public override string EnsureFullyQualified(string databaseName, string schema,

public override TopXResponse HowDoWeAchieveTopX(int x)
{
return new TopXResponse("LIMIT " + x,QueryComponent.Postfix);
return new TopXResponse($"LIMIT {x}",QueryComponent.Postfix);
}

public override string GetParameterDeclaration(string proposedNewParameterName, string sqlType)
{
//MySql doesn't require parameter declaration you just start using it like javascript
return "/*" + proposedNewParameterName + "*/";
return $"/* {proposedNewParameterName} */";
}

public override string Escape(string sql)
{
//https://dev.mysql.com/doc/refman/5.7/en/string-literals.html

sql = sql.Replace("\\", "\\\\"); //first of all swap current \ for \\ (don't do this later because we are going to inject a bunch of that stuff!).

sql = sql.Replace("'", "\\'"); //swap ' for \'

sql = sql.Replace("\"", "\\\""); //swap " for \"
sql = sql.Replace("\r\n", "\\n"); //swap newline whitespace with \r for \n
sql = sql.Replace("\n", "\\n"); //swap newline whitespace for \n
sql = sql.Replace("\t", "\\t"); //swap tab whitespace for \t

//only apply in pattern matching use cases (rare?) otherwise they break it! you will have to handle this yourself if you have that situation
//sql = sql.Replace("%", "\\%"); //swap % for \%
//sql = sql.Replace("_", "\\_"); //swap _ for \_

return sql;
// https://dev.mysql.com/doc/refman/8.0/en/string-literals.html
var r = new StringBuilder(sql.Length);
foreach (var c in sql)
{
r.Append(c switch
{
'\0' => "\\0",
'\'' => "\\'",
'"' => "\"",
'\b' => "\\b",
'\n' => "\\n",
'\r' => "\\r",
'\t' => "\\t",
'\u001a' => "\\Z",
'\\' => "\\",
// Pattern matching only:
// '%' => "\\%",
// '_' => "\\_",
_ => $"{c}"
});
}
return r.ToString();
}

public override string GetScalarFunctionSql(MandatoryScalarFunctions function)
{

switch (function)
return function switch
{
case MandatoryScalarFunctions.GetTodaysDate: //this works at least as of 5.7.19
return "now()";
case MandatoryScalarFunctions.GetGuid: //using this as defaults in columns requires MySql 8 (2018)
return "(uuid())";
case MandatoryScalarFunctions.Len:
return "LENGTH";
default:
throw new ArgumentOutOfRangeException("function");
}
MandatoryScalarFunctions.GetTodaysDate => //this works at least as of 5.7.19
"now()",
MandatoryScalarFunctions.GetGuid => //using this as defaults in columns requires MySql 8 (2018)
"(uuid())",
MandatoryScalarFunctions.Len => "LENGTH",
_ => throw new ArgumentOutOfRangeException(nameof(function))
};
}

public override string GetAutoIncrementKeywordIfAny()
Expand Down Expand Up @@ -130,7 +134,7 @@ public override string GetAutoIncrementKeywordIfAny()

public override string HowDoWeAchieveMd5(string selectSql)
{
return "md5(" + selectSql + ")";
return $"md5({selectSql})";
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyTitle>FAnsi.Implementations.Oracle</AssemblyTitle>
<Product>FAnsi.Implementations.Oracle</Product>
<Copyright>Copyright © 2019</Copyright>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<NoWarn>CS1591</NoWarn>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion NuGet/FAnsi.NuGet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<RootNamespace>NuGet</RootNamespace>
<AssemblyName>NuGet</AssemblyName>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyTitle>HIC.FAnsiSql</AssemblyTitle>
<Company>Health Informatics Centre, University of Dundee</Company>
<Product>HIC.FAnsiSql</Product>
Expand Down
6 changes: 3 additions & 3 deletions NuGet/FAnsi.NuGet.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
</dependencies>
</metadata>
<files>
<file src="bin\$configuration$\netstandard2.0\FAnsi*.dll" target="lib\netstandard2.0" />
<file src="bin\$configuration$\netstandard2.0\FAnsi*.pdb" target="lib\netstandard2.0" />
<file src="bin\$configuration$\netstandard2.0\FAnsi*.xml" target="lib\netstandard2.0" />
<file src="bin\$configuration$\netstandard2.1\FAnsi*.dll" target="lib\netstandard2.1" />
<file src="bin\$configuration$\netstandard2.1\FAnsi*.pdb" target="lib\netstandard2.1" />
<file src="bin\$configuration$\netstandard2.1\FAnsi*.xml" target="lib\netstandard2.1" />
</files>
</package>
Loading

0 comments on commit f4a8c37

Please sign in to comment.