merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / fldui / xfldui.cxx
blobb19fe540239cf4f77c87f9eaddd381b20fcf3e25
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xfldui.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <tools/debug.hxx>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/container/XNameAccess.hpp>
38 #include <com/sun/star/sdbc/XDataSource.hpp>
39 #include <com/sun/star/sdbc/DataType.hpp>
40 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
41 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
42 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
43 #include <com/sun/star/beans/XPropertySet.hpp>
44 #include <comphelper/processfactory.hxx>
45 #include <fldmgr.hxx>
46 #ifndef _DBMGR_HXX
47 #include <dbmgr.hxx>
48 #endif
49 #include <wrtsh.hxx> // Actives Fenster
50 #ifndef _VIEW_HXX
51 #include <view.hxx>
52 #endif
53 #include <swmodule.hxx>
56 using namespace ::com::sun::star::uno;
57 using namespace ::com::sun::star::container;
58 using namespace ::com::sun::star::lang;
59 using namespace ::com::sun::star::sdb;
60 using namespace ::com::sun::star::sdbc;
61 using namespace ::com::sun::star::sdbcx;
62 using namespace ::com::sun::star::beans;
65 // ---------------------------------------------------------------------------
66 // This file contains all routines of the fldui directory, which must compile
67 // with exceptions. So we can reduce the code of the other files, which don't
68 // need any exception handling.
69 // ---------------------------------------------------------------------------
71 /*--------------------------------------------------------------------
72 Beschreibung: Ist das Datenbankfeld numerisch?
73 Anm: Im Fehlerfall wird TRUE returnt.
74 --------------------------------------------------------------------*/
76 BOOL SwFldMgr::IsDBNumeric( const String& rDBName, const String& rTblQryName,
77 BOOL bIsTable, const String& rFldName)
79 BOOL bNumeric = TRUE;
81 SwNewDBMgr* pDBMgr = pWrtShell ? pWrtShell->GetNewDBMgr() :
82 ::GetActiveView()->GetWrtShell().GetNewDBMgr();
84 ::rtl::OUString sSource(rDBName);
85 Reference< XConnection> xConnection =
86 pDBMgr->RegisterConnection(sSource);
88 if( !xConnection.is() )
89 return bNumeric;
91 Reference<XColumnsSupplier> xColsSupplier;
92 if(bIsTable)
94 Reference<XTablesSupplier> xTSupplier = Reference<XTablesSupplier>(xConnection, UNO_QUERY);
95 if(xTSupplier.is())
97 Reference<XNameAccess> xTbls = xTSupplier->getTables();
98 DBG_ASSERT(xTbls->hasByName(rTblQryName), "table not available anymore?");
99 try
101 Any aTable = xTbls->getByName(rTblQryName);
102 Reference<XPropertySet> xPropSet;
103 aTable >>= xPropSet;
104 xColsSupplier = Reference<XColumnsSupplier>(xPropSet, UNO_QUERY);
106 catch(Exception&){}
109 else
111 Reference<XQueriesSupplier> xQSupplier = Reference<XQueriesSupplier>(xConnection, UNO_QUERY);
112 if(xQSupplier.is())
114 Reference<XNameAccess> xQueries = xQSupplier->getQueries();
115 DBG_ASSERT(xQueries->hasByName(rTblQryName), "table not available anymore?");
118 Any aQuery = xQueries->getByName(rTblQryName);
119 Reference<XPropertySet> xPropSet;
120 aQuery >>= xPropSet;
121 xColsSupplier = Reference<XColumnsSupplier>(xPropSet, UNO_QUERY);
123 catch(Exception&){}
127 if(xColsSupplier.is())
129 Reference <XNameAccess> xCols;
132 xCols = xColsSupplier->getColumns();
134 catch(Exception& )
136 DBG_ERROR("Exception in getColumns()");
138 if(xCols.is() && xCols->hasByName(rFldName))
140 Any aCol = xCols->getByName(rFldName);
141 Reference <XPropertySet> xCol;
142 aCol >>= xCol;
143 Any aType = xCol->getPropertyValue( UniString::CreateFromAscii("Type"));
144 sal_Int32 eDataType = 0;
145 aType >>= eDataType;
146 switch(eDataType)
148 case DataType::BIT:
149 case DataType::BOOLEAN:
150 case DataType::TINYINT:
151 case DataType::SMALLINT:
152 case DataType::INTEGER:
153 case DataType::BIGINT:
154 case DataType::FLOAT:
155 case DataType::REAL:
156 case DataType::DOUBLE:
157 case DataType::NUMERIC:
158 case DataType::DECIMAL:
159 case DataType::DATE:
160 case DataType::TIME:
161 case DataType::TIMESTAMP:
162 break;
164 case DataType::BINARY:
165 case DataType::VARBINARY:
166 case DataType::LONGVARBINARY:
167 case DataType::SQLNULL:
168 case DataType::OTHER:
169 case DataType::OBJECT:
170 case DataType::DISTINCT:
171 case DataType::STRUCT:
172 case DataType::ARRAY:
173 case DataType::BLOB:
174 case DataType::CLOB:
175 case DataType::REF:
176 case DataType::CHAR:
177 case DataType::VARCHAR:
178 case DataType::LONGVARCHAR:
179 default:
180 bNumeric = FALSE;
184 return bNumeric;