bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / fldui / xfldui.cxx
blob61624c9f3394a73b9b25e165974fa4a3dfa6913d
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 <com/sun/star/lang/XMultiServiceFactory.hpp>
22 #include <com/sun/star/container/XNameAccess.hpp>
23 #include <com/sun/star/sdbc/XDataSource.hpp>
24 #include <com/sun/star/sdbc/DataType.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 <comphelper/processfactory.hxx>
30 #include <fldmgr.hxx>
31 #include <dbmgr.hxx>
32 #include <wrtsh.hxx> // active window
33 #include <view.hxx>
34 #include <swmodule.hxx>
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::container;
39 using namespace ::com::sun::star::lang;
40 using namespace ::com::sun::star::sdb;
41 using namespace ::com::sun::star::sdbc;
42 using namespace ::com::sun::star::sdbcx;
43 using namespace ::com::sun::star::beans;
46 // ---------------------------------------------------------------------------
47 // This file contains all routines of the fldui directory, which must compile
48 // with exceptions. So we can reduce the code of the other files, which don't
49 // need any exception handling.
50 // ---------------------------------------------------------------------------
52 /*--------------------------------------------------------------------
53 Description: Is the database field numeric?
54 remark: in case of error sal_True is returned
55 --------------------------------------------------------------------*/
57 sal_Bool SwFldMgr::IsDBNumeric( const String& rDBName, const String& rTblQryName,
58 sal_Bool bIsTable, const String& rFldName)
60 sal_Bool bNumeric = sal_True;
62 SwNewDBMgr* pDBMgr = pWrtShell ? pWrtShell->GetNewDBMgr() :
63 ::GetActiveView()->GetWrtShell().GetNewDBMgr();
65 OUString sSource(rDBName);
66 Reference< XConnection> xConnection =
67 pDBMgr->RegisterConnection(sSource);
69 if( !xConnection.is() )
70 return bNumeric;
72 Reference<XColumnsSupplier> xColsSupplier;
73 if(bIsTable)
75 Reference<XTablesSupplier> xTSupplier = Reference<XTablesSupplier>(xConnection, UNO_QUERY);
76 if(xTSupplier.is())
78 Reference<XNameAccess> xTbls = xTSupplier->getTables();
79 OSL_ENSURE(xTbls->hasByName(rTblQryName), "table not available anymore?");
80 try
82 Any aTable = xTbls->getByName(rTblQryName);
83 Reference<XPropertySet> xPropSet;
84 aTable >>= xPropSet;
85 xColsSupplier = Reference<XColumnsSupplier>(xPropSet, UNO_QUERY);
87 catch (const Exception&)
92 else
94 Reference<XQueriesSupplier> xQSupplier = Reference<XQueriesSupplier>(xConnection, UNO_QUERY);
95 if(xQSupplier.is())
97 Reference<XNameAccess> xQueries = xQSupplier->getQueries();
98 OSL_ENSURE(xQueries->hasByName(rTblQryName), "table not available anymore?");
99 try
101 Any aQuery = xQueries->getByName(rTblQryName);
102 Reference<XPropertySet> xPropSet;
103 aQuery >>= xPropSet;
104 xColsSupplier = Reference<XColumnsSupplier>(xPropSet, UNO_QUERY);
106 catch (const Exception&)
112 if(xColsSupplier.is())
114 Reference <XNameAccess> xCols;
117 xCols = xColsSupplier->getColumns();
119 catch (const Exception&)
121 OSL_FAIL("Exception in getColumns()");
123 if(xCols.is() && xCols->hasByName(rFldName))
125 Any aCol = xCols->getByName(rFldName);
126 Reference <XPropertySet> xCol;
127 aCol >>= xCol;
128 Any aType = xCol->getPropertyValue(OUString("Type"));
129 sal_Int32 eDataType = 0;
130 aType >>= eDataType;
131 switch(eDataType)
133 case DataType::BIT:
134 case DataType::BOOLEAN:
135 case DataType::TINYINT:
136 case DataType::SMALLINT:
137 case DataType::INTEGER:
138 case DataType::BIGINT:
139 case DataType::FLOAT:
140 case DataType::REAL:
141 case DataType::DOUBLE:
142 case DataType::NUMERIC:
143 case DataType::DECIMAL:
144 case DataType::DATE:
145 case DataType::TIME:
146 case DataType::TIMESTAMP:
147 break;
149 case DataType::BINARY:
150 case DataType::VARBINARY:
151 case DataType::LONGVARBINARY:
152 case DataType::SQLNULL:
153 case DataType::OTHER:
154 case DataType::OBJECT:
155 case DataType::DISTINCT:
156 case DataType::STRUCT:
157 case DataType::ARRAY:
158 case DataType::BLOB:
159 case DataType::CLOB:
160 case DataType::REF:
161 case DataType::CHAR:
162 case DataType::VARCHAR:
163 case DataType::LONGVARCHAR:
164 default:
165 bNumeric = sal_False;
169 return bNumeric;
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */