Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
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
/***********************************************************************************************************************************
Db Protocol Handler
***********************************************************************************************************************************/
#include <build.h>
 
#include "common/debug.h"
#include "common/io/io.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/json.h"
#include "common/type/list.h"
#include "config/config.h"
#include "db/protocol.h"
#include "postgres/client.h"
#include "postgres/interface.h"
 
/**********************************************************************************************************************************/
FN_EXTERN ProtocolServerResult *
dbOpenProtocol(PackRead *const param)
{
    FUNCTION_LOG_BEGIN(logLevelDebug);
        (void)param;
    FUNCTION_LOG_END();
 
    ASSERT(param == NULL);
 
    ProtocolServerResult *const result = protocolServerResultNewP();
 
    MEM_CONTEXT_TEMP_BEGIN()
    {
        PgClient *const pgClient = pgClientNew(
            cfgOptionStrNull(cfgOptPgSocketPath), cfgOptionUInt(cfgOptPgPort), cfgOptionStr(cfgOptPgDatabase),
            cfgOptionStrNull(cfgOptPgUser), cfgOptionUInt64(cfgOptDbTimeout));
        pgClientOpen(pgClient);
 
        // Set session data
        protocolServerResultSessionDataSet(result, pgClient);
    }
    MEM_CONTEXT_TEMP_END();
 
    FUNCTION_LOG_RETURN(PROTOCOL_SERVER_RESULT, result);
}
 
/**********************************************************************************************************************************/
FN_EXTERN ProtocolServerResult *
dbQueryProtocol(PackRead *const param, void *const pgClient)
{
    FUNCTION_LOG_BEGIN(logLevelDebug);
        FUNCTION_LOG_PARAM(PACK_READ, param);
        FUNCTION_LOG_PARAM(PG_CLIENT, pgClient);
    FUNCTION_LOG_END();
 
    FUNCTION_AUDIT_STRUCT();
 
    ASSERT(param != NULL);
    ASSERT(pgClient != NULL);
 
    ProtocolServerResult *const result = protocolServerResultNewP();
 
    MEM_CONTEXT_TEMP_BEGIN()
    {
        const PgClientQueryResult resultType = (PgClientQueryResult)pckReadStrIdP(param);
        const String *const query = pckReadStrP(param);
 
        pckWritePackP(protocolServerResultData(result), pgClientQuery(pgClient, query, resultType));
    }
    MEM_CONTEXT_TEMP_END();
 
    FUNCTION_LOG_RETURN(PROTOCOL_SERVER_RESULT, result);
}