clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name pq_xviews.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D PQ_SDBC_MAJOR=0 -D PQ_SDBC_MINOR=8 -D PQ_SDBC_MICRO=2 -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/openldap/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/postgresql/src/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/postgresql/src/interfaces/libpq -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/nss/dist/public/nss -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/nss/dist/out/include -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/connectivity/source/drivers/postgresql/pq_xviews.cxx
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | #include <rtl/ustrbuf.hxx> |
38 | #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> |
39 | #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> |
40 | #include <com/sun/star/sdbc/SQLException.hpp> |
41 | #include <com/sun/star/sdbc/XRow.hpp> |
42 | #include <cppuhelper/exc_hlp.hxx> |
43 | |
44 | #include "pq_xviews.hxx" |
45 | #include "pq_xview.hxx" |
46 | #include "pq_xtables.hxx" |
47 | #include "pq_statics.hxx" |
48 | #include "pq_tools.hxx" |
49 | |
50 | using osl::MutexGuard; |
51 | |
52 | using com::sun::star::beans::XPropertySet; |
53 | |
54 | using com::sun::star::uno::makeAny; |
55 | using com::sun::star::uno::UNO_QUERY; |
56 | using com::sun::star::uno::Reference; |
57 | |
58 | using com::sun::star::container::NoSuchElementException; |
59 | |
60 | using com::sun::star::sdbc::XRow; |
61 | using com::sun::star::sdbc::XStatement; |
62 | using com::sun::star::sdbc::XResultSet; |
63 | |
64 | |
65 | namespace pq_sdbc_driver |
66 | { |
67 | Views::Views( |
68 | const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, |
69 | const css::uno::Reference< css::sdbc::XConnection > & origin, |
70 | ConnectionSettings *pSettings ) |
71 | : Container( refMutex, origin, pSettings, getStatics().VIEW ) |
72 | {} |
73 | |
74 | Views::~Views() |
75 | {} |
76 | |
77 | void Views::refresh() |
78 | { |
79 | try |
80 | { |
81 | osl::MutexGuard guard( m_xMutex->GetMutex() ); |
82 | Statics & st = getStatics(); |
83 | |
84 | Reference< XStatement > stmt = m_origin->createStatement(); |
85 | |
86 | Reference< XResultSet > rs = stmt->executeQuery("SELECT " |
87 | "DISTINCT ON( pg_namespace.nspname, relname) " |
88 | "pg_namespace.nspname," |
89 | "relname," |
90 | "pg_get_viewdef(ev_class) " |
91 | "FROM pg_namespace, pg_class, pg_rewrite " |
92 | "WHERE pg_namespace.oid = relnamespace " |
93 | "AND pg_class.oid = ev_class " |
94 | "AND relkind=\'v\'" ); |
95 | |
96 | Reference< XRow > xRow( rs , UNO_QUERY ); |
97 | |
98 | m_values.clear(); |
99 | String2IntMap map; |
100 | sal_Int32 viewIndex = 0; |
101 | |
102 | while( rs->next() ) |
103 | { |
104 | OUString table, schema, command; |
105 | schema = xRow->getString( 1 ); |
106 | table = xRow->getString( 2 ); |
107 | command = xRow->getString( 3 ); |
108 | |
109 | View *pView = new View (m_xMutex, m_origin, m_pSettings ); |
110 | Reference< css::beans::XPropertySet > prop = pView; |
111 | |
112 | pView->setPropertyValue_NoBroadcast_public(st.NAME , makeAny(table) ); |
113 | pView->setPropertyValue_NoBroadcast_public(st.SCHEMA_NAME, makeAny(schema) ); |
114 | pView->setPropertyValue_NoBroadcast_public(st.COMMAND, makeAny(command) ); |
115 | |
116 | { |
117 | m_values.push_back( makeAny( prop ) ); |
118 | map[ schema + "." + table ] = viewIndex; |
119 | ++viewIndex; |
120 | } |
121 | } |
122 | m_name2index.swap( map ); |
123 | } |
124 | catch ( css::sdbc::SQLException & e ) |
125 | { |
126 | css::uno::Any anyEx = cppu::getCaughtException(); |
127 | throw css::lang::WrappedTargetRuntimeException( e.Message, |
128 | e.Context, anyEx ); |
129 | } |
130 | fire( RefreshedBroadcaster( *this ) ); |
131 | } |
132 | |
133 | |
134 | void Views::appendByDescriptor( |
135 | const css::uno::Reference< css::beans::XPropertySet >& descriptor ) |
136 | { |
137 | osl::MutexGuard guard( m_xMutex->GetMutex() ); |
138 | |
139 | Statics &st = getStatics(); |
140 | OUString name,schema,command; |
141 | descriptor->getPropertyValue( st.SCHEMA_NAME ) >>= schema; |
142 | descriptor->getPropertyValue( st.NAME ) >>= name; |
143 | descriptor->getPropertyValue( st.COMMAND ) >>= command; |
144 | |
145 | Reference< XStatement > stmt = m_origin->createStatement(); |
146 | |
147 | OUStringBuffer buf( 128 ); |
148 | |
149 | buf.append( "CREATE VIEW "); |
150 | bufferQuoteQualifiedIdentifier( buf, schema, name, m_pSettings ); |
151 | buf.append(" AS " ).append( command ); |
152 | |
153 | stmt->executeUpdate( buf.makeStringAndClear() ); |
154 | |
155 | disposeNoThrow( stmt ); |
156 | refresh(); |
157 | if( m_pSettings->tables.is() ) |
158 | { |
159 | m_pSettings->pTablesImpl->refresh(); |
160 | } |
161 | } |
162 | |
163 | void Views::dropByName( const OUString& elementName ) |
164 | { |
165 | String2IntMap::const_iterator ii = m_name2index.find( elementName ); |
166 | if( ii == m_name2index.end() ) |
167 | { |
168 | throw css::container::NoSuchElementException( |
169 | "View " + elementName + " is unknown, so it can't be dropped", *this ); |
170 | } |
171 | dropByIndex( ii->second ); |
172 | } |
173 | |
174 | void Views::dropByIndex( sal_Int32 index ) |
175 | { |
176 | osl::MutexGuard guard( m_xMutex->GetMutex() ); |
177 | if( index < 0 || index >= static_cast<sal_Int32>(m_values.size()) ) |
178 | { |
179 | throw css::lang::IndexOutOfBoundsException( |
180 | "VIEWS: Index out of range (allowed 0 to " + OUString::number(m_values.size() -1) |
181 | + ", got " + OUString::number( index ) + ")", |
182 | *this ); |
183 | } |
184 | |
185 | Reference< XPropertySet > set; |
186 | m_values[index] >>= set; |
187 | Statics &st = getStatics(); |
188 | OUString name,schema; |
189 | set->getPropertyValue( st.SCHEMA_NAME ) >>= schema; |
190 | set->getPropertyValue( st.NAME ) >>= name; |
191 | |
192 | Reference< XStatement > stmt = m_origin->createStatement( ); |
193 | |
194 | stmt->executeUpdate( "DROP VIEW \"" + schema + "\".\"" + name + "\"" ); |
195 | } |
196 | |
197 | |
198 | css::uno::Reference< css::beans::XPropertySet > Views::createDataDescriptor() |
199 | { |
200 | return new ViewDescriptor( m_xMutex, m_origin, m_pSettings ); |
201 | } |
202 | |
203 | Reference< css::container::XNameAccess > Views::create( |
204 | const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, |
205 | const css::uno::Reference< css::sdbc::XConnection > & origin, |
206 | ConnectionSettings *pSettings, |
207 | Views **ppViews) |
208 | { |
209 | *ppViews = new Views( refMutex, origin, pSettings ); |
| |
210 | Reference< css::container::XNameAccess > ret = *ppViews; |
211 | (*ppViews)->refresh(); |
| 2 | | Called C++ object pointer is null |
|
212 | |
213 | return ret; |
214 | } |
215 | |
216 | }; |
217 | |
218 | |