1mod connect;
2mod parse;
3
4use sqlx_core::connection::LogSettings;
5
6#[derive(Debug, Clone)]
7pub struct XuguConnectOptions {
8 pub(crate) host: String,
9 pub(crate) port: u16,
10 pub(crate) user: String,
11 pub(crate) password: String,
12 pub(crate) database: String,
13 pub(crate) charset: String,
14 version: Option<i16>,
15 return_schema: bool,
16 return_rowid: bool,
17 encryptor: Option<String>,
18 time_zone: Option<String>,
19 iso_level: Option<String>,
20 lock_timeout: Option<String>,
21 lob_ret: Option<String>,
22 identity_mode: Option<String>,
23 keyword_filter: Option<String>,
24 disable_binlog: Option<String>,
25 auto_commit: bool,
26 pub(crate) use_ssl: bool,
27 current_schema: Option<String>,
28 compatible_mode: Option<String>,
29
30 pub(crate) log_settings: LogSettings,
31}
32
33impl Default for XuguConnectOptions {
34 fn default() -> Self {
35 Self::new()
36 }
37}
38
39impl XuguConnectOptions {
40 pub(crate) fn to_conn_str(&self) -> String {
41 let return_schema = if self.return_schema { "on" } else { "off" };
42 let version = self.get_version();
43 let mut conn_str = format!(
45 "login database='{}' user='{}' password='{}' version={} return_schema={} return_cursor_id=on",
46 self.database, self.user, self.password, version, return_schema,
47 );
48
49 if self.return_rowid {
51 conn_str += " return_rowid=true";
52 }
53 if let Some(encryptor) = &self.encryptor {
54 conn_str += " encryptor=";
55 conn_str += encryptor;
56 }
57 if self.charset.is_empty() {
58 conn_str += " char_set=utf8";
59 } else {
60 conn_str = conn_str + " char_set=" + self.charset.as_str();
61 }
62 if let Some(time_zone) = &self.time_zone {
63 conn_str = conn_str + " time_zone='" + time_zone + "'";
64 }
65 if let Some(iso_level) = &self.iso_level {
66 conn_str += " iso_level='";
67 conn_str += iso_level;
68 conn_str += "'";
69 }
70 if let Some(lock_timeout) = &self.lock_timeout {
71 conn_str += " lock_timeout=";
72 conn_str += lock_timeout;
73 }
74 if let Some(lob_ret) = &self.lob_ret {
75 conn_str += " lob_ret='";
76 conn_str += lob_ret;
77 conn_str += "'";
78 }
79 if let Some(identity_mode) = &self.identity_mode {
80 conn_str += " identity_mode='";
81 conn_str += identity_mode;
82 conn_str += "'";
83 }
84 if let Some(keyword_filter) = &self.keyword_filter {
85 conn_str += " keyword_filter='";
86 conn_str += keyword_filter;
87 conn_str += "'";
88 }
89 if let Some(disable_binlog) = &self.disable_binlog {
90 conn_str += " disable_binlog='";
91 conn_str += disable_binlog;
92 conn_str += "'";
93 }
94 if self.auto_commit {
95 conn_str += " auto_commit=on";
96 } else {
97 conn_str += " auto_commit=off";
98 }
99 if let Some(current_schema) = &self.current_schema {
100 conn_str += " current_schema='";
101 conn_str += current_schema;
102 conn_str += "'";
103 }
104 if let Some(compatible_mode) = &self.compatible_mode {
105 conn_str += " compatible_mode='";
106 conn_str += compatible_mode;
107 conn_str += "'";
108 }
109
110 conn_str += "\0";
111 conn_str
112 }
113
114 pub fn get_version(&self) -> i16 {
115 self.version.unwrap_or(301)
116 }
117}
118
119impl XuguConnectOptions {
120 pub fn new() -> Self {
122 Self {
123 host: String::from("127.0.0.1"),
124 port: 5138,
125 database: String::from("SYSTEM"),
126 user: String::from("SYSDBA"),
127 password: String::from("SYSDBA"),
128 version: None,
129 return_schema: true,
130 return_rowid: false,
131 encryptor: None,
132 charset: String::from("utf8"),
133 time_zone: None,
134 iso_level: Some(String::from("READ COMMITTED")),
135 lock_timeout: None,
136 lob_ret: None,
137 identity_mode: None,
138 keyword_filter: None,
139 disable_binlog: None,
140 auto_commit: true,
141 use_ssl: false,
142 current_schema: None,
143 compatible_mode: None,
144
145 log_settings: Default::default(),
146 }
147 }
148
149 pub fn host(mut self, host: &str) -> Self {
154 host.clone_into(&mut self.host);
155 self
156 }
157
158 pub fn port(mut self, port: u16) -> Self {
162 self.port = port;
163 self
164 }
165
166 pub fn database(mut self, database: &str) -> Self {
168 self.database = database.to_owned();
169 self
170 }
171
172 pub fn user(mut self, user: &str) -> Self {
174 user.clone_into(&mut self.user);
175 self
176 }
177
178 pub fn password(mut self, password: &str) -> Self {
180 self.password = password.to_owned();
181 self
182 }
183
184 pub fn version(mut self, version: i16) -> Self {
186 self.version = Some(version);
187 self
188 }
189
190 pub fn return_schema(mut self, value: bool) -> Self {
191 self.return_schema = value;
192 self
193 }
194
195 pub fn return_rowid(mut self, value: bool) -> Self {
196 self.return_schema = value;
197 self
198 }
199
200 pub fn encryptor(mut self, value: &str) -> Self {
201 self.encryptor = Some(value.into());
202 self
203 }
204
205 pub fn iso_level(mut self, value: &str) -> Self {
206 self.iso_level = Some(value.into());
207 self
208 }
209
210 pub fn lock_timeout(mut self, value: &str) -> Self {
211 self.lock_timeout = Some(value.into());
212 self
213 }
214
215 pub fn lob_ret(mut self, value: &str) -> Self {
216 self.lob_ret = Some(value.into());
217 self
218 }
219
220 pub fn identity_mode(mut self, value: &str) -> Self {
221 self.identity_mode = Some(value.into());
222 self
223 }
224
225 pub fn keyword_filter(mut self, value: &str) -> Self {
226 self.keyword_filter = Some(value.into());
227 self
228 }
229
230 pub fn disable_binlog(mut self, value: &str) -> Self {
231 self.disable_binlog = Some(value.into());
232 self
233 }
234
235 pub fn auto_commit(mut self, value: bool) -> Self {
236 self.auto_commit = value;
237 self
238 }
239
240 pub fn use_ssl(mut self, value: bool) -> Self {
241 self.use_ssl = value;
242 self
243 }
244
245 pub fn current_schema(mut self, value: &str) -> Self {
246 self.current_schema = Some(value.into());
247 self
248 }
249
250 pub fn compatible_mode(mut self, value: &str) -> Self {
251 self.compatible_mode = Some(value.into());
252 self
253 }
254
255 pub fn charset(mut self, charset: &str) -> Self {
262 charset.clone_into(&mut self.charset);
263 self
264 }
265
266 pub fn timezone(mut self, value: impl Into<Option<String>>) -> Self {
283 self.time_zone = value.into();
284 self
285 }
286}
287
288impl XuguConnectOptions {
289 pub fn get_host(&self) -> &str {
300 &self.host
301 }
302
303 pub fn get_port(&self) -> u16 {
314 self.port
315 }
316
317 pub fn get_user(&self) -> &str {
328 &self.user
329 }
330
331 pub fn get_database(&self) -> &str {
342 &self.database
343 }
344
345 pub fn get_charset(&self) -> &str {
355 &self.charset
356 }
357}