1use crate::provider::{RawBytes, Sqlite3Api, ValueType};
2use crate::statement::Statement;
3use crate::value::{Value, ValueRef};
4
5pub struct Row<'s, 'c, 'p, P: Sqlite3Api> {
7 stmt: &'s Statement<'c, 'p, P>,
8}
9
10impl<'s, 'c, 'p, P: Sqlite3Api> Row<'s, 'c, 'p, P> {
11 pub(crate) fn new(stmt: &'s Statement<'c, 'p, P>) -> Self {
12 Self { stmt }
13 }
14
15 pub fn column_count(&self) -> i32 {
17 unsafe { self.stmt.conn.api.column_count(self.stmt.stmt) }
18 }
19
20 pub fn column_type(&self, col: i32) -> ValueType {
22 unsafe { self.stmt.conn.api.column_type(self.stmt.stmt, col) }
23 }
24
25 pub fn column_int64(&self, col: i32) -> i64 {
27 unsafe { self.stmt.conn.api.column_int64(self.stmt.stmt, col) }
28 }
29
30 pub fn column_double(&self, col: i32) -> f64 {
32 unsafe { self.stmt.conn.api.column_double(self.stmt.stmt, col) }
33 }
34
35 pub fn column_text_raw(&self, col: i32) -> RawBytes {
37 unsafe { self.stmt.conn.api.column_text(self.stmt.stmt, col) }
38 }
39
40 pub fn column_blob_raw(&self, col: i32) -> RawBytes {
42 unsafe { self.stmt.conn.api.column_blob(self.stmt.stmt, col) }
43 }
44
45 pub fn column_text(&self, col: i32) -> Option<&str> {
47 unsafe { self.column_text_raw(col).as_str() }
48 }
49
50 pub fn column_blob(&self, col: i32) -> &[u8] {
52 unsafe { self.column_blob_raw(col).as_slice() }
53 }
54
55 pub fn column_value_ref(&self, col: i32) -> ValueRef<'_> {
57 match self.column_type(col) {
58 ValueType::Null => ValueRef::Null,
59 ValueType::Integer => ValueRef::Integer(self.column_int64(col)),
60 ValueType::Float => ValueRef::Float(self.column_double(col)),
61 ValueType::Text => unsafe { ValueRef::from_raw_text(self.column_text_raw(col)) },
62 ValueType::Blob => unsafe { ValueRef::from_raw_blob(self.column_blob_raw(col)) },
63 }
64 }
65
66 pub fn column_value(&self, col: i32) -> Value {
68 self.column_value_ref(col).to_owned()
69 }
70}