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