Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / fldui / xfldui.cxx
blobe5532f89454b0e85c75f8113b37b1d1f56c19eaa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <comphelper/diagnose_ex.hxx>
22 #include <com/sun/star/container/XNameAccess.hpp>
23 #include <com/sun/star/sdbc/DataType.hpp>
24 #include <com/sun/star/sdbc/XConnection.hpp>
25 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
26 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
27 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <fldmgr.hxx>
30 #include <dbmgr.hxx>
31 #include <wrtsh.hxx>
32 #include <view.hxx>
33 #include <swmodule.hxx>
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::container;
37 using namespace ::com::sun::star::lang;
38 using namespace ::com::sun::star::sdb;
39 using namespace ::com::sun::star::sdbc;
40 using namespace ::com::sun::star::sdbcx;
41 using namespace ::com::sun::star::beans;
43 // This file contains all routines of the fldui directory, which must compile
44 // with exceptions. So we can reduce the code of the other files, which don't
45 // need any exception handling.
47 // Is the database field numeric?
48 // remark: in case of error true is returned
49 bool SwFieldMgr::IsDBNumeric( const OUString& rDBName, const OUString& rTableQryName,
50 bool bIsTable, const OUString& rFieldName)
52 bool bNumeric = true;
54 SwDBManager* pDBManager;
55 if (m_pWrtShell)
56 pDBManager = m_pWrtShell->GetDBManager();
57 else
59 if (SwView* pView = GetActiveView())
60 pDBManager = pView->GetWrtShell().GetDBManager();
61 else
62 return bNumeric;
65 Reference< XConnection> xConnection =
66 pDBManager->RegisterConnection(rDBName);
68 if( !xConnection.is() )
69 return bNumeric;
71 Reference<XColumnsSupplier> xColsSupplier;
72 if(bIsTable)
74 Reference<XTablesSupplier> xTSupplier(xConnection, UNO_QUERY);
75 if(xTSupplier.is())
77 Reference<XNameAccess> xTables = xTSupplier->getTables();
78 OSL_ENSURE(xTables->hasByName(rTableQryName), "table not available anymore?");
79 try
81 Any aTable = xTables->getByName(rTableQryName);
82 Reference<XPropertySet> xPropSet;
83 aTable >>= xPropSet;
84 xColsSupplier.set(xPropSet, UNO_QUERY);
86 catch (const Exception&)
91 else
93 Reference<XQueriesSupplier> xQSupplier(xConnection, UNO_QUERY);
94 if(xQSupplier.is())
96 Reference<XNameAccess> xQueries = xQSupplier->getQueries();
97 OSL_ENSURE(xQueries->hasByName(rTableQryName), "table not available anymore?");
98 try
100 Any aQuery = xQueries->getByName(rTableQryName);
101 Reference<XPropertySet> xPropSet;
102 aQuery >>= xPropSet;
103 xColsSupplier.set(xPropSet, UNO_QUERY);
105 catch (const Exception&)
111 if(xColsSupplier.is())
113 Reference <XNameAccess> xCols;
116 xCols = xColsSupplier->getColumns();
118 catch (const Exception&)
120 TOOLS_WARN_EXCEPTION( "sw", "getColumns()");
122 if(xCols.is() && xCols->hasByName(rFieldName))
124 Any aCol = xCols->getByName(rFieldName);
125 Reference <XPropertySet> xCol;
126 aCol >>= xCol;
127 Any aType = xCol->getPropertyValue("Type");
128 sal_Int32 eDataType = 0;
129 aType >>= eDataType;
130 switch(eDataType)
132 case DataType::BIT:
133 case DataType::BOOLEAN:
134 case DataType::TINYINT:
135 case DataType::SMALLINT:
136 case DataType::INTEGER:
137 case DataType::BIGINT:
138 case DataType::FLOAT:
139 case DataType::REAL:
140 case DataType::DOUBLE:
141 case DataType::NUMERIC:
142 case DataType::DECIMAL:
143 case DataType::DATE:
144 case DataType::TIME:
145 case DataType::TIMESTAMP:
146 break;
148 case DataType::BINARY:
149 case DataType::VARBINARY:
150 case DataType::LONGVARBINARY:
151 case DataType::SQLNULL:
152 case DataType::OTHER:
153 case DataType::OBJECT:
154 case DataType::DISTINCT:
155 case DataType::STRUCT:
156 case DataType::ARRAY:
157 case DataType::BLOB:
158 case DataType::CLOB:
159 case DataType::REF:
160 case DataType::CHAR:
161 case DataType::VARCHAR:
162 case DataType::LONGVARCHAR:
163 default:
164 bNumeric = false;
168 return bNumeric;
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */