Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2026-04-30 9f2ef60949ced4fab4d077a7e1c6d913f3620c9b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using Xunit;
using System.Linq;
 
public abstract class BaseCombineUUIdsDllTests : PlDotNetTest
{
    protected abstract string FunctionBody { get; }
 
    protected abstract LanguageType Language { get; }
 
    public BaseCombineUUIdsDllTests()
    {
        FunctionInfo = new SqlFunctionInfo
        {
            Name = "CombineUUIdsDll",
            Arguments = new List<FunctionArgument> { new FunctionArgument("a", "UUID"), new FunctionArgument("b", "UUID") },
            ReturnType = "UUID",
            Body = FunctionBody,
            Language = LanguageType.PlcSharp,
            IsStrict = false,
        };
    }
 
    public static object[][] TestCases()
    {
        return new object[][] { new object[] { "c#-uuid-dll", "combineUUIDsDLL1", "'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::UUID, '87e3006a-604e-11ed-9b6a-0242ac120002'::UUID", "= 'a0eebc99-9c0b-4ef8-9b6a-0242ac120002'::UUID" }, new object[] { "c#-uuid-dll", "combineUUIDsDLL2", "'123e4567-e89b-12d3-a456-426614174000'::UUID, '024be913-3bf8-4499-9694-12769239b763'::UUID", "= '123e4567-e89b-12d3-9694-12769239b763'::UUID" }, new object[] { "c#-uuid-null-dll", "combineUUIDsDLL3", "NULL::UUID, '024be913-3bf8-4499-9694-12769239b763'::UUID", "= 'a0eebc99-9c0b-4ef8-9694-12769239b763'::UUID" }, };
    }
 
    [Theory]
    [MemberData(nameof(TestCases))]
    public void TestCombineUUIdsDll(string featureName, string testName, string input, string expectedResult)
    {
        RunGenericTest(featureName, testName, input, expectedResult);
    }
}
 
[Trait("Language", "CSharp")]
[Trait("Category", "Dll")]
public class CombineUUIdsDllTestsCSharp : BaseCombineUUIdsDllTests
{
    protected override string FunctionBody => @"
'/app/pldotnet/tests/csharp/DotNetTestProject/bin/Release/CSharpTest.dll:TestDLLFunctions.TestClass!combineuuids'
    ";
    protected override LanguageType Language => LanguageType.PlcSharp;
    public override string GetFunctionDefinition(SqlFunctionInfo functionInfo)
    {
        var arguments = string.Join(", ", functionInfo.Arguments.Select(arg => $"{arg.Name} {arg.Type}"));
        string strictKeyword = functionInfo.IsStrict ? "STRICT" : "";
        // Conditionally build the returnTypeString
        string returnTypeString = string.IsNullOrEmpty(functionInfo.ReturnType) ? string.Empty : $"RETURNS {functionInfo.ReturnType}";
        return $@"CREATE OR REPLACE FUNCTION {functionInfo.Name}({arguments})
{returnTypeString} AS {functionInfo.Body} LANGUAGE {functionInfo.LanguageString} {strictKeyword};";
    }
}