File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,26 @@ impl Statement<'_> {
50
50
/// sure that current statement has already been stepped once before
51
51
/// calling this method.
52
52
///
53
+ /// # Example
54
+ ///
55
+ /// ```rust,no_run
56
+ /// # use duckdb::{Connection, Result};
57
+ /// fn get_column_count(conn: &Connection) -> Result<usize> {
58
+ /// let mut stmt = conn.prepare("SELECT id, name FROM people")?;
59
+ ///
60
+ /// // Option 1: Execute first, then get column count
61
+ /// stmt.execute([])?;
62
+ /// let count = stmt.column_count();
63
+ ///
64
+ /// // Option 2: Get column count from rows (avoids borrowing issues)
65
+ /// let mut stmt2 = conn.prepare("SELECT id, name FROM people")?;
66
+ /// let rows = stmt2.query([])?;
67
+ /// let count2 = rows.as_ref().unwrap().column_count();
68
+ ///
69
+ /// Ok(count)
70
+ /// }
71
+ /// ```
72
+ ///
53
73
/// # Caveats
54
74
/// Panics if the query has not been [`execute`](Statement::execute)d yet.
55
75
#[ inline]
Original file line number Diff line number Diff line change @@ -101,7 +101,29 @@ impl<'stmt> Rows<'stmt> {
101
101
AndThenRows { rows : self , map : f }
102
102
}
103
103
104
- /// Give access to the underlying statement
104
+ /// Access the underlying statement
105
+ ///
106
+ /// This method provides a way to access the `Statement` that created these `Rows`
107
+ /// without additional borrowing conflicts. This is particularly useful when you need
108
+ /// to access statement metadata (like column count or names) while iterating over results.
109
+ ///
110
+ /// # Example
111
+ ///
112
+ /// ```rust,no_run
113
+ /// # use duckdb::{Connection, Result};
114
+ /// fn process_results(conn: &Connection) -> Result<()> {
115
+ /// let mut stmt = conn.prepare("SELECT id, name FROM people")?;
116
+ /// let mut rows = stmt.query([])?;
117
+ ///
118
+ /// let column_count = rows.as_ref().unwrap().column_count();
119
+ /// println!("Processing {} columns", column_count);
120
+ ///
121
+ /// while let Some(row) = rows.next()? {
122
+ /// // Process row...
123
+ /// }
124
+ /// Ok(())
125
+ /// }
126
+ /// ```
105
127
pub fn as_ref ( & self ) -> Option < & Statement < ' stmt > > {
106
128
self . stmt
107
129
}
You can’t perform that action at this time.
0 commit comments