1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26
27
28 #include <tools/debug.hxx>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <com/sun/star/container/XNameAccess.hpp>
31 #include <com/sun/star/sdbc/XDataSource.hpp>
32 #include <com/sun/star/sdbc/DataType.hpp>
33 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
34 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
35 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <comphelper/processfactory.hxx>
38 #include <fldmgr.hxx>
39 #ifndef _DBMGR_HXX
40 #include <dbmgr.hxx>
41 #endif
42 #include <wrtsh.hxx> // Actives Fenster
43 #ifndef _VIEW_HXX
44 #include <view.hxx>
45 #endif
46 #include <swmodule.hxx>
47
48
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::container;
51 using namespace ::com::sun::star::lang;
52 using namespace ::com::sun::star::sdb;
53 using namespace ::com::sun::star::sdbc;
54 using namespace ::com::sun::star::sdbcx;
55 using namespace ::com::sun::star::beans;
56
57
58 // ---------------------------------------------------------------------------
59 // This file contains all routines of the fldui directory, which must compile
60 // with exceptions. So we can reduce the code of the other files, which don't
61 // need any exception handling.
62 // ---------------------------------------------------------------------------
63
64 /*--------------------------------------------------------------------
65 Beschreibung: Ist das Datenbankfeld numerisch?
66 Anm: Im Fehlerfall wird sal_True returnt.
67 --------------------------------------------------------------------*/
68
IsDBNumeric(const String & rDBName,const String & rTblQryName,sal_Bool bIsTable,const String & rFldName)69 sal_Bool SwFldMgr::IsDBNumeric( const String& rDBName, const String& rTblQryName,
70 sal_Bool bIsTable, const String& rFldName)
71 {
72 sal_Bool bNumeric = sal_True;
73
74 SwNewDBMgr* pDBMgr = pWrtShell ? pWrtShell->GetNewDBMgr() :
75 ::GetActiveView()->GetWrtShell().GetNewDBMgr();
76
77 ::rtl::OUString sSource(rDBName);
78 Reference< XConnection> xConnection =
79 pDBMgr->RegisterConnection(sSource);
80
81 if( !xConnection.is() )
82 return bNumeric;
83
84 Reference<XColumnsSupplier> xColsSupplier;
85 if(bIsTable)
86 {
87 Reference<XTablesSupplier> xTSupplier = Reference<XTablesSupplier>(xConnection, UNO_QUERY);
88 if(xTSupplier.is())
89 {
90 Reference<XNameAccess> xTbls = xTSupplier->getTables();
91 DBG_ASSERT(xTbls->hasByName(rTblQryName), "table not available anymore?");
92 try
93 {
94 Any aTable = xTbls->getByName(rTblQryName);
95 Reference<XPropertySet> xPropSet;
96 aTable >>= xPropSet;
97 xColsSupplier = Reference<XColumnsSupplier>(xPropSet, UNO_QUERY);
98 }
99 catch(Exception&){}
100 }
101 }
102 else
103 {
104 Reference<XQueriesSupplier> xQSupplier = Reference<XQueriesSupplier>(xConnection, UNO_QUERY);
105 if(xQSupplier.is())
106 {
107 Reference<XNameAccess> xQueries = xQSupplier->getQueries();
108 DBG_ASSERT(xQueries->hasByName(rTblQryName), "table not available anymore?");
109 try
110 {
111 Any aQuery = xQueries->getByName(rTblQryName);
112 Reference<XPropertySet> xPropSet;
113 aQuery >>= xPropSet;
114 xColsSupplier = Reference<XColumnsSupplier>(xPropSet, UNO_QUERY);
115 }
116 catch(Exception&){}
117 }
118 }
119
120 if(xColsSupplier.is())
121 {
122 Reference <XNameAccess> xCols;
123 try
124 {
125 xCols = xColsSupplier->getColumns();
126 }
127 catch(Exception& )
128 {
129 DBG_ERROR("Exception in getColumns()");
130 }
131 if(xCols.is() && xCols->hasByName(rFldName))
132 {
133 Any aCol = xCols->getByName(rFldName);
134 Reference <XPropertySet> xCol;
135 aCol >>= xCol;
136 Any aType = xCol->getPropertyValue( UniString::CreateFromAscii("Type"));
137 sal_Int32 eDataType = 0;
138 aType >>= eDataType;
139 switch(eDataType)
140 {
141 case DataType::BIT:
142 case DataType::BOOLEAN:
143 case DataType::TINYINT:
144 case DataType::SMALLINT:
145 case DataType::INTEGER:
146 case DataType::BIGINT:
147 case DataType::FLOAT:
148 case DataType::REAL:
149 case DataType::DOUBLE:
150 case DataType::NUMERIC:
151 case DataType::DECIMAL:
152 case DataType::DATE:
153 case DataType::TIME:
154 case DataType::TIMESTAMP:
155 break;
156
157 case DataType::BINARY:
158 case DataType::VARBINARY:
159 case DataType::LONGVARBINARY:
160 case DataType::SQLNULL:
161 case DataType::OTHER:
162 case DataType::OBJECT:
163 case DataType::DISTINCT:
164 case DataType::STRUCT:
165 case DataType::ARRAY:
166 case DataType::BLOB:
167 case DataType::CLOB:
168 case DataType::REF:
169 case DataType::CHAR:
170 case DataType::VARCHAR:
171 case DataType::LONGVARCHAR:
172 default:
173 bNumeric = sal_False;
174 }
175 }
176 }
177 return bNumeric;
178 }
179
180
181