Skip to content

Commit b170c00

Browse files
committed
sql-text -> sql-query
1 parent b51bd36 commit b170c00

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Options
1717
-------
1818
* `-m/--mode`: `postgres` or `odbc`
1919
* `-c/--connection-string`: Mode-appropriate connection string. So `postgresql://<username>:<pasword>@<host>:<port>` or `Driver=<path to driver>;<various ODBC options>` depending on your driver
20-
* `-s/--sql-text`: SQL query to run once connected. It should return at least one row, or will be regarded as failing. Default: no query, just be regarded as succeeding the moment it connects.
20+
* `-s/--sql-query`: SQL query to run once connected. It should return at least one row, or will be regarded as failing. Default: no query, just be regarded as succeeding the moment it connects.
2121
* `-p/--pause`: Pause between attempts for non-permanent failures. Default is 3 seconds
2222
* `-t/--timeout`: Time to wait before failing entirely. Default is wait forever.
2323

src/common.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl DbMode {
2020
pub struct Opts {
2121
pub mode: DbMode,
2222
pub connection_string: String,
23-
pub sql_text: Option<String>,
23+
pub sql_query: Option<String>,
2424
pub timeout_seconds: Option<u64>,
2525
pub quiet: bool,
2626
pub pause_seconds: u64,
@@ -47,9 +47,9 @@ pub fn parse_args() -> Opts {
4747
.help("Connection string"),
4848
)
4949
.arg(
50-
Arg::with_name("sql-text")
50+
Arg::with_name("sql-query")
5151
.short("s")
52-
.long("sql-text")
52+
.long("sql-query")
5353
.takes_value(true)
5454
.help("SQL query that should return at least one row (default: no querying)"),
5555
)
@@ -78,8 +78,8 @@ pub fn parse_args() -> Opts {
7878
Opts {
7979
mode: DbMode::from_str(matches.value_of("mode").unwrap()),
8080
connection_string: matches.value_of("connection-string").unwrap().to_string(),
81-
sql_text: matches
82-
.value_of("sql-text")
81+
sql_query: matches
82+
.value_of("sql-query")
8383
.and_then(|s| Some(s.to_string())),
8484
timeout_seconds: matches
8585
.value_of("timeout")
@@ -98,7 +98,7 @@ impl Opts {
9898
Opts {
9999
mode: DbMode::Odbc,
100100
connection_string: "".to_string(),
101-
sql_text: None,
101+
sql_query: None,
102102
timeout_seconds: None,
103103
quiet: false,
104104
pause_seconds: 3,
@@ -113,11 +113,11 @@ impl Opts {
113113
self
114114
}
115115

116-
pub fn sql_text<I>(mut self, st: I) -> Self
116+
pub fn sql_query<I>(mut self, st: I) -> Self
117117
where
118118
I: Into<String>,
119119
{
120-
self.sql_text = Some(st.into());
120+
self.sql_query = Some(st.into());
121121
self
122122
}
123123
}

src/odbc.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ impl From<DiagnosticRecord> for DbError {
3030
pub fn connect(opts: &Opts) -> std::result::Result<Vec<HashMap<String, String>>, DbError> {
3131
let env = create_environment_v3().map_err(|e| e.unwrap())?;
3232
let conn = env.connect_with_connection_string(&opts.connection_string)?;
33-
if let Some(ref sql_text) = opts.sql_text {
34-
execute_statement(&conn, sql_text)
33+
if let Some(ref sql_query) = opts.sql_query {
34+
execute_statement(&conn, sql_query)
3535
} else {
3636
return Ok(Vec::new());
3737
}
3838
}
3939

4040
fn execute_statement<'env>(
4141
conn: &Connection<'env, odbc_safe::AutocommitOn>,
42-
sql_text: &String,
42+
sql_query: &String,
4343
) -> Result<Vec<HashMap<String, String>>, DbError> {
4444
let stmt = Statement::with_parent(conn)?;
4545
let mut results: Vec<HashMap<String, String>> = Vec::new();
46-
match stmt.exec_direct(&sql_text)? {
46+
match stmt.exec_direct(&sql_query)? {
4747
Data(mut stmt) => {
4848
let col_count = stmt.num_result_cols()? as u16;
4949
let mut cols: HashMap<u16, odbc::ColumnDescriptor> = HashMap::new();
@@ -130,7 +130,7 @@ mod test {
130130
"Driver={};Database=test.db;",
131131
std::env::var("SQLITE_DRIVER").unwrap()
132132
))
133-
.sql_text("SELECT 1 from sqlite_master"),
133+
.sql_query("SELECT 1 from sqlite_master"),
134134
)
135135
.unwrap();
136136
}
@@ -159,7 +159,7 @@ mod test {
159159
connect(
160160
&Opts::new()
161161
.connection_string(postgres_connect())
162-
.sql_text("SHOW IS_SUPERUSER"),
162+
.sql_query("SHOW IS_SUPERUSER"),
163163
)
164164
.unwrap();
165165
}
@@ -170,7 +170,7 @@ mod test {
170170
let err = connect(
171171
&Opts::new()
172172
.connection_string(postgres_connect())
173-
.sql_text("foobar"),
173+
.sql_query("foobar"),
174174
)
175175
.unwrap_err();
176176
assert_eq!(err.kind, DbErrorLifetime::Permanent, "{:?}", err);

src/pg.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ impl From<Error> for DbError {
1919

2020
pub fn connect(opts: &Opts) -> std::result::Result<Vec<HashMap<String, String>>, DbError> {
2121
let conn = Connection::connect(opts.connection_string.as_str(), TlsMode::None)?;
22-
if let Some(ref sql_text) = opts.sql_text {
23-
execute_statement(&conn, sql_text)
22+
if let Some(ref sql_query) = opts.sql_query {
23+
execute_statement(&conn, sql_query)
2424
} else {
2525
return Ok(Vec::new());
2626
}
2727
}
2828

2929
fn execute_statement<'env>(
3030
conn: &postgres::Connection,
31-
sql_text: &String,
31+
sql_query: &String,
3232
) -> Result<Vec<HashMap<String, String>>, DbError> {
3333
let mut results: Vec<HashMap<String, String>> = Vec::new();
34-
let rows = conn.query(&sql_text, &[])?;
34+
let rows = conn.query(&sql_query, &[])?;
3535
let cols = rows.columns();
3636
for row in rows.iter() {
3737
let mut result: HashMap<String, String> = HashMap::new();
@@ -83,7 +83,7 @@ mod test {
8383
connect(
8484
&Opts::new()
8585
.connection_string(postgres_connect())
86-
.sql_text("SHOW IS_SUPERUSER"),
86+
.sql_query("SHOW IS_SUPERUSER"),
8787
)
8888
.unwrap();
8989
}
@@ -94,7 +94,7 @@ mod test {
9494
let err = connect(
9595
&Opts::new()
9696
.connection_string(postgres_connect())
97-
.sql_text("foobar"),
97+
.sql_query("foobar"),
9898
)
9999
.unwrap_err();
100100
assert_eq!(err.kind, DbErrorLifetime::Permanent, "{:?}", err);

tests/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn command_line_timeout_with_odbc() -> Result<(), Box<dyn std::error::Error>> {
1414
"--connection-string={}",
1515
wait_for_db::odbc::postgres_connect()
1616
))
17-
.arg("--sql-text=select 1 from foo");
17+
.arg("--sql-query=select 1 from foo");
1818
cmd.assert().failure().stdout(
1919
predicate::str::contains("Temporary error (exiting as out of time)").and(
2020
predicate::str::contains("ERROR: relation \"foo\" does not exist"),
@@ -34,7 +34,7 @@ fn command_line_timeout_with_postgres() -> Result<(), Box<dyn std::error::Error>
3434
"--connection-string={}",
3535
wait_for_db::pg::postgres_connect()
3636
))
37-
.arg("--sql-text=select 1 from foo");
37+
.arg("--sql-query=select 1 from foo");
3838
cmd.assert().failure().stdout(
3939
predicate::str::contains("Temporary error (exiting as out of time)").and(
4040
predicate::str::contains("message: \"relation \\\"foo\\\" does not exist\""),

0 commit comments

Comments
 (0)