1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "TPrivilegesResultSet.hxx"
31 using namespace connectivity
;
32 //------------------------------------------------------------------------------
33 using namespace ::com::sun::star::beans
;
34 using namespace ::com::sun::star::uno
;
35 using namespace ::com::sun::star::sdbcx
;
36 using namespace ::com::sun::star::sdbc
;
37 using namespace ::com::sun::star::container
;
38 using namespace ::com::sun::star::lang
;
39 //------------------------------------------------------------------------------
40 OResultSetPrivileges::OResultSetPrivileges( const Reference
< XDatabaseMetaData
>& _rxMeta
42 , const ::rtl::OUString
& schemaPattern
43 , const ::rtl::OUString
& tableNamePattern
)
44 : ODatabaseMetaDataResultSet(eTablePrivileges
)
45 , m_bResetValues(sal_True
)
47 osl_incrementInterlockedCount( &m_refCount
);
49 ::rtl::OUString sUserWorkingFor
;
50 Sequence
< ::rtl::OUString
> sTableTypes(3);
51 // we want all catalogues, all schemas, all tables
52 sTableTypes
[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VIEW"));
53 sTableTypes
[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TABLE"));
54 sTableTypes
[2] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")); // just to be sure to include anything else ....
57 m_xTables
= _rxMeta
->getTables(catalog
,schemaPattern
,tableNamePattern
,sTableTypes
);
58 m_xRow
= Reference
< XRow
>(m_xTables
,UNO_QUERY
);
60 sUserWorkingFor
= _rxMeta
->getUserName();
66 ODatabaseMetaDataResultSet::ORows aRows
;
67 static ODatabaseMetaDataResultSet::ORow
aRow(8);
68 aRow
[5] = new ORowSetValueDecorator(sUserWorkingFor
);
69 aRow
[6] = ODatabaseMetaDataResultSet::getSelectValue();
70 aRow
[7] = new ORowSetValueDecorator(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("YES")));
71 aRows
.push_back(aRow
);
72 aRow
[6] = ODatabaseMetaDataResultSet::getInsertValue();
73 aRows
.push_back(aRow
);
74 aRow
[6] = ODatabaseMetaDataResultSet::getDeleteValue();
75 aRows
.push_back(aRow
);
76 aRow
[6] = ODatabaseMetaDataResultSet::getUpdateValue();
77 aRows
.push_back(aRow
);
78 aRow
[6] = ODatabaseMetaDataResultSet::getCreateValue();
79 aRows
.push_back(aRow
);
80 aRow
[6] = ODatabaseMetaDataResultSet::getReadValue();
81 aRows
.push_back(aRow
);
82 aRow
[6] = ODatabaseMetaDataResultSet::getAlterValue();
83 aRows
.push_back(aRow
);
84 aRow
[6] = ODatabaseMetaDataResultSet::getDropValue();
85 aRows
.push_back(aRow
);
86 aRow
[6] = new ORowSetValueDecorator(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("REFERENCE")));
87 aRows
.push_back(aRow
);
91 osl_decrementInterlockedCount( &m_refCount
);
93 //------------------------------------------------------------------------------
94 const ORowSetValue
& OResultSetPrivileges::getValue(sal_Int32 columnIndex
)
101 if ( m_xRow
.is() && m_bResetValues
)
103 (*m_aRowsIter
)[1] = new ORowSetValueDecorator(m_xRow
->getString(1));
104 if ( m_xRow
->wasNull() )
105 (*m_aRowsIter
)[1]->setNull();
106 (*m_aRowsIter
)[2] = new ORowSetValueDecorator(m_xRow
->getString(2));
107 if ( m_xRow
->wasNull() )
108 (*m_aRowsIter
)[2]->setNull();
109 (*m_aRowsIter
)[3] = new ORowSetValueDecorator(m_xRow
->getString(3));
110 if ( m_xRow
->wasNull() )
111 (*m_aRowsIter
)[3]->setNull();
113 m_bResetValues
= sal_False
;
116 return ODatabaseMetaDataResultSet::getValue(columnIndex
);
118 // -----------------------------------------------------------------------------
119 void SAL_CALL
OResultSetPrivileges::disposing(void)
121 ODatabaseMetaDataResultSet::disposing();
125 // -----------------------------------------------------------------------------
126 sal_Bool SAL_CALL
OResultSetPrivileges::next( ) throw(SQLException
, RuntimeException
)
128 ::osl::MutexGuard
aGuard( m_aMutex
);
129 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
131 sal_Bool bReturn
= sal_False
;
132 if ( m_xTables
.is() )
136 m_bResetValues
= sal_True
;
137 if ( !m_xTables
->next() )
141 bReturn
= ODatabaseMetaDataResultSet::next();
145 m_bResetValues
= bReturn
= m_xTables
->next();
150 // -----------------------------------------------------------------------------
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */