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 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "TPrivilegesResultSet.hxx"
21 :
22 : using namespace connectivity;
23 :
24 : using namespace ::com::sun::star::beans;
25 : using namespace ::com::sun::star::uno;
26 : using namespace ::com::sun::star::sdbcx;
27 : using namespace ::com::sun::star::sdbc;
28 : using namespace ::com::sun::star::container;
29 : using namespace ::com::sun::star::lang;
30 :
31 2 : OResultSetPrivileges::OResultSetPrivileges( const Reference< XDatabaseMetaData>& _rxMeta
32 : , const Any& catalog
33 : , const OUString& schemaPattern
34 : , const OUString& tableNamePattern)
35 : : ODatabaseMetaDataResultSet(eTablePrivileges)
36 2 : , m_bResetValues(true)
37 : {
38 2 : osl_atomic_increment( &m_refCount );
39 : {
40 2 : OUString sUserWorkingFor;
41 4 : Sequence< OUString > sTableTypes(3);
42 : // we want all catalogues, all schemas, all tables
43 2 : sTableTypes[0] = "VIEW";
44 2 : sTableTypes[1] = "TABLE";
45 2 : sTableTypes[2] = "%"; // just to be sure to include anything else ....
46 : try
47 : {
48 2 : m_xTables = _rxMeta->getTables(catalog,schemaPattern,tableNamePattern,sTableTypes);
49 2 : m_xRow = Reference< XRow>(m_xTables,UNO_QUERY);
50 :
51 2 : sUserWorkingFor = _rxMeta->getUserName();
52 : }
53 0 : catch(Exception&)
54 : {
55 : }
56 :
57 4 : ODatabaseMetaDataResultSet::ORows aRows;
58 2 : static ODatabaseMetaDataResultSet::ORow aRow(8);
59 2 : aRow[5] = new ORowSetValueDecorator(sUserWorkingFor);
60 2 : aRow[6] = ODatabaseMetaDataResultSet::getSelectValue();
61 2 : aRow[7] = new ORowSetValueDecorator(OUString("YES"));
62 2 : aRows.push_back(aRow);
63 2 : aRow[6] = ODatabaseMetaDataResultSet::getInsertValue();
64 2 : aRows.push_back(aRow);
65 2 : aRow[6] = ODatabaseMetaDataResultSet::getDeleteValue();
66 2 : aRows.push_back(aRow);
67 2 : aRow[6] = ODatabaseMetaDataResultSet::getUpdateValue();
68 2 : aRows.push_back(aRow);
69 2 : aRow[6] = ODatabaseMetaDataResultSet::getCreateValue();
70 2 : aRows.push_back(aRow);
71 2 : aRow[6] = ODatabaseMetaDataResultSet::getReadValue();
72 2 : aRows.push_back(aRow);
73 2 : aRow[6] = ODatabaseMetaDataResultSet::getAlterValue();
74 2 : aRows.push_back(aRow);
75 2 : aRow[6] = ODatabaseMetaDataResultSet::getDropValue();
76 2 : aRows.push_back(aRow);
77 2 : aRow[6] = new ORowSetValueDecorator(OUString("REFERENCE"));
78 2 : aRows.push_back(aRow);
79 :
80 4 : setRows(aRows);
81 : }
82 2 : osl_atomic_decrement( &m_refCount );
83 2 : }
84 :
85 36 : const ORowSetValue& OResultSetPrivileges::getValue(sal_Int32 columnIndex)
86 : {
87 36 : switch(columnIndex)
88 : {
89 : case 1:
90 : case 2:
91 : case 3:
92 0 : if ( m_xRow.is() && m_bResetValues )
93 : {
94 0 : (*m_aRowsIter)[1] = new ORowSetValueDecorator(m_xRow->getString(1));
95 0 : if ( m_xRow->wasNull() )
96 0 : (*m_aRowsIter)[1]->setNull();
97 0 : (*m_aRowsIter)[2] = new ORowSetValueDecorator(m_xRow->getString(2));
98 0 : if ( m_xRow->wasNull() )
99 0 : (*m_aRowsIter)[2]->setNull();
100 0 : (*m_aRowsIter)[3] = new ORowSetValueDecorator(m_xRow->getString(3));
101 0 : if ( m_xRow->wasNull() )
102 0 : (*m_aRowsIter)[3]->setNull();
103 :
104 0 : m_bResetValues = false;
105 : }
106 : }
107 36 : return ODatabaseMetaDataResultSet::getValue(columnIndex);
108 : }
109 :
110 2 : void SAL_CALL OResultSetPrivileges::disposing(void)
111 : {
112 2 : ODatabaseMetaDataResultSet::disposing();
113 2 : m_xTables.clear();
114 2 : m_xRow.clear();
115 2 : }
116 :
117 20 : sal_Bool SAL_CALL OResultSetPrivileges::next( ) throw(SQLException, RuntimeException, std::exception)
118 : {
119 20 : ::osl::MutexGuard aGuard( m_aMutex );
120 20 : checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
121 :
122 20 : bool bReturn = false;
123 20 : if ( m_xTables.is() )
124 : {
125 20 : if ( m_bBOF )
126 : {
127 2 : m_bResetValues = true;
128 2 : if ( !m_xTables->next() )
129 0 : return sal_False;
130 : }
131 :
132 20 : bReturn = ODatabaseMetaDataResultSet::next();
133 20 : if ( !bReturn )
134 : {
135 2 : m_bBOF = false;
136 2 : m_bResetValues = bReturn = m_xTables->next();
137 : }
138 : }
139 20 : return bReturn;
140 : }
141 :
142 :
143 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|