LibreOffice Module sw (master) 1
xfldui.cxx
Go to the documentation of this file.
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 <osl/diagnose.h>
21#include <tools/diagnose_ex.h>
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>
34
35using namespace ::com::sun::star::uno;
36using namespace ::com::sun::star::container;
37using namespace ::com::sun::star::lang;
38using namespace ::com::sun::star::sdb;
39using namespace ::com::sun::star::sdbc;
40using namespace ::com::sun::star::sdbcx;
41using namespace ::com::sun::star::beans;
42
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.
46
47// Is the database field numeric?
48// remark: in case of error true is returned
49bool SwFieldMgr::IsDBNumeric( const OUString& rDBName, const OUString& rTableQryName,
50 bool bIsTable, const OUString& rFieldName)
51{
52 bool bNumeric = true;
53
56
57 Reference< XConnection> xConnection =
58 pDBManager->RegisterConnection(rDBName);
59
60 if( !xConnection.is() )
61 return bNumeric;
62
63 Reference<XColumnsSupplier> xColsSupplier;
64 if(bIsTable)
65 {
66 Reference<XTablesSupplier> xTSupplier(xConnection, UNO_QUERY);
67 if(xTSupplier.is())
68 {
69 Reference<XNameAccess> xTables = xTSupplier->getTables();
70 OSL_ENSURE(xTables->hasByName(rTableQryName), "table not available anymore?");
71 try
72 {
73 Any aTable = xTables->getByName(rTableQryName);
74 Reference<XPropertySet> xPropSet;
75 aTable >>= xPropSet;
76 xColsSupplier.set(xPropSet, UNO_QUERY);
77 }
78 catch (const Exception&)
79 {
80 }
81 }
82 }
83 else
84 {
85 Reference<XQueriesSupplier> xQSupplier(xConnection, UNO_QUERY);
86 if(xQSupplier.is())
87 {
88 Reference<XNameAccess> xQueries = xQSupplier->getQueries();
89 OSL_ENSURE(xQueries->hasByName(rTableQryName), "table not available anymore?");
90 try
91 {
92 Any aQuery = xQueries->getByName(rTableQryName);
93 Reference<XPropertySet> xPropSet;
94 aQuery >>= xPropSet;
95 xColsSupplier.set(xPropSet, UNO_QUERY);
96 }
97 catch (const Exception&)
98 {
99 }
100 }
101 }
102
103 if(xColsSupplier.is())
104 {
105 Reference <XNameAccess> xCols;
106 try
107 {
108 xCols = xColsSupplier->getColumns();
109 }
110 catch (const Exception&)
111 {
112 TOOLS_WARN_EXCEPTION( "sw", "getColumns()");
113 }
114 if(xCols.is() && xCols->hasByName(rFieldName))
115 {
116 Any aCol = xCols->getByName(rFieldName);
117 Reference <XPropertySet> xCol;
118 aCol >>= xCol;
119 Any aType = xCol->getPropertyValue("Type");
120 sal_Int32 eDataType = 0;
121 aType >>= eDataType;
122 switch(eDataType)
123 {
124 case DataType::BIT:
125 case DataType::BOOLEAN:
126 case DataType::TINYINT:
127 case DataType::SMALLINT:
128 case DataType::INTEGER:
129 case DataType::BIGINT:
130 case DataType::FLOAT:
131 case DataType::REAL:
132 case DataType::DOUBLE:
133 case DataType::NUMERIC:
134 case DataType::DECIMAL:
135 case DataType::DATE:
136 case DataType::TIME:
137 case DataType::TIMESTAMP:
138 break;
139
140 case DataType::BINARY:
141 case DataType::VARBINARY:
142 case DataType::LONGVARBINARY:
143 case DataType::SQLNULL:
144 case DataType::OTHER:
145 case DataType::OBJECT:
146 case DataType::DISTINCT:
147 case DataType::STRUCT:
148 case DataType::ARRAY:
149 case DataType::BLOB:
150 case DataType::CLOB:
151 case DataType::REF:
152 case DataType::CHAR:
153 case DataType::VARCHAR:
154 case DataType::LONGVARCHAR:
155 default:
156 bNumeric = false;
157 }
158 }
159 }
160 return bNumeric;
161}
162
163/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::sdbc::XConnection > const & RegisterConnection(OUString const &rSource)
create and store or find an already stored connection to a data source for use in SwFieldMgr and SwDB...
Definition: dbmgr.cxx:2345
SwDBManager * GetDBManager() const
For evaluation of DB fields (new DB-manager).
Definition: edfld.cxx:328
SwWrtShell * m_pWrtShell
Definition: fldmgr.hxx:102
bool IsDBNumeric(const OUString &rDBName, const OUString &rTableQryName, bool bIsTable, const OUString &rFieldName)
Definition: xfldui.cxx:49
SwWrtShell & GetWrtShell() const
Definition: view.hxx:412
#define TOOLS_WARN_EXCEPTION(area, stream)
@ Exception
SwView * GetActiveView()
Definition: swmodul1.cxx:116