1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26 #include "TPrivilegesResultSet.hxx"
27 
28 using namespace connectivity;
29 //------------------------------------------------------------------------------
30 using namespace ::com::sun::star::beans;
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::sdbcx;
33 using namespace ::com::sun::star::sdbc;
34 using namespace ::com::sun::star::container;
35 using namespace ::com::sun::star::lang;
36 //------------------------------------------------------------------------------
OResultSetPrivileges(const Reference<XDatabaseMetaData> & _rxMeta,const Any & catalog,const::rtl::OUString & schemaPattern,const::rtl::OUString & tableNamePattern)37 OResultSetPrivileges::OResultSetPrivileges( const Reference< XDatabaseMetaData>& _rxMeta
38 										   , const Any& catalog
39 										   , const ::rtl::OUString& schemaPattern
40 										   , const ::rtl::OUString& tableNamePattern)
41 										   : ODatabaseMetaDataResultSet(eTablePrivileges)
42                                            , m_bResetValues(sal_True)
43 {
44 	osl_incrementInterlockedCount( &m_refCount );
45 	{
46 		::rtl::OUString sUserWorkingFor;
47 		static Sequence< ::rtl::OUString > sTableTypes;
48 		if ( sTableTypes.getLength() == 0 )
49 		{
50 			// we want all catalogues, all schemas, all tables
51 			sTableTypes.realloc(3);
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 ....
55 		}
56 		try
57 		{
58 			m_xTables = _rxMeta->getTables(catalog,schemaPattern,tableNamePattern,sTableTypes);
59 			m_xRow = Reference< XRow>(m_xTables,UNO_QUERY);
60 
61 			sUserWorkingFor = _rxMeta->getUserName();
62 		}
63 		catch(Exception&)
64 		{
65 		}
66 
67 		ODatabaseMetaDataResultSet::ORows aRows;
68 		static ODatabaseMetaDataResultSet::ORow aRow(8);
69 		aRow[5] = new ORowSetValueDecorator(sUserWorkingFor);
70 		aRow[6] = ODatabaseMetaDataResultSet::getSelectValue();
71 		aRow[7] = new ORowSetValueDecorator(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("YES")));
72 		aRows.push_back(aRow);
73 		aRow[6] = ODatabaseMetaDataResultSet::getInsertValue();
74 		aRows.push_back(aRow);
75 		aRow[6] = ODatabaseMetaDataResultSet::getDeleteValue();
76 		aRows.push_back(aRow);
77 		aRow[6] = ODatabaseMetaDataResultSet::getUpdateValue();
78 		aRows.push_back(aRow);
79 		aRow[6] = ODatabaseMetaDataResultSet::getCreateValue();
80 		aRows.push_back(aRow);
81 		aRow[6] = ODatabaseMetaDataResultSet::getReadValue();
82 		aRows.push_back(aRow);
83 		aRow[6] = ODatabaseMetaDataResultSet::getAlterValue();
84 		aRows.push_back(aRow);
85 		aRow[6] = ODatabaseMetaDataResultSet::getDropValue();
86 		aRows.push_back(aRow);
87 		aRow[6] = new ORowSetValueDecorator(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("REFERENCE")));
88 		aRows.push_back(aRow);
89 
90 		setRows(aRows);
91 	}
92 	osl_decrementInterlockedCount( &m_refCount );
93 }
94 //------------------------------------------------------------------------------
getValue(sal_Int32 columnIndex)95 const ORowSetValue& OResultSetPrivileges::getValue(sal_Int32 columnIndex)
96 {
97 	switch(columnIndex)
98 	{
99 		case 1:
100 		case 2:
101 		case 3:
102 			if ( m_xRow.is() && m_bResetValues )
103 			{
104 				(*m_aRowsIter)[1] = new ORowSetValueDecorator(m_xRow->getString(1));
105 				if ( m_xRow->wasNull() )
106 					(*m_aRowsIter)[1]->setNull();
107 				(*m_aRowsIter)[2] = new ORowSetValueDecorator(m_xRow->getString(2));
108 				if ( m_xRow->wasNull() )
109 					(*m_aRowsIter)[2]->setNull();
110 				(*m_aRowsIter)[3] = new ORowSetValueDecorator(m_xRow->getString(3));
111 				if ( m_xRow->wasNull() )
112 					(*m_aRowsIter)[3]->setNull();
113 
114 				m_bResetValues = sal_False;
115 			}
116 	}
117 	return ODatabaseMetaDataResultSet::getValue(columnIndex);
118 }
119 // -----------------------------------------------------------------------------
disposing(void)120 void SAL_CALL OResultSetPrivileges::disposing(void)
121 {
122 	ODatabaseMetaDataResultSet::disposing();
123 m_xTables.clear();
124 m_xRow.clear();
125 }
126 // -----------------------------------------------------------------------------
next()127 sal_Bool SAL_CALL OResultSetPrivileges::next(  ) throw(SQLException, RuntimeException)
128 {
129 	::osl::MutexGuard aGuard( m_aMutex );
130 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
131 
132 	sal_Bool bReturn = sal_False;
133 	if ( m_xTables.is() )
134 	{
135 		if ( m_bBOF )
136 		{
137 			m_bResetValues = sal_True;
138 			if ( !m_xTables->next() )
139 				return sal_False;
140 		}
141 
142         bReturn = ODatabaseMetaDataResultSet::next();
143         if ( !bReturn )
144 		{
145 			m_bBOF = sal_False;
146 			m_bResetValues = bReturn = m_xTables->next();
147 		}
148 	}
149 	return bReturn;
150 }
151 // -----------------------------------------------------------------------------
152