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/sdbcx/XTablesSupplier.hpp>
24 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
25 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <fldmgr.hxx>
28 #include <dbmgr.hxx>
29 #include <wrtsh.hxx>
30 #include <view.hxx>
31 #include <swmodule.hxx>
32 
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::container;
35 using namespace ::com::sun::star::lang;
36 using namespace ::com::sun::star::sdb;
37 using namespace ::com::sun::star::sdbc;
38 using namespace ::com::sun::star::sdbcx;
39 using namespace ::com::sun::star::beans;
40 
41 // This file contains all routines of the fldui directory, which must compile
42 // with exceptions. So we can reduce the code of the other files, which don't
43 // need any exception handling.
44 
45 // Is the database field numeric?
46 // remark: in case of error true is returned
47 bool SwFieldMgr::IsDBNumeric( const OUString& rDBName, const OUString& rTableQryName,
48  bool bIsTable, const OUString& rFieldName)
49 {
50  bool bNumeric = true;
51 
52  SwDBManager* pDBManager = m_pWrtShell ? m_pWrtShell->GetDBManager() :
54 
55  Reference< XConnection> xConnection =
56  pDBManager->RegisterConnection(rDBName);
57 
58  if( !xConnection.is() )
59  return bNumeric;
60 
61  Reference<XColumnsSupplier> xColsSupplier;
62  if(bIsTable)
63  {
64  Reference<XTablesSupplier> xTSupplier(xConnection, UNO_QUERY);
65  if(xTSupplier.is())
66  {
67  Reference<XNameAccess> xTables = xTSupplier->getTables();
68  OSL_ENSURE(xTables->hasByName(rTableQryName), "table not available anymore?");
69  try
70  {
71  Any aTable = xTables->getByName(rTableQryName);
72  Reference<XPropertySet> xPropSet;
73  aTable >>= xPropSet;
74  xColsSupplier.set(xPropSet, UNO_QUERY);
75  }
76  catch (const Exception&)
77  {
78  }
79  }
80  }
81  else
82  {
83  Reference<XQueriesSupplier> xQSupplier(xConnection, UNO_QUERY);
84  if(xQSupplier.is())
85  {
86  Reference<XNameAccess> xQueries = xQSupplier->getQueries();
87  OSL_ENSURE(xQueries->hasByName(rTableQryName), "table not available anymore?");
88  try
89  {
90  Any aQuery = xQueries->getByName(rTableQryName);
91  Reference<XPropertySet> xPropSet;
92  aQuery >>= xPropSet;
93  xColsSupplier.set(xPropSet, UNO_QUERY);
94  }
95  catch (const Exception&)
96  {
97  }
98  }
99  }
100 
101  if(xColsSupplier.is())
102  {
104  try
105  {
106  xCols = xColsSupplier->getColumns();
107  }
108  catch (const Exception&)
109  {
110  OSL_FAIL("Exception in getColumns()");
111  }
112  if(xCols.is() && xCols->hasByName(rFieldName))
113  {
114  Any aCol = xCols->getByName(rFieldName);
115  Reference <XPropertySet> xCol;
116  aCol >>= xCol;
117  Any aType = xCol->getPropertyValue("Type");
118  sal_Int32 eDataType = 0;
119  aType >>= eDataType;
120  switch(eDataType)
121  {
122  case DataType::BIT:
123  case DataType::BOOLEAN:
124  case DataType::TINYINT:
125  case DataType::SMALLINT:
126  case DataType::INTEGER:
127  case DataType::BIGINT:
128  case DataType::FLOAT:
129  case DataType::REAL:
130  case DataType::DOUBLE:
131  case DataType::NUMERIC:
132  case DataType::DECIMAL:
133  case DataType::DATE:
134  case DataType::TIME:
135  case DataType::TIMESTAMP:
136  break;
137 
138  case DataType::BINARY:
139  case DataType::VARBINARY:
140  case DataType::LONGVARBINARY:
141  case DataType::SQLNULL:
142  case DataType::OTHER:
143  case DataType::OBJECT:
144  case DataType::DISTINCT:
145  case DataType::STRUCT:
146  case DataType::ARRAY:
147  case DataType::BLOB:
148  case DataType::CLOB:
149  case DataType::REF:
150  case DataType::CHAR:
151  case DataType::VARCHAR:
152  case DataType::LONGVARCHAR:
153  default:
154  bNumeric = false;
155  }
156  }
157  }
158  return bNumeric;
159 }
160 
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwView * GetActiveView()
Definition: swmodul1.cxx:123
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:2427
SwWrtShell & GetWrtShell() const
Definition: view.hxx:400
SwDBManager * GetDBManager() const
For evaluation of DB fields (new DB-manager).
Definition: edfld.cxx:340
SwWrtShell * m_pWrtShell
Definition: fldmgr.hxx:103
bool IsDBNumeric(const OUString &rDBName, const OUString &rTableQryName, bool bIsTable, const OUString &rFieldName)
Definition: xfldui.cxx:47