Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : */
9 :
10 : #include "Table.hxx"
11 : #include "Tables.hxx"
12 : #include "Catalog.hxx"
13 :
14 : #include <connectivity/dbtools.hxx>
15 :
16 : #include <com/sun/star/sdbc/XRow.hpp>
17 :
18 : using namespace ::connectivity;
19 : using namespace ::connectivity::firebird;
20 : using namespace ::connectivity::sdbcx;
21 : using namespace ::cppu;
22 : using namespace ::osl;
23 :
24 : using namespace ::com::sun::star;
25 : using namespace ::com::sun::star::beans;
26 : using namespace ::com::sun::star::container;
27 : using namespace ::com::sun::star::lang;
28 : using namespace ::com::sun::star::sdbc;
29 : using namespace ::com::sun::star::uno;
30 :
31 :
32 : //----- OCollection -----------------------------------------------------------
33 0 : void Tables::impl_refresh()
34 : throw(RuntimeException)
35 : {
36 0 : static_cast<Catalog&>(m_rParent).refreshTables();
37 0 : }
38 :
39 2 : ObjectType Tables::createObject(const OUString& rName)
40 : {
41 : // Only retrieving a single table, so table type is irrelevant (param 4)
42 2 : uno::Reference< XResultSet > xTables = m_xMetaData->getTables(Any(),
43 : OUString(),
44 : rName,
45 2 : uno::Sequence< OUString >());
46 :
47 2 : if (!xTables.is())
48 0 : throw RuntimeException();
49 :
50 4 : uno::Reference< XRow > xRow(xTables,UNO_QUERY);
51 :
52 2 : if (!xRow.is() || !xTables->next())
53 0 : throw RuntimeException();
54 :
55 : ObjectType xRet(new Table(this,
56 : m_rMutex,
57 2 : m_xMetaData->getConnection(),
58 2 : xRow->getString(3), // Name
59 2 : xRow->getString(4), // Type
60 6 : xRow->getString(5))); // Description / Remarks / Comments
61 :
62 2 : if (xTables->next())
63 0 : throw RuntimeException(); // Only one table should be returned
64 :
65 4 : return xRet;
66 : }
67 :
68 0 : uno::Reference< XPropertySet > Tables::createDescriptor()
69 : {
70 : // There is some internal magic so that the same class can be used as either
71 : // a descriptor or as a normal table. See VTable.cxx for the details. In our
72 : // case we just need to ensure we use the correct constructor.
73 0 : return new Table(this, m_rMutex, m_xMetaData->getConnection());
74 : }
75 :
76 : //----- XAppend ---------------------------------------------------------------
77 0 : ObjectType Tables::appendObject(const OUString& rName,
78 : const uno::Reference< XPropertySet >& rDescriptor)
79 : {
80 : OUString sSql(::dbtools::createSqlCreateTableStatement(rDescriptor,
81 0 : m_xMetaData->getConnection()));
82 0 : m_xMetaData->getConnection()->createStatement()->execute(sSql);
83 :
84 0 : return createObject(rName);
85 : }
86 :
87 : //----- XDrop -----------------------------------------------------------------
88 0 : void Tables::dropObject(sal_Int32 nPosition, const OUString& sName)
89 : {
90 0 : uno::Reference< XPropertySet > xTable(getObject(nPosition));
91 :
92 0 : if (!ODescriptor::isNew(xTable))
93 : {
94 0 : OUStringBuffer sSql("DROP ");
95 :
96 0 : OUString sType;
97 0 : xTable->getPropertyValue("Type") >>= sType;
98 0 : sSql.append(sType);
99 :
100 0 : const OUString sQuoteString = m_xMetaData->getIdentifierQuoteString();
101 0 : sSql.append(::dbtools::quoteName(sQuoteString,sName));
102 :
103 0 : m_xMetaData->getConnection()->createStatement()->execute(sSql.makeStringAndClear());
104 0 : }
105 0 : }
106 :
107 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|