3737class pg_result_t
3838{
3939public:
40- pg_result_t () = default ;
40+ pg_result_t () noexcept = default ;
4141
4242 explicit pg_result_t (PGresult *result) noexcept : m_result(result) {}
4343
44- // / Get a pointer to the underlying PGresult object.
45- PGresult *get () const noexcept { return m_result.get (); }
46-
4744 // / Get the status of this result.
4845 ExecStatusType status () const noexcept
4946 {
@@ -56,27 +53,42 @@ class pg_result_t
5653 // / The number of tuples (rows) in this result.
5754 int num_tuples () const noexcept { return PQntuples (m_result.get ()); }
5855
59- // / Does the field at (row, col) has the NULL value?
56+ /* *
57+ * Does the field at (row, col) has the NULL value?
58+ *
59+ * \pre 0 <= row < num_tuples() and 0 <= col < num_fields()
60+ */
6061 bool is_null (int row, int col) const noexcept
6162 {
62- assert (row < num_tuples () && col < num_fields ());
63+ assert (row >= 0 && row < num_tuples () && col >= 0 &&
64+ col < num_fields ());
6365 return PQgetisnull (m_result.get (), row, col) != 0 ;
6466 }
6567
66- // / The length of the field at (row, col) in bytes.
68+ /* *
69+ * The length of the field at (row, col) in bytes.
70+ *
71+ * \pre 0 <= row < num_tuples() and 0 <= col < num_fields()
72+ */
6773 int get_length (int row, int col) const noexcept
6874 {
69- assert (row < num_tuples () && col < num_fields ());
75+ assert (row >= 0 && row < num_tuples () && col >= 0 &&
76+ col < num_fields ());
7077 return PQgetlength (m_result.get (), row, col);
7178 }
7279
7380 /* *
7481 * Get value of the field at (row, col) as char pointer. The string is
7582 * null-terminated. Only valid as long as the pg_result_t is in scope.
83+ *
84+ * When the result is NULL, an empty string is returned.
85+ *
86+ * \pre 0 <= row < num_tuples() and 0 <= col < num_fields()
7687 */
7788 char const *get_value (int row, int col) const noexcept
7889 {
79- assert (row < num_tuples () && col < num_fields ());
90+ assert (row >= 0 && row < num_tuples () && col >= 0 &&
91+ col < num_fields ());
8092 return PQgetvalue (m_result.get (), row, col);
8193 }
8294
@@ -100,7 +112,7 @@ class pg_result_t
100112 }
101113
102114 // / Return true if this holds an actual result.
103- explicit operator bool () { return m_result.get (); }
115+ explicit operator bool () const noexcept { return m_result.get (); }
104116
105117private:
106118 struct pg_result_deleter_t
@@ -207,6 +219,10 @@ class pg_conn_t
207219 pg_result_t query (ExecStatusType expect, char const *sql) const ;
208220 pg_result_t query (ExecStatusType expect, std::string const &sql) const ;
209221
222+ /* *
223+ * Update a PostgreSQL setting (like with the SET command). Will silently
224+ * ignore settings that are not available or any other errors.
225+ */
210226 void set_config (char const *setting, char const *value) const ;
211227
212228 /* *
@@ -223,6 +239,7 @@ class pg_conn_t
223239
224240 void end_copy (std::string const &context) const ;
225241
242+ // / Return the latest generated error message on this connection.
226243 char const *error_msg () const noexcept ;
227244
228245 // / Close database connection.
@@ -253,15 +270,15 @@ std::string tablespace_clause(std::string const &name);
253270std::string qualified_name (std::string const &schema, std::string const &name);
254271
255272/* *
256- * Check that the string confirms to the identifier syntax we accept.
257- * Throws a runtime exception if an invalid character is found.
273+ * Check that the string conforms to the identifier syntax we accept.
258274 *
259275 * Note that PostgreSQL accepts any character in a quoted identifier.
260- * This function checks for some characters that are problematic in the
261- * internal functions that create SQL statements.
276+ * This function checks for some characters that are potentially problematic
277+ * in our internal functions that create SQL statements.
262278 *
263- * \param name Identifier to check.
264- * \param in Name of the identifier. Only used to create a human-readable error.
279+ * \param name Identifier to check.
280+ * \param in Name of the identifier. Only used to create a human-readable error.
281+ * \throws runtime_exception If an invalid character is found in the name.
265282 */
266283void check_identifier (std::string const &name, char const *in);
267284
0 commit comments