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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
use num_enum::TryFromPrimitive;
use crate::*;
pub trait FirebirdClientEmbeddedAttach<T: FirebirdClient> {
fn attach_database(
&mut self,
db_name: &str,
user: &str,
) -> Result<<T as FirebirdClient>::DbHandle, FbError>;
}
pub trait FirebirdClientRemoteAttach<T: FirebirdClient> {
fn attach_database(
&mut self,
host: &str,
port: u16,
db_name: &str,
user: &str,
pass: &str,
) -> Result<<T as FirebirdClient>::DbHandle, FbError>;
}
pub trait FirebirdClient: Send {
type DbHandle: Send + Clone + Copy;
type TrHandle: Send + Clone + Copy;
type StmtHandle: Send + Clone + Copy;
type Args: Send + Sync + Clone;
fn new(args: Self::Args) -> Result<Self, FbError>
where
Self: Sized;
fn detach_database(&mut self, db_handle: Self::DbHandle) -> Result<(), FbError>;
fn drop_database(&mut self, db_handle: Self::DbHandle) -> Result<(), FbError>;
fn begin_transaction(
&mut self,
db_handle: Self::DbHandle,
isolation_level: TrIsolationLevel,
) -> Result<Self::TrHandle, FbError>;
fn transaction_operation(&mut self, tr_handle: Self::TrHandle, op: TrOp)
-> Result<(), FbError>;
fn exec_immediate(
&mut self,
db_handle: Self::DbHandle,
tr_handle: Self::TrHandle,
dialect: Dialect,
sql: &str,
) -> Result<(), FbError>;
fn prepare_statement(
&mut self,
db_handle: Self::DbHandle,
tr_handle: Self::TrHandle,
dialect: Dialect,
sql: &str,
) -> Result<(StmtType, Self::StmtHandle), FbError>;
fn free_statement(
&mut self,
stmt_handle: Self::StmtHandle,
op: FreeStmtOp,
) -> Result<(), FbError>;
fn execute(
&mut self,
tr_handle: Self::TrHandle,
stmt_handle: Self::StmtHandle,
params: Vec<Param>,
) -> Result<(), FbError>;
fn fetch(&mut self, stmt_handle: Self::StmtHandle) -> Result<Option<Vec<Column>>, FbError>;
}
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
#[repr(u8)]
pub enum Dialect {
D1 = 1,
D2 = 2,
D3 = 3,
}
#[repr(u8)]
pub enum TrIsolationLevel {
Concurrency = ibase::isc_tpb_concurrency as u8,
Concistency = ibase::isc_tpb_consistency as u8,
ReadCommited = ibase::isc_tpb_read_committed as u8,
}
impl Default for TrIsolationLevel {
fn default() -> Self {
Self::ReadCommited
}
}
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum TrOp {
Commit,
CommitRetaining,
Rollback,
RollbackRetaining,
}
#[repr(u8)]
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum FreeStmtOp {
Close = ibase::DSQL_close as u8,
Drop = ibase::DSQL_drop as u8,
}
#[repr(u8)]
#[derive(Debug, Eq, PartialEq, Copy, Clone, TryFromPrimitive)]
pub enum StmtType {
Select = ibase::isc_info_sql_stmt_select as u8,
Insert = ibase::isc_info_sql_stmt_insert as u8,
Update = ibase::isc_info_sql_stmt_update as u8,
Delete = ibase::isc_info_sql_stmt_delete as u8,
DDL = ibase::isc_info_sql_stmt_ddl as u8,
GetSegment = ibase::isc_info_sql_stmt_get_segment as u8,
PutSegment = ibase::isc_info_sql_stmt_put_segment as u8,
ExecProcedure = ibase::isc_info_sql_stmt_exec_procedure as u8,
StartTrans = ibase::isc_info_sql_stmt_start_trans as u8,
Commit = ibase::isc_info_sql_stmt_commit as u8,
Rollback = ibase::isc_info_sql_stmt_rollback as u8,
SelectForUpd = ibase::isc_info_sql_stmt_select_for_upd as u8,
SetGenerator = ibase::isc_info_sql_stmt_set_generator as u8,
Savepoint = ibase::isc_info_sql_stmt_savepoint as u8,
}