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