bump product version to 6.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / ado / AKeys.cxx
blob559d7a7f101d767503001c2225ff89f8d823f7db
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <ado/AKeys.hxx>
21 #include <ado/AKey.hxx>
22 #include <com/sun/star/sdbc/XRow.hpp>
23 #include <com/sun/star/sdbc/XResultSet.hpp>
24 #include <com/sun/star/sdbcx/KeyType.hpp>
25 #include <com/sun/star/sdbc/KeyRule.hpp>
26 #include <ado/AConnection.hxx>
27 #include <comphelper/types.hxx>
28 #include <ado/Awrapado.hxx>
29 #include <connectivity/dbexception.hxx>
30 #include <strings.hrc>
32 using namespace ::comphelper;
33 using namespace connectivity;
34 using namespace connectivity::ado;
35 using namespace com::sun::star::uno;
36 using namespace com::sun::star::lang;
37 using namespace com::sun::star::beans;
38 using namespace com::sun::star::sdbc;
39 using namespace com::sun::star::sdbcx;
40 using namespace com::sun::star::container;
42 sdbcx::ObjectType OKeys::createObject(const OUString& _rName)
44 return new OAdoKey(isCaseSensitive(),m_pConnection,m_aCollection.GetItem(_rName));
47 void OKeys::impl_refresh()
49 m_aCollection.Refresh();
52 Reference< XPropertySet > OKeys::createDescriptor()
54 return new OAdoKey(isCaseSensitive(),m_pConnection);
57 // XAppend
58 sdbcx::ObjectType OKeys::appendObject( const OUString&, const Reference< XPropertySet >& descriptor )
60 OAdoKey* pKey = nullptr;
61 if ( !getImplementation( pKey, descriptor ) || pKey == nullptr)
62 m_pConnection->throwGenericSQLException( STR_INVALID_KEY_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) );
64 // To pass as column parameter to Key's Append method
65 OLEVariant vOptional;
66 vOptional.setNoArg();
68 OAdoKey::Map2KeyRule(getINT32(descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))));
70 WpADOKey aKey = pKey->getImpl();
71 OUString sName = aKey.get_Name();
72 if(!sName.getLength())
73 aKey.put_Name("PrimaryKey");
75 ADOKeys* pKeys = m_aCollection;
76 if ( FAILED(pKeys->Append(OLEVariant(static_cast<ADOKey*>(aKey)),
77 adKeyPrimary, // must be every time adKeyPrimary
78 vOptional)) )
80 ADOS::ThrowException(*m_pConnection->getConnection(),static_cast<XTypeProvider*>(this));
81 // just make sure that an SQLExceptionis thrown here
82 m_pConnection->throwGenericSQLException( STR_INVALID_KEY_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) );
85 return new OAdoKey(isCaseSensitive(),m_pConnection,pKey->getImpl());
88 // XDrop
89 void OKeys::dropObject(sal_Int32 /*_nPos*/,const OUString& _sElementName)
91 if(!m_aCollection.Delete(OLEVariant(_sElementName).getString()))
92 ADOS::ThrowException(*m_pConnection->getConnection(),static_cast<XTypeProvider*>(this));
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */