Skip to content

Commit f1d97fb

Browse files
authored
refactor: don't set readonly by default (#377)
1 parent 63f3f2e commit f1d97fb

File tree

3 files changed

+49
-55
lines changed

3 files changed

+49
-55
lines changed

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,6 @@ mod settings {
605605
pub(crate) const DEFAULT_FORMAT: &str = "default_format";
606606
pub(crate) const COMPRESS: &str = "compress";
607607
pub(crate) const DECOMPRESS: &str = "decompress";
608-
pub(crate) const READONLY: &str = "readonly";
609608
pub(crate) const ROLE: &str = "role";
610609
pub(crate) const QUERY: &str = "query";
611610
}

src/query.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl Query {
5959

6060
/// Executes the query.
6161
pub async fn execute(self) -> Result<()> {
62-
self.do_execute(false, None)?.finish().await
62+
self.do_execute(None)?.finish().await
6363
}
6464

6565
/// Executes the query, returning a [`RowCursor`] to obtain results.
@@ -93,7 +93,7 @@ impl Query {
9393
formats::ROW_BINARY
9494
};
9595

96-
let response = self.do_execute(true, Some(format))?;
96+
let response = self.do_execute(Some(format))?;
9797
Ok(RowCursor::new(response, validation))
9898
}
9999

