Coverage Report

Created: 2026-05-16 08:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/ogr/ogrsf_frmts/vfk/vfkpropertydefn.cpp
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  VFK Reader - Data block property definition
4
 * Purpose:  Implements VFKPropertyDefn class.
5
 * Author:   Martin Landa, landa.martin gmail.com
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 2009-2010, 2012, Martin Landa <landa.martin gmail.com>
9
 *
10
 * SPDX-License-Identifier: MIT
11
 ****************************************************************************/
12
13
#include "vfkreader.h"
14
#include "vfkreaderp.h"
15
16
#include "cpl_conv.h"
17
#include "cpl_error.h"
18
19
/*!
20
  \brief VFKPropertyDefn constructor
21
22
  \param pszName property name
23
  \param pszType property type (original, string)
24
  \param pszEncoding encoding (only for "text" type)
25
*/
26
VFKPropertyDefn::VFKPropertyDefn(const char *pszName, const char *pszType,
27
                                 const char *pszEncoding)
28
68.8k
    : m_pszName(CPLStrdup(pszName)), m_pszType(CPLStrdup(pszType)),
29
68.8k
      m_pszEncoding(nullptr), m_nWidth(0), m_nPrecision(0)
30
68.8k
{
31
68.8k
    char *poWidth = m_pszType + 1;
32
68.8k
    char *poChar = m_pszType + 1;
33
68.8k
    int nLength = 0;  // Used after for.
34
443k
    for (; *poChar && *poChar != '.'; nLength++, poChar++)
35
374k
        ;
36
37
68.8k
    char *pszWidth = static_cast<char *>(CPLMalloc(nLength + 1));
38
68.8k
    strncpy(pszWidth, poWidth, nLength);
39
68.8k
    pszWidth[nLength] = '\0';
40
41
68.8k
    m_nWidth = atoi(pszWidth);
42
68.8k
    CPLFree(pszWidth);
43
44
    // Type.
45
68.8k
    if (*m_pszType == 'N')
46
23.0k
    {
47
23.0k
        if (*poChar == '.')
48
2.90k
        {
49
2.90k
            m_eFType = OFTReal;
50
2.90k
            m_nPrecision = atoi(poChar + 1);
51
2.90k
        }
52
20.1k
        else
53
20.1k
        {
54
20.1k
            if (m_nWidth < 10)
55
9.07k
                m_eFType = OFTInteger;
56
11.1k
            else
57
11.1k
            {
58
11.1k
                m_eFType = OFTInteger64;
59
11.1k
            }
60
20.1k
        }
61
23.0k
    }
62
45.7k
    else if (*m_pszType == 'T')
63
7.16k
    {
64
        // String.
65
7.16k
        m_eFType = OFTString;
66
7.16k
        m_pszEncoding = CPLStrdup(pszEncoding);
67
7.16k
    }
68
38.6k
    else if (*m_pszType == 'D')
69
9.05k
    {
70
        // Date.
71
        // m_eFType = OFTDateTime;
72
9.05k
        m_eFType = OFTString;
73
9.05k
        m_nWidth = 25;
74
9.05k
    }
75
29.5k
    else
76
29.5k
    {
77
        // Unknown - string.
78
29.5k
        m_eFType = OFTString;
79
29.5k
        m_pszEncoding = CPLStrdup(pszEncoding);
80
29.5k
    }
81
68.8k
}
82
83
/*!
84
  \brief VFKPropertyDefn destructor
85
*/
86
VFKPropertyDefn::~VFKPropertyDefn()
87
68.8k
{
88
68.8k
    CPLFree(m_pszName);
89
68.8k
    CPLFree(m_pszType);
90
68.8k
    if (m_pszEncoding)
91
36.7k
        CPLFree(m_pszEncoding);
92
68.8k
}
93
94
/*!
95
  \brief Get SQL data type
96
97
  \return string with data type ("text" by default)
98
*/
99
CPLString VFKPropertyDefn::GetTypeSQL() const
100
9.98k
{
101
9.98k
    switch (m_eFType)
102
9.98k
    {
103
1.96k
        case OFTInteger:
104
1.96k
            return CPLString("integer");
105
2.65k
        case OFTInteger64:
106
2.65k
            return CPLString("bigint");
107
497
        case OFTReal:
108
497
            return CPLString("real");
109
4.87k
        case OFTString:
110
4.87k
            return CPLString("text");
111
0
        default:
112
0
            return CPLString("text");
113
9.98k
    }
114
9.98k
}