Repository navigation
Expand file tree
/
Copy pathexecutor.rs
More file actions
76 lines (61 loc) · 2.04 KB
/
Copy pathexecutor.rs
File metadata and controls
76 lines (61 loc) · 2.04 KB
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
use std::collections::HashMap;
use std::io;
use std::sync::Arc;
use crate::cursor::Cursor;
use crate::executor::{Execute, Executor};
use crate::postgres::protocol::{self, Encode, StatementId, TypeFormat};
use crate::postgres::{PgArguments, PgConnection, PgCursor, PgRow, PgTypeInfo, Postgres};
impl PgConnection {
pub(crate) fn write_simple_query(&mut self, query: &str) {
self.stream.write(protocol::Query(query));
}
pub(crate) fn write_prepare(&mut self, query: &str, args: &PgArguments) -> StatementId {
// TODO: check query cache
let id = StatementId(self.next_statement_id);
self.next_statement_id += 1;
self.stream.write(protocol::Parse {
statement: id,
query,
param_types: &*args.types,
});
// TODO: write to query cache
id
}
pub(crate) fn write_describe(&mut self, d: protocol::Describe) {
self.stream.write(d);
}
pub(crate) fn write_bind(&mut self, portal: &str, statement: StatementId, args: &PgArguments) {
self.stream.write(protocol::Bind {
portal,
statement,
formats: &[TypeFormat::Binary],
// TODO: Early error if there is more than i16
values_len: args.types.len() as i16,
values: &*args.values,
result_formats: &[TypeFormat::Binary],
});
}
pub(crate) fn write_execute(&mut self, portal: &str, limit: i32) {
self.stream.write(protocol::Execute { portal, limit });
}
pub(crate) fn write_sync(&mut self) {
self.stream.write(protocol::Sync);
}
}
impl<'e> Executor<'e> for &'e mut super::PgConnection {
type Database = Postgres;
fn execute<'q, E>(self, query: E) -> PgCursor<'e, 'q>
where
E: Execute<'q, Self::Database>,
{
PgCursor::from_connection(self, query)
}
#[doc(hidden)]
#[inline]
fn execute_by_ref<'q, E>(&mut self, query: E) -> PgCursor<'_, 'q>
where
E: Execute<'q, Self::Database>,
{
self.execute(query)
}
}