@@ -144,15 +144,11 @@ impl Query {
144144
///
145145
/// [provided format]: https://clickhouse.com/docs/en/interfaces/formats
146146
pub fn fetch_bytes(self, format: impl AsRef<str>) -> Result<BytesCursor> {
147-
let response = self.do_execute(true, Some(format.as_ref()))?;
147+
let response = self.do_execute(Some(format.as_ref()))?;
148148
Ok(BytesCursor::new(response))
149149
}
150150

151-
pub(crate) fn do_execute(
152-
self,
153-
readonly: bool,
154-
default_format: Option<&str>,
155-
) -> Result<Response> {
151+
pub(crate) fn do_execute(self, default_format: Option<&str>) -> Result<Response> {
156152
let query = self.sql.finish()?;
157153

158154
let mut url =
@@ -168,17 +164,6 @@ impl Query {
168164
pairs.append_pair(settings::DATABASE, database);
169165
}
170166

171-
// Normally, we enforce `readonly` for all `fetch_*` operations.
172-
// However, we still allow overriding it to support several niche use-cases,
173-
// e.g., temporary tables usage. See https://github.com/ClickHouse/clickhouse-rs/issues/230
174-
if readonly {
175-
let readonly_value = match self.client.options.get(settings::READONLY) {
176-
None => "1",
177-
Some(value) => value,
178-
};
179-
pairs.append_pair(settings::READONLY, readonly_value);
180-
}
181-
182167
if self.client.compression.is_lz4() {
183168
pairs.append_pair(settings::COMPRESS, "1");
184169
}

tests/it/query_readonly.rs

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,120 +40,130 @@ async fn readonly_user() {
4040
async fn test_fetch(client: &Client) {
4141
let query = select_readonly_setting_query(client);
4242
let initial_readonly_row = run_fetch(query).await;
43+
44+
// As of 0.14.2, we won't be implicitly setting `readonly` anymore.
4345
assert_eq!(
44-
initial_readonly_row.value, "1",
45-
"initial `fetch` readonly setting value should be 1"
46+
initial_readonly_row.value, "0",
47+
"initial `fetch` readonly setting value should be 0"
4648
);
4749

48-
let query = select_readonly_setting_query(client).with_option("readonly", "0");
50+
let query = select_readonly_setting_query(client).with_option("readonly", "1");
4951
let disabled_readonly_row = run_fetch(query).await;
5052
assert_eq!(
51-
disabled_readonly_row.value, "0",
52-
"`fetch` modified readonly setting value should be 0"
53+
disabled_readonly_row.value, "1",
54+
"`fetch` modified readonly setting value should be 1"
5355
);
5456

55-
let query = select_readonly_setting_query(client).with_option("readonly", "1");
57+
let query = select_readonly_setting_query(client).with_option("readonly", "0");
5658
let same_readonly_row = run_fetch(query).await;
5759
assert_eq!(
58-
same_readonly_row.value, "1",
60+
same_readonly_row.value, "0",
5961
"`fetch` should allow setting the same readonly setting value"
6062
);
6163
}
6264

6365
async fn test_fetch_bytes(client: &Client) {
6466
let query = select_readonly_setting_query(client);
6567
let initial_readonly_value = run_fetch_bytes(query).await;
68+
69+
// As of 0.14.2, we won't be implicitly setting `readonly` anymore.
6670
assert_eq!(
67-
initial_readonly_value, b"1\n",
68-
"initial `fetch_bytes` readonly setting value should be 1"
71+
initial_readonly_value, b"0\n",
72+
"initial `fetch_bytes` readonly setting value should be 0"
6973
);
7074

71-
let query = select_readonly_setting_query(client).with_option("readonly", "0");
75+
let query = select_readonly_setting_query(client).with_option("readonly", "1");
7276
let disabled_readonly_value = run_fetch_bytes(query).await;
7377
assert_eq!(
74-
disabled_readonly_value, b"0\n",
75-
"`fetch_bytes` modified readonly setting value should be 0"
78+
disabled_readonly_value, b"1\n",
79+
"`fetch_bytes` modified readonly setting value should be 1"
7680
);
7781

78-
let query = select_readonly_setting_query(client).with_option("readonly", "1");
82+
let query = select_readonly_setting_query(client).with_option("readonly", "0");
7983
let same_readonly_value = run_fetch_bytes(query).await;
8084
assert_eq!(
81-
same_readonly_value, b"1\n",
85+
same_readonly_value, b"0\n",
8286
"`fetch_bytes` should allow setting the same readonly setting value"
8387
);
8488
}
8589

8690
async fn test_fetch_one(client: &Client) {
8791
let query = select_readonly_setting_query(client);
8892
let initial_readonly_value: String = run_fetch_one(query).await;
93+
94+
// As of 0.14.2, we won't be implicitly setting `readonly` anymore.
8995
assert_eq!(
90-
initial_readonly_value, "1",
91-
"initial `fetch_one` readonly setting value should be 1"
96+
initial_readonly_value, "0",
97+
"initial `fetch_one` readonly setting value should be 0"
9298
);
9399

94-
let query = select_readonly_setting_query(client).with_option("readonly", "0");
100+
let query = select_readonly_setting_query(client).with_option("readonly", "1");
95101
let disabled_readonly_value: String = run_fetch_one(query).await;
96102
assert_eq!(
97-
disabled_readonly_value, "0",
98-
"`fetch_one` modified readonly setting value should be 0"
103+
disabled_readonly_value, "1",
104+
"`fetch_one` modified readonly setting value should be 1"
99105
);
100106

101-
let query = select_readonly_setting_query(client).with_option("readonly", "1");
107+
let query = select_readonly_setting_query(client).with_option("readonly", "0");
102108
let same_readonly_value: String = run_fetch_one(query).await;
103109
assert_eq!(
104-
same_readonly_value, "1",
110+
same_readonly_value, "0",
105111
"`fetch_one` should allow setting the same readonly setting value"
106112
);
107113
}
108114

109115
async fn test_fetch_optional(client: &Client) {
110116
let query = select_readonly_setting_query(client);
111117
let initial_readonly_value: Option<String> = run_fetch_optional(query).await;
118+
119+
// As of 0.14.2, we won't be implicitly setting `readonly` anymore.
112120
assert_eq!(
113121
initial_readonly_value.as_deref(),
114-
Some("1"),
115-
"initial `fetch_optional` readonly setting value should be 1"
122+
Some("0"),
123+
"initial `fetch_optional` readonly setting value should be 0"
116124
);
117125

118-
let query = select_readonly_setting_query(client).with_option("readonly", "0");
126+
let query = select_readonly_setting_query(client).with_option("readonly", "1");
119127
let disabled_readonly_value: Option<String> = run_fetch_optional(query).await;
120128
assert_eq!(
121129
disabled_readonly_value.as_deref(),
122-
Some("0"),
123-
"`fetch_optional` modified readonly setting value should be 0"
130+
Some("1"),
131+
"`fetch_optional` modified readonly setting value should be 1"
124132
);
125133

126-
let query = select_readonly_setting_query(client).with_option("readonly", "1");
134+
let query = select_readonly_setting_query(client).with_option("readonly", "0");
127135
let same_readonly_value: Option<String> = run_fetch_optional(query).await;
128136
assert_eq!(
129137
same_readonly_value.as_deref(),
130-
Some("1"),
138+
Some("0"),
131139
"`fetch_optional` should allow setting the same readonly setting value"
132140
);
133141
}
134142

135143
async fn test_fetch_all(client: &Client) {
136144
let query = select_readonly_setting_query(client);
137145
let initial_readonly_value: Vec<String> = run_fetch_all(query).await;
146+
147+
// As of 0.14.2, we won't be implicitly setting `readonly` anymore.
138148
assert_eq!(
139149
initial_readonly_value,
140-
vec!["1"],
141-
"initial `fetch_all` readonly setting value should be 1"
150+
vec!["0"],
151+
"initial `fetch_all` readonly setting value should be 0"
142152
);
143153

144-
let query = select_readonly_setting_query(client).with_option("readonly", "0");
154+
let query = select_readonly_setting_query(client).with_option("readonly", "1");
145155
let disabled_readonly_value: Vec<String> = run_fetch_all(query).await;
146156
assert_eq!(
147157
disabled_readonly_value,
148-
vec!["0"],
149-
"`fetch_all` modified readonly setting value should be 0"
158+
vec!["1"],
159+
"`fetch_all` modified readonly setting value should be 1"
150160
);
151161

152-
let query = select_readonly_setting_query(client).with_option("readonly", "1");
162+
let query = select_readonly_setting_query(client).with_option("readonly", "0");
153163
let same_readonly_value: Vec<String> = run_fetch_all(query).await;
154164
assert_eq!(
155165
same_readonly_value,
156-
vec!["1"],
166+
vec!["0"],
157167
"`fetch_all` should allow setting the same readonly setting value"
158168
);
159169
}

0 commit comments

Comments
 (0)