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