Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/connectivity/source/drivers/file/FDriver.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <file/FDriver.hxx>
21
#include <file/FConnection.hxx>
22
#include <file/fcode.hxx>
23
#include <comphelper/servicehelper.hxx>
24
#include <comphelper/types.hxx>
25
#include <cppuhelper/supportsservice.hxx>
26
#include <connectivity/dbexception.hxx>
27
#include <strings.hrc>
28
#include <resource/sharedresources.hxx>
29
#include <utility>
30
31
32
using namespace connectivity::file;
33
using namespace com::sun::star::uno;
34
using namespace com::sun::star::lang;
35
using namespace com::sun::star::beans;
36
using namespace com::sun::star::sdbc;
37
using namespace com::sun::star::sdbcx;
38
39
OFileDriver::OFileDriver(css::uno::Reference< css::uno::XComponentContext > _xContext)
40
1
    : ODriver_BASE(m_aMutex)
41
1
    ,m_xContext(std::move(_xContext))
42
1
{
43
1
}
44
45
void OFileDriver::disposing()
46
0
{
47
0
    ::osl::MutexGuard aGuard(m_aMutex);
48
49
50
0
    for (auto const& connection : m_xConnections)
51
0
    {
52
0
        rtl::Reference< OConnection > xComp(connection);
53
0
        if (xComp.is())
54
0
            xComp->dispose();
55
0
    }
56
0
    m_xConnections.clear();
57
58
0
    ODriver_BASE::disposing();
59
0
}
60
61
// XServiceInfo
62
63
OUString SAL_CALL OFileDriver::getImplementationName(  )
64
0
{
65
0
    return u"com.sun.star.sdbc.driver.file.Driver"_ustr;
66
0
}
67
68
sal_Bool SAL_CALL OFileDriver::supportsService( const OUString& _rServiceName )
69
0
{
70
0
    return cppu::supportsService(this, _rServiceName);
71
0
}
72
73
74
Sequence< OUString > SAL_CALL OFileDriver::getSupportedServiceNames(  )
75
0
{
76
0
    return { u"com.sun.star.sdbc.Driver"_ustr, u"com.sun.star.sdbcx.Driver"_ustr };
77
0
}
78
79
80
Reference< XConnection > SAL_CALL OFileDriver::connect( const OUString& url, const Sequence< PropertyValue >& info )
81
0
{
82
0
    ::osl::MutexGuard aGuard( m_aMutex );
83
0
    checkDisposed(ODriver_BASE::rBHelper.bDisposed);
84
85
0
    rtl::Reference<OConnection> pCon = new OConnection(this);
86
0
    pCon->construct(url,info);
87
0
    m_xConnections.push_back(pCon);
88
89
0
    return pCon;
90
0
}
91
92
sal_Bool SAL_CALL OFileDriver::acceptsURL( const OUString& url )
93
0
{
94
0
    return url.startsWith("sdbc:file:");
95
0
}
96
97
Sequence< DriverPropertyInfo > SAL_CALL OFileDriver::getPropertyInfo( const OUString& url, const Sequence< PropertyValue >& /*info*/ )
98
0
{
99
0
    if ( acceptsURL(url) )
100
0
    {
101
102
0
        Sequence< OUString > aBoolean { u"0"_ustr, u"1"_ustr };
103
104
0
        return
105
0
        {
106
0
             {
107
0
                u"CharSet"_ustr
108
0
                ,u"CharSet of the database."_ustr
109
0
                ,false
110
0
                ,{}
111
0
                ,{}
112
0
             },
113
0
             {
114
0
                u"Extension"_ustr
115
0
                ,u"Extension of the file format."_ustr
116
0
                ,false
117
0
                ,u".*"_ustr
118
0
                ,{}
119
0
             },
120
0
             {
121
0
                u"ShowDeleted"_ustr
122
0
                ,u"Display inactive records."_ustr
123
0
                ,false
124
0
                ,u"0"_ustr
125
0
                ,aBoolean
126
0
             },
127
0
             {
128
0
                u"EnableSQL92Check"_ustr
129
0
                ,u"Use SQL92 naming constraints."_ustr
130
0
                ,false
131
0
                ,u"0"_ustr
132
0
                ,aBoolean
133
0
             },
134
0
             {
135
0
                u"UseRelativePath"_ustr
136
0
                ,u"Handle the connection url as relative path."_ustr
137
0
                ,false
138
0
                ,u"0"_ustr
139
0
                ,aBoolean
140
0
             },
141
0
             {
142
0
                u"URL"_ustr
143
0
                ,u"The URL of the database document which is used to create an absolute path."_ustr
144
0
                ,false
145
0
                ,{}
146
0
                ,{}
147
0
             }
148
0
        };
149
0
    } // if ( acceptsURL(url) )
150
0
    {
151
0
        ::connectivity::SharedResources aResources;
152
0
        const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
153
0
        ::dbtools::throwGenericSQLException(sMessage ,*this);
154
0
    } // if ( ! acceptsURL(url) )
155
0
}
156
157
sal_Int32 SAL_CALL OFileDriver::getMajorVersion(  )
158
0
{
159
0
    return 1;
160
0
}
161
162
sal_Int32 SAL_CALL OFileDriver::getMinorVersion(  )
163
0
{
164
0
    return 0;
165
0
}
166
167
168
// XDataDefinitionSupplier
169
Reference< XTablesSupplier > SAL_CALL OFileDriver::getDataDefinitionByConnection( const Reference< css::sdbc::XConnection >& connection )
170
0
{
171
0
    ::osl::MutexGuard aGuard( m_aMutex );
172
0
    checkDisposed(ODriver_BASE::rBHelper.bDisposed);
173
174
0
    if (OConnection* pSearchConnection = comphelper::getFromUnoTunnel<OConnection>(connection))
175
0
    {
176
0
        for (auto const& elem : m_xConnections)
177
0
        {
178
0
            if (elem.get().get() == pSearchConnection)
179
0
                return pSearchConnection->createCatalog();
180
0
        }
181
0
    }
182
0
    return {};
183
0
}
184
185
186
Reference< XTablesSupplier > SAL_CALL OFileDriver::getDataDefinitionByURL( const OUString& url, const Sequence< PropertyValue >& info )
187
0
{
188
0
    if ( ! acceptsURL(url) )
189
0
    {
190
0
        ::connectivity::SharedResources aResources;
191
0
        const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
192
0
        ::dbtools::throwGenericSQLException(sMessage ,*this);
193
0
    }
194
0
    return getDataDefinitionByConnection(connect(url,info));
195
0
}
196
197
198
OOperandAttr::OOperandAttr(sal_uInt16 _nPos,const Reference< XPropertySet>& _xColumn)
199
0
    : OOperandRow(_nPos,::comphelper::getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))))
200
0
{
201
0
}
202
203
204
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */