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 <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>
28 #include <fldmgr.hxx>
29 #include <dbmgr.hxx>
30 #include <wrtsh.hxx>
31 #include <view.hxx>
32 #include <swmodule.hxx>
33 
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;
41 
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.
45 
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)
50 {
51  bool bNumeric = true;
52 
53  SwDBManager* pDBManager = m_pWrtShell ? m_pWrtShell->GetDBManager() :
55 
56  Reference< XConnection> xConnection =
57  pDBManager->RegisterConnection(rDBName);
58 
59  if( !xConnection.is() )
60  return bNumeric;
61 
62  Reference<XColumnsSupplier> xColsSupplier;
63  if(bIsTable)
64  {
65  Reference<XTablesSupplier> xTSupplier(xConnection, UNO_QUERY);
66  if(xTSupplier.is())
67  {
68  Reference<XNameAccess> xTables = xTSupplier->getTables();
69  OSL_ENSURE(xTables->hasByName(rTableQryName), "table not available anymore?");
70  try
71  {
72  Any aTable = xTables->getByName(rTableQryName);
73  Reference<XPropertySet> xPropSet;
74  aTable >>= xPropSet;
75  xColsSupplier.set(xPropSet, UNO_QUERY);
76  }
77  catch (const Exception&)
78  {
79  }
80  }
81  }
82  else
83  {
84  Reference<XQueriesSupplier> xQSupplier(xConnection, UNO_QUERY);
85  if(xQSupplier.is())
86  {
87  Reference<XNameAccess> xQueries = xQSupplier->getQueries();
88  OSL_ENSURE(xQueries->hasByName(rTableQryName), "table not available anymore?");
89  try
90  {
91  Any aQuery = xQueries->getByName(rTableQryName);
92  Reference<XPropertySet> xPropSet;
93  aQuery >>= xPropSet;
94  xColsSupplier.set(xPropSet, UNO_QUERY);
95  }
96  catch (const Exception&)
97  {
98  }
99  }
100  }
101 
102  if(xColsSupplier.is())
103  {
104  Reference <XNameAccess> xCols;
105  try
106  {
107  xCols = xColsSupplier->getColumns();
108  }
109  catch (const Exception&)
110  {
111  OSL_FAIL("Exception in getColumns()");
112  }
113  if(xCols.is() && xCols->hasByName(rFieldName))
114  {
115  Any aCol = xCols->getByName(rFieldName);
116  Reference <XPropertySet> xCol;
117  aCol >>= xCol;
118  Any aType = xCol->getPropertyValue("Type");
119  sal_Int32 eDataType = 0;
120  aType >>= eDataType;
121  switch(eDataType)
122  {
123  case DataType::BIT:
124  case DataType::BOOLEAN:
125  case DataType::TINYINT:
126  case DataType::SMALLINT:
127  case DataType::INTEGER:
128  case DataType::BIGINT:
129  case DataType::FLOAT:
130  case DataType::REAL:
131  case DataType::DOUBLE:
132  case DataType::NUMERIC:
133  case DataType::DECIMAL:
134  case DataType::DATE:
135  case DataType::TIME:
136  case DataType::TIMESTAMP:
137  break;
138 
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:
148  case DataType::BLOB:
149  case DataType::CLOB:
150  case DataType::REF:
151  case DataType::CHAR:
152  case DataType::VARCHAR:
153  case DataType::LONGVARCHAR:
154  default:
155  bNumeric = false;
156  }
157  }
158  }
159  return bNumeric;
160 }
161 
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwView * GetActiveView()
Definition: swmodul1.cxx:115
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:2369
SwWrtShell & GetWrtShell() const
Definition: view.hxx:400
SwDBManager * GetDBManager() const
For evaluation of DB fields (new DB-manager).
Definition: edfld.cxx:336
SwWrtShell * m_pWrtShell
Definition: fldmgr.hxx:103
bool IsDBNumeric(const OUString &rDBName, const OUString &rTableQryName, bool bIsTable, const OUString &rFieldName)
Definition: xfldui.cxx:48