1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <osl/diagnose.h>
21 #include <com/sun/star/container/XNameAccess.hpp>
22 #include <com/sun/star/sdbc/DataType.hpp>
23 #include <com/sun/star/sdbc/XConnection.hpp>
24 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
25 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
26 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <swmodule.hxx>
34 using namespace ::com::sun::star::uno
;
35 using namespace ::com::sun::star::container
;
36 using namespace ::com::sun::star::lang
;
37 using namespace ::com::sun::star::sdb
;
38 using namespace ::com::sun::star::sdbc
;
39 using namespace ::com::sun::star::sdbcx
;
40 using namespace ::com::sun::star::beans
;
42 // This file contains all routines of the fldui directory, which must compile
43 // with exceptions. So we can reduce the code of the other files, which don't
44 // need any exception handling.
46 // Is the database field numeric?
47 // remark: in case of error true is returned
48 bool SwFieldMgr::IsDBNumeric( const OUString
& rDBName
, const OUString
& rTableQryName
,
49 bool bIsTable
, const OUString
& rFieldName
)
53 SwDBManager
* pDBManager
= m_pWrtShell
? m_pWrtShell
->GetDBManager() :
54 ::GetActiveView()->GetWrtShell().GetDBManager();
56 Reference
< XConnection
> xConnection
=
57 pDBManager
->RegisterConnection(rDBName
);
59 if( !xConnection
.is() )
62 Reference
<XColumnsSupplier
> xColsSupplier
;
65 Reference
<XTablesSupplier
> xTSupplier(xConnection
, UNO_QUERY
);
68 Reference
<XNameAccess
> xTables
= xTSupplier
->getTables();
69 OSL_ENSURE(xTables
->hasByName(rTableQryName
), "table not available anymore?");
72 Any aTable
= xTables
->getByName(rTableQryName
);
73 Reference
<XPropertySet
> xPropSet
;
75 xColsSupplier
.set(xPropSet
, UNO_QUERY
);
77 catch (const Exception
&)
84 Reference
<XQueriesSupplier
> xQSupplier(xConnection
, UNO_QUERY
);
87 Reference
<XNameAccess
> xQueries
= xQSupplier
->getQueries();
88 OSL_ENSURE(xQueries
->hasByName(rTableQryName
), "table not available anymore?");
91 Any aQuery
= xQueries
->getByName(rTableQryName
);
92 Reference
<XPropertySet
> xPropSet
;
94 xColsSupplier
.set(xPropSet
, UNO_QUERY
);
96 catch (const Exception
&)
102 if(xColsSupplier
.is())
104 Reference
<XNameAccess
> xCols
;
107 xCols
= xColsSupplier
->getColumns();
109 catch (const Exception
&)
111 OSL_FAIL("Exception in getColumns()");
113 if(xCols
.is() && xCols
->hasByName(rFieldName
))
115 Any aCol
= xCols
->getByName(rFieldName
);
116 Reference
<XPropertySet
> xCol
;
118 Any aType
= xCol
->getPropertyValue("Type");
119 sal_Int32 eDataType
= 0;
124 case DataType::BOOLEAN
:
125 case DataType::TINYINT
:
126 case DataType::SMALLINT
:
127 case DataType::INTEGER
:
128 case DataType::BIGINT
:
129 case DataType::FLOAT
:
131 case DataType::DOUBLE
:
132 case DataType::NUMERIC
:
133 case DataType::DECIMAL
:
136 case DataType::TIMESTAMP
:
139 case DataType::BINARY
:
140 case DataType::VARBINARY
:
141 case DataType::LONGVARBINARY
:
142 case DataType::SQLNULL
:
143 case DataType::OTHER
:
144 case DataType::OBJECT
:
145 case DataType::DISTINCT
:
146 case DataType::STRUCT
:
147 case DataType::ARRAY
:
152 case DataType::VARCHAR
:
153 case DataType::LONGVARCHAR
:
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */