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_connectivity.hxx" 26 #include "adabas/BCatalog.hxx" 27 #include "adabas/BConnection.hxx" 28 #include "adabas/BGroups.hxx" 29 #include "adabas/BUsers.hxx" 30 #include "adabas/BTables.hxx" 31 #include "adabas/BViews.hxx" 32 #include <com/sun/star/sdbc/XRow.hpp> 33 #include <com/sun/star/sdbc/XResultSet.hpp> 34 #include <comphelper/types.hxx> 35 36 37 // ------------------------------------------------------------------------- 38 using namespace connectivity; 39 using namespace connectivity::adabas; 40 using namespace ::com::sun::star::uno; 41 using namespace ::com::sun::star::beans; 42 using namespace ::com::sun::star::sdbcx; 43 using namespace ::com::sun::star::sdbc; 44 using namespace ::com::sun::star::container; 45 using namespace ::com::sun::star::lang; 46 // ----------------------------------------------------------------------------- 47 OAdabasCatalog::OAdabasCatalog(SQLHANDLE _aConnectionHdl, OAdabasConnection* _pCon) : connectivity::sdbcx::OCatalog(_pCon) 48 ,m_pConnection(_pCon) 49 ,m_aConnectionHdl(_aConnectionHdl) 50 { 51 } 52 // ----------------------------------------------------------------------------- 53 ::rtl::OUString OAdabasCatalog::buildName(const Reference< XRow >& _xRow) 54 { 55 ::rtl::OUString sName; 56 sName = _xRow->getString(2); 57 if ( sName.getLength() ) 58 sName += OAdabasCatalog::getDot(); 59 sName += _xRow->getString(3); 60 61 62 return sName; 63 } 64 // ----------------------------------------------------------------------------- 65 void OAdabasCatalog::fillVector(const ::rtl::OUString& _sQuery,TStringVector& _rVector) 66 { 67 Reference< XStatement > xStmt = m_pConnection->createStatement( ); 68 OSL_ENSURE(xStmt.is(),"OAdabasCatalog::fillVector: Could not create a statement!"); 69 Reference< XResultSet > xResult = xStmt->executeQuery(_sQuery); 70 71 fillNames(xResult,_rVector); 72 ::comphelper::disposeComponent(xStmt); 73 74 } 75 // ------------------------------------------------------------------------- 76 void OAdabasCatalog::refreshTables() 77 { 78 TStringVector aVector; 79 { 80 Sequence< ::rtl::OUString > aTypes(1); 81 aTypes[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")); 82 Reference< XResultSet > xResult = m_xMetaData->getTables(Any(), 83 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")), 84 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")), 85 aTypes); 86 fillNames(xResult,aVector); 87 } 88 89 if(m_pTables) 90 m_pTables->reFill(aVector); 91 else 92 m_pTables = new OTables(m_xMetaData,*this,m_aMutex,aVector); 93 } 94 // ------------------------------------------------------------------------- 95 void OAdabasCatalog::refreshViews() 96 { 97 TStringVector aVector; 98 static const ::rtl::OUString s_sView(RTL_CONSTASCII_USTRINGPARAM("SELECT DISTINCT NULL,DOMAIN.VIEWDEFS.OWNER, DOMAIN.VIEWDEFS.VIEWNAME FROM DOMAIN.VIEWDEFS")); 99 fillVector(s_sView,aVector); 100 101 if(m_pViews) 102 m_pViews->reFill(aVector); 103 else 104 m_pViews = new OViews(m_xMetaData,*this,m_aMutex,aVector); 105 } 106 // ------------------------------------------------------------------------- 107 void OAdabasCatalog::refreshGroups() 108 { 109 TStringVector aVector; 110 static const ::rtl::OUString s_sGroup(RTL_CONSTASCII_USTRINGPARAM("SELECT DISTINCT NULL,NULL,GROUPNAME FROM DOMAIN.USERS WHERE GROUPNAME IS NOT NULL AND GROUPNAME <> ' '")); 111 fillVector(s_sGroup,aVector); 112 if(m_pGroups) 113 m_pGroups->reFill(aVector); 114 else 115 m_pGroups = new OGroups(*this,m_aMutex,aVector,m_pConnection,this); 116 } 117 // ------------------------------------------------------------------------- 118 void OAdabasCatalog::refreshUsers() 119 { 120 TStringVector aVector; 121 static const ::rtl::OUString s_sUsers(RTL_CONSTASCII_USTRINGPARAM("SELECT DISTINCT NULL,NULL,USERNAME FROM DOMAIN.USERS WHERE USERNAME IS NOT NULL AND USERNAME <> ' ' AND USERNAME <> 'CONTROL'")); 122 fillVector(s_sUsers,aVector); 123 124 if(m_pUsers) 125 m_pUsers->reFill(aVector); 126 else 127 m_pUsers = new OUsers(*this,m_aMutex,aVector,m_pConnection,this); 128 } 129 // ------------------------------------------------------------------------- 130 const ::rtl::OUString& OAdabasCatalog::getDot() 131 { 132 static const ::rtl::OUString sDot(RTL_CONSTASCII_USTRINGPARAM(".")); 133 return sDot; 134 } 135 // ----------------------------------------------------------------------------- 136 void OAdabasCatalog::correctColumnProperties(sal_Int32 /*_nPrec*/, sal_Int32& _rnType,::rtl::OUString& _rsTypeName) 137 { 138 switch(_rnType) 139 { 140 case DataType::DECIMAL: 141 { 142 static const ::rtl::OUString sDecimal(RTL_CONSTASCII_USTRINGPARAM("DECIMAL")); 143 if(_rnType == DataType::DECIMAL && _rsTypeName == sDecimal) 144 _rnType = DataType::NUMERIC; 145 } 146 break; 147 case DataType::FLOAT: 148 // if(_nPrec >= 16) 149 { 150 static const ::rtl::OUString sDouble(RTL_CONSTASCII_USTRINGPARAM("DOUBLE PRECISION")); 151 _rsTypeName = sDouble; 152 _rnType = DataType::DOUBLE; 153 } 154 // else if(_nPrec > 15) 155 // { 156 // static const ::rtl::OUString sReal = ::rtl::OUString::createFromAscii("REAL"); 157 // _rsTypeName = sReal; 158 // _rnType = DataType::REAL; 159 // } 160 break; 161 } 162 } 163 // ----------------------------------------------------------------------------- 164 165