@@ -56,27 +56,42 @@ class pg_result_t
5656 // / The number of tuples (rows) in this result.
5757 int num_tuples () const noexcept { return PQntuples (m_result.get ()); }
5858
59- // / Does the field at (row, col) has the NULL value?
59+ /* *
60+ * Does the field at (row, col) has the NULL value?
61+ *
62+ * \pre 0 <= row < num_tuples() and 0 <= col < num_fields()
63+ */
6064 bool is_null (int row, int col) const noexcept
6165 {
62- assert (row < num_tuples () && col < num_fields ());
66+ assert (row >= 0 && row < num_tuples () && col >= 0 &&
67+ col < num_fields ());
6368 return PQgetisnull (m_result.get (), row, col) != 0 ;
6469 }
6570
66- // / The length of the field at (row, col) in bytes.
71+ /* *
72+ * The length of the field at (row, col) in bytes.
73+ *
74+ * \pre 0 <= row < num_tuples() and 0 <= col < num_fields()
75+ */
6776 int get_length (int row, int col) const noexcept
6877 {
69- assert (row < num_tuples () && col < num_fields ());
78+ assert (row >= 0 && row < num_tuples () && col >= 0 &&
79+ col < num_fields ());
7080 return PQgetlength (m_result.get (), row, col);
7181 }
7282
7383 /* *
7484 * Get value of the field at (row, col) as char pointer. The string is
7585 * null-terminated. Only valid as long as the pg_result_t is in scope.
86+ *
87+ * When the result is NULL, an empty string is returned.
88+ *
89+ * \pre 0 <= row < num_tuples() and 0 <= col < num_fields()
7690 */
7791 char const *get_value (int row, int col) const noexcept
7892 {
79- assert (row < num_tuples () && col < num_fields ());
93+ assert (row >= 0 && row < num_tuples () && col >= 0 &&
94+ col < num_fields ());
8095 return PQgetvalue (m_result.get (), row, col);
8196 }
8297
0 commit comments