Skip to content

Commit 681a660

Browse files
committed
Always silence notices on PG
I don't care that my `CASCADE` query did in fact cascade to things, and I certainly don't want it printing to stderr ever.
1 parent 846b3f8 commit 681a660

6 files changed

Lines changed: 13 additions & 45 deletions

File tree

diesel/src/connection/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ pub trait Connection: SimpleConnection + Sized + Send {
150150
where
151151
T: QueryFragment<Self::Backend> + QueryId;
152152

153-
#[doc(hidden)]
154-
fn silence_notices<F: FnOnce() -> T, T>(&self, f: F) -> T;
155153
#[doc(hidden)]
156154
fn transaction_manager(&self) -> &Self::TransactionManager;
157155
}

diesel/src/migrations/mod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,12 @@ pub fn setup_database<Conn: Connection>(conn: &Conn) -> QueryResult<usize> {
235235
}
236236

237237
fn create_schema_migrations_table_if_needed<Conn: Connection>(conn: &Conn) -> QueryResult<usize> {
238-
conn.silence_notices(|| {
239-
conn.execute(
240-
"CREATE TABLE IF NOT EXISTS __diesel_schema_migrations (
241-
version VARCHAR(50) PRIMARY KEY NOT NULL,
242-
run_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
243-
)",
244-
)
245-
})
238+
conn.execute(
239+
"CREATE TABLE IF NOT EXISTS __diesel_schema_migrations (\
240+
version VARCHAR(50) PRIMARY KEY NOT NULL,\
241+
run_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP\
242+
)",
243+
)
246244
}
247245

248246
#[doc(hidden)]

diesel/src/mysql/connection/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ impl Connection for MysqlConnection {
8080
})
8181
}
8282

83-
#[doc(hidden)]
84-
fn silence_notices<F: FnOnce() -> T, T>(&self, f: F) -> T {
85-
f()
86-
}
87-
8883
#[doc(hidden)]
8984
fn execute_returning_count<T>(&self, source: &T) -> QueryResult<usize>
9085
where

diesel/src/pg/connection/mod.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod row;
55
pub mod result;
66
mod stmt;
77

8-
use std::ffi::{CStr, CString};
8+
use std::ffi::CString;
99
use std::os::raw as libc;
1010

1111
use connection::*;
@@ -88,16 +88,6 @@ impl Connection for PgConnection {
8888
.map(|r| r.rows_affected())
8989
}
9090

91-
#[doc(hidden)]
92-
fn silence_notices<F: FnOnce() -> T, T>(&self, f: F) -> T {
93-
self.raw_connection
94-
.set_notice_processor(noop_notice_processor);
95-
let result = f();
96-
self.raw_connection
97-
.set_notice_processor(default_notice_processor);
98-
result
99-
}
100-
10191
#[doc(hidden)]
10292
fn transaction_manager(&self) -> &Self::TransactionManager {
10393
&self.transaction_manager
@@ -142,20 +132,14 @@ impl PgConnection {
142132
fn set_config_options(&self) -> QueryResult<()> {
143133
self.execute("SET TIME ZONE 'UTC'")?;
144134
self.execute("SET CLIENT_ENCODING TO 'UTF8'")?;
135+
self.raw_connection
136+
.set_notice_processor(noop_notice_processor);
145137
Ok(())
146138
}
147139
}
148140

149141
extern "C" fn noop_notice_processor(_: *mut libc::c_void, _message: *const libc::c_char) {}
150142

151-
extern "C" fn default_notice_processor(_: *mut libc::c_void, message: *const libc::c_char) {
152-
use std::io::Write;
153-
let c_str = unsafe { CStr::from_ptr(message) };
154-
::std::io::stderr()
155-
.write_all(c_str.to_bytes())
156-
.expect("Error writing to `stderr`");
157-
}
158-
159143
#[cfg(test)]
160144
mod tests {
161145
extern crate dotenv;

diesel/src/sqlite/connection/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ impl Connection for SqliteConnection {
8585
Ok(self.raw_connection.rows_affected_by_last_query())
8686
}
8787

88-
#[doc(hidden)]
89-
fn silence_notices<F: FnOnce() -> T, T>(&self, f: F) -> T {
90-
f()
91-
}
92-
9388
#[doc(hidden)]
9489
fn transaction_manager(&self) -> &Self::TransactionManager {
9590
&self.transaction_manager

diesel_cli/tests/support/postgres_database.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,9 @@ impl Drop for Database {
6161
PgConnection::establish(&postgres_url),
6262
"Couldn't connect to database"
6363
);
64-
conn.silence_notices(|| {
65-
try_drop!(
66-
conn.execute(&format!(r#"DROP DATABASE IF EXISTS "{}""#, database)),
67-
"Couldn't drop database"
68-
);
69-
});
64+
try_drop!(
65+
conn.execute(&format!(r#"DROP DATABASE IF EXISTS "{}""#, database)),
66+
"Couldn't drop database"
67+
);
7068
}
7169
}

0 commit comments

Comments
 (0)