This file is indexed.

/usr/include/Poco/Data/ODBC/Diagnostics.h is in libpoco-dev 1.8.0.1-1ubuntu4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
//
// Diagnostics.h
//
// Library: Data/ODBC
// Package: ODBC
// Module:  Diagnostics
//
// Definition of Diagnostics.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier:	BSL-1.0
//


#ifndef Data_ODBC_Diagnostics_INCLUDED
#define Data_ODBC_Diagnostics_INCLUDED


#include "Poco/Data/ODBC/ODBC.h"
#include <vector>
#include <cstring>
#ifdef POCO_OS_FAMILY_WINDOWS
#include <windows.h>
#endif
#include <sqlext.h>


namespace Poco {
namespace Data {
namespace ODBC {


template <typename H, SQLSMALLINT handleType>
class Diagnostics
	/// Utility class providing functionality for retrieving ODBC diagnostic
	/// records. Diagnostics object must be created with corresponding handle
	/// as constructor argument. During construction, diagnostic records fields 
	/// are populated and the object is ready for querying.
{
public:

	static const unsigned int SQL_STATE_SIZE = SQL_SQLSTATE_SIZE + 1;
	static const unsigned int SQL_MESSAGE_LENGTH = SQL_MAX_MESSAGE_LENGTH + 1;
	static const unsigned int SQL_NAME_LENGTH = 128;
	static const std::string  DATA_TRUNCATED;

	struct DiagnosticFields
	{
		/// SQLGetDiagRec fields
		SQLCHAR    _sqlState[SQL_STATE_SIZE];
		SQLCHAR    _message[SQL_MESSAGE_LENGTH];
		SQLINTEGER _nativeError;
	};

	typedef std::vector<DiagnosticFields> FieldVec;
	typedef typename FieldVec::const_iterator Iterator;

	explicit Diagnostics(const H& handle): _handle(handle)
		/// Creates and initializes the Diagnostics.
	{
		std::memset(_connectionName, 0, sizeof(_connectionName));
		std::memset(_serverName, 0, sizeof(_serverName));
		diagnostics();
	}

	~Diagnostics()
		/// Destroys the Diagnostics.
	{
	}

	std::string sqlState(int index) const
		/// Returns SQL state.
	{
		poco_assert (index < count());
		return std::string((char*) _fields[index]._sqlState);
	}

	std::string message(int index) const
		/// Returns error message.
	{
		poco_assert (index < count());
		return std::string((char*) _fields[index]._message);
	}

	long nativeError(int index) const
		/// Returns native error code.
	{
		poco_assert (index < count());
		return _fields[index]._nativeError;
	}

	std::string connectionName() const
		/// Returns the connection name. 
		/// If there is no active connection, connection name defaults to NONE.
		/// If connection name is not applicable for query context (such as when querying environment handle),
		/// connection name defaults to NOT_APPLICABLE.
	{
		return std::string((char*) _connectionName);
	}

	std::string serverName() const
		/// Returns the server name.
		/// If the connection has not been established, server name defaults to NONE.
		/// If server name is not applicable for query context (such as when querying environment handle),
		/// connection name defaults to NOT_APPLICABLE.
	{
		return std::string((char*) _serverName);
	}

	int count() const
		/// Returns the number of contained diagnostic records.
	{
		return (int) _fields.size();
	}

	void reset()
		/// Resets the diagnostic fields container.
	{
		_fields.clear();
	}

	const FieldVec& fields() const
	{
		return _fields;
	}

	Iterator begin() const
	{
		return _fields.begin();
	}

	Iterator end() const
	{
		return _fields.end();
	}

	const Diagnostics& diagnostics()
	{
		DiagnosticFields df;
		SQLSMALLINT count = 1;
		SQLSMALLINT messageLength = 0;
		static const std::string none = "None";
		static const std::string na = "Not applicable";

		reset();

		while (!Utility::isError(SQLGetDiagRec(handleType, 
			_handle, 
			count, 
			df._sqlState, 
			&df._nativeError, 
			df._message, 
			SQL_MESSAGE_LENGTH, 
			&messageLength))) 
		{
			if (1 == count)
			{
				// success of the following two calls is optional
				// (they fail if connection has not been established yet
				//  or return empty string if not applicable for the context)
				if (Utility::isError(SQLGetDiagField(handleType, 
					_handle, 
					count, 
					SQL_DIAG_CONNECTION_NAME, 
					_connectionName, 
					sizeof(_connectionName), 
					&messageLength)))
				{
					std::size_t len = sizeof(_connectionName) > none.length() ? 
						none.length() : sizeof(_connectionName) - 1;
					std::memcpy(_connectionName, none.c_str(), len);
				}
				else if (0 == _connectionName[0]) 
				{
					std::size_t len = sizeof(_connectionName) > na.length() ? 
						na.length() : sizeof(_connectionName) - 1;
					std::memcpy(_connectionName, na.c_str(), len);
				}
				
				if (Utility::isError(SQLGetDiagField(handleType, 
					_handle, 
					count, 
					SQL_DIAG_SERVER_NAME, 
					_serverName, 
					sizeof(_serverName), 
					&messageLength)))
				{
					std::size_t len = sizeof(_serverName) > none.length() ? 
						none.length() : sizeof(_serverName) - 1;
					std::memcpy(_serverName, none.c_str(), len);
				}
				else if (0 == _serverName[0]) 
				{
					std::size_t len = sizeof(_serverName) > na.length() ? 
						na.length() : sizeof(_serverName) - 1;
					std::memcpy(_serverName, na.c_str(), len);
				}
			}

			_fields.push_back(df);

			std::memset(df._sqlState, 0, SQL_STATE_SIZE);
			std::memset(df._message, 0, SQL_MESSAGE_LENGTH);
			df._nativeError = 0;

			++count;
		}

		return *this;
	}

private:

	Diagnostics();

	/// SQLGetDiagField fields
	SQLCHAR _connectionName[SQL_NAME_LENGTH];
	SQLCHAR _serverName[SQL_NAME_LENGTH];

	/// Diagnostics container
	FieldVec _fields;

	/// Context handle
	const H& _handle;
};


typedef Diagnostics<SQLHENV, SQL_HANDLE_ENV> EnvironmentDiagnostics;
typedef Diagnostics<SQLHDBC, SQL_HANDLE_DBC> ConnectionDiagnostics;
typedef Diagnostics<SQLHSTMT, SQL_HANDLE_STMT> StatementDiagnostics;
typedef Diagnostics<SQLHDESC, SQL_HANDLE_DESC> DescriptorDiagnostics;


} } } // namespace Poco::Data::ODBC


#endif