Исходный код СУБД 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
@startuml
 
!pragma useVerticalIf on
 
participant "PostgreSQL" as S
participant "pl/dotnet: C" as D
participant "pl/dotnet: C#/UserHandler" as H
participant "pl/dotnet: C#/UserFunction" as F
 
autonumber
S -> D: pldotnet_generic_handler(FunctionCallInfo fcinfo, bool is_inline, pldotnet_Language language="csharp")
group Main call from C into dotnet
    D -> H: CallUserFunction (arguments: List<IntPtr>, output: IntPtr, isnull: bool[])
    group Convert each Datum to dotnet values to pass to function
        H -> H: argument_0 = InputNullableValue(arguments.[0], isnull.[0])
        H -> H: InputValue(arguments.[0])
        H -> D: pldotnet_GetInt32(arguments.[0])
        D -[dotted]->> H: return(value)
        H -[dotted]->> H: return(value) // return from InputValue()
        H -[dotted]->> H: return(value) // return from InputNullableValue()
        H -> H: argument_1 = InputNullableValue(arguments.[1], isnull.[1])
        H -> H: InputValue(arguments.[1])
        H -> D: pldotnet_GetInt16(arguments.[1])
        D -[dotted]->> H: return(value)
        H -[dotted]->> H: return(value) // return from InputValue()
        H -[dotted]->> H: return(value) // return from InputNullableValue()
    end
    group UserFunction call
        H -> F: user_function(argument_0, argument_1)
        F -> F: result = a + b
        F -[dotted]->> H: return(result) // from user_function()
    end
    group Convert dotnet value to Datum & set for return
        H -> H: IntHandlerObj.OutputNullableValue(result);
        H -> D: pldotnet_CreateDatumInt32(result)
        D -[dotted]->> H: return(resultDatum)
        H -[dotted]->> H: return() // from IntHandlerObj.OutputNullableValue(result)
    end
    H -[dotted]->> D: return(success) // from CallUserFunction()
end
D -[dotted]->> S: return(datum) // from pldotnet_generic_handler()
 
@enduml
 
''' namespace PlDotNET.UserSpace
''' {
'''     public static class UserFunction
'''     {
'''         public static int? integertest(int a, short b)
'''         {
''' #line 1
'''             return a + b;
'''         }
'''     }
'''     public static class UserHandler
'''     {
'''         public static IntHandler IntHandlerObj = new IntHandler();
'''         public static ShortHandler ShortHandlerObj = new ShortHandler();
'''         public static unsafe void CallUserFunction(List<IntPtr> arguments, IntPtr output, bool[] isnull)
'''         {
''' #line 1
'''             // As the SQL function named integertest is `STRICT` or `RETURNS NULL ON NULL INPUT`,
'''             // `PL.NET` doesn't check whether any argument datum is null.
'''             // You can also set true for the `Engine.AlwaysNullable` variable
'''             // to always check whether the datum is null.
'''             // BEGIN create arguments for integertest
'''             var argument_0 = IntHandlerObj.InputValue(arguments[0]);
'''             var argument_1 = ShortHandlerObj.InputValue(arguments[1]);
'''             // END create arguments for integertest
'''             var result = PlDotNET.UserSpace.UserFunction.integertest((int)argument_0, (short)argument_1);
'''             var resultDatum = IntHandlerObj.OutputNullableValue(result);
'''             OutputResult.SetDatumResult(resultDatum, result == null, output);
'''         }
'''     }
''' }