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