Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / ado / AKeys.cxx
blobb272dac406af0d5cca8da97cfb750a908e7470ab
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 <comphelper/property.hxx>
30 #include <connectivity/dbexception.hxx>
31 #include "resource/ado_res.hrc"
33 #if defined __MINGW32__
34 #pragma GCC diagnostic warning "-Wwrite-strings"
35 #endif
37 using namespace ::comphelper;
38 using namespace connectivity;
39 using namespace connectivity::ado;
40 using namespace com::sun::star::uno;
41 using namespace com::sun::star::lang;
42 using namespace com::sun::star::beans;
43 using namespace com::sun::star::sdbc;
44 using namespace com::sun::star::sdbcx;
45 using namespace com::sun::star::container;
47 sdbcx::ObjectType OKeys::createObject(const OUString& _rName)
49 return new OAdoKey(isCaseSensitive(),m_pConnection,m_aCollection.GetItem(_rName));
52 void OKeys::impl_refresh() throw(RuntimeException)
54 m_aCollection.Refresh();
57 Reference< XPropertySet > OKeys::createDescriptor()
59 return new OAdoKey(isCaseSensitive(),m_pConnection);
62 // XAppend
63 sdbcx::ObjectType OKeys::appendObject( const OUString&, const Reference< XPropertySet >& descriptor )
65 OAdoKey* pKey = NULL;
66 if ( !getImplementation( pKey, descriptor ) || pKey == NULL)
67 m_pConnection->throwGenericSQLException( STR_INVALID_KEY_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) );
69 // To pass as column parameter to Key's Apppend method
70 OLEVariant vOptional;
71 vOptional.setNoArg();
73 #if OSL_DEBUG_LEVEL > 0
74 KeyTypeEnum eKey =
75 #endif
76 OAdoKey::Map2KeyRule(getINT32(descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))));
77 #if OSL_DEBUG_LEVEL > 0
78 (void)eKey;
79 #endif
81 WpADOKey aKey = pKey->getImpl();
82 OUString sName = aKey.get_Name();
83 if(!sName.getLength())
84 aKey.put_Name(OUString("PrimaryKey") );
86 ADOKeys* pKeys = m_aCollection;
87 if ( FAILED(pKeys->Append(OLEVariant((ADOKey*)aKey),
88 adKeyPrimary, // must be every time adKeyPrimary
89 vOptional)) )
91 ADOS::ThrowException(*m_pConnection->getConnection(),static_cast<XTypeProvider*>(this));
92 // just make sure that an SQLExceptionis thrown here
93 m_pConnection->throwGenericSQLException( STR_INVALID_KEY_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) );
96 return new OAdoKey(isCaseSensitive(),m_pConnection,pKey->getImpl());
99 // XDrop
100 void OKeys::dropObject(sal_Int32 /*_nPos*/,const OUString& _sElementName)
102 if(!m_aCollection.Delete(OLEVariant(_sElementName)))
103 ADOS::ThrowException(*m_pConnection->getConnection(),static_cast<XTypeProvider*>(this));
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */