Skip to content

Commit 219d10f

Browse files
committed
Change "update" to "execute"
Closes rust-postgres#24
1 parent 40f6a4e commit 219d10f

3 files changed

Lines changed: 63 additions & 63 deletions

File tree

lib.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@ fn main() {
2424
let conn = PostgresConnection::connect("postgres://postgres@localhost",
2525
&NoSsl);
2626
27-
conn.update("CREATE TABLE person (
27+
conn.execute("CREATE TABLE person (
2828
id SERIAL PRIMARY KEY,
2929
name VARCHAR NOT NULL,
3030
time_created TIMESTAMP NOT NULL,
3131
data BYTEA
32-
)", []);
32+
)", []);
3333
let me = Person {
3434
id: 0,
3535
name: ~"Steven",
3636
time_created: time::get_time(),
3737
data: None
3838
};
39-
conn.update("INSERT INTO person (name, time_created, data)
39+
conn.execute("INSERT INTO person (name, time_created, data)
4040
VALUES ($1, $2, $3)",
41-
[&me.name as &ToSql, &me.time_created as &ToSql,
42-
&me.data as &ToSql]);
41+
[&me.name as &ToSql, &me.time_created as &ToSql,
42+
&me.data as &ToSql]);
4343
4444
let stmt = conn.prepare("SELECT id, name, time_created, data FROM person");
4545
for row in stmt.query([]) {
@@ -697,26 +697,26 @@ impl PostgresConnection {
697697
}
698698
}
699699

700-
/// A convenience function for update queries that are only run once.
700+
/// A convenience function for queries that are only run once.
701701
///
702702
/// If an error is returned, it could have come from either the preparation
703703
/// or execution of the statement.
704704
///
705705
/// On success, returns the number of rows modified or 0 if not applicable.
706-
pub fn try_update(&self, query: &str, params: &[&ToSql])
706+
pub fn try_execute(&self, query: &str, params: &[&ToSql])
707707
-> Result<uint, PostgresDbError> {
708-
self.try_prepare(query).and_then(|stmt| stmt.try_update(params))
708+
self.try_prepare(query).and_then(|stmt| stmt.try_execute(params))
709709
}
710710

711-
/// A convenience wrapper around `try_update`.
711+
/// A convenience wrapper around `try_execute`.
712712
///
713713
/// # Failure
714714
///
715715
/// Fails if there was an error preparing or executing the statement.
716-
pub fn update(&self, query: &str, params: &[&ToSql]) -> uint {
717-
match self.try_update(query, params) {
716+
pub fn execute(&self, query: &str, params: &[&ToSql]) -> uint {
717+
match self.try_execute(query, params) {
718718
Ok(res) => res,
719-
Err(err) => fail!("Error running update:\n{}",
719+
Err(err) => fail!("Error running query:\n{}",
720720
err.pretty_error(query))
721721
}
722722
}
@@ -803,15 +803,15 @@ impl<'conn> PostgresTransaction<'conn> {
803803
}
804804
}
805805

806-
/// Like `PostgresConnection::try_update`.
807-
pub fn try_update(&self, query: &str, params: &[&ToSql])
806+
/// Like `PostgresConnection::try_execute`.
807+
pub fn try_execute(&self, query: &str, params: &[&ToSql])
808808
-> Result<uint, PostgresDbError> {
809-
self.conn.try_update(query, params)
809+
self.conn.try_execute(query, params)
810810
}
811811

812-
/// Like `PostgresConnection::update`.
813-
pub fn update(&self, query: &str, params: &[&ToSql]) -> uint {
814-
self.conn.update(query, params)
812+
/// Like `PostgresConnection::execute`.
813+
pub fn execute(&self, query: &str, params: &[&ToSql]) -> uint {
814+
self.conn.execute(query, params)
815815
}
816816

817817
/// Like `PostgresConnection::transaction`.
@@ -862,17 +862,17 @@ pub trait PostgresStatement {
862862
///
863863
/// Fails if the number or types of the provided parameters do not match
864864
/// the parameters of the statement.
865-
fn try_update(&self, params: &[&ToSql]) -> Result<uint, PostgresDbError>;
865+
fn try_execute(&self, params: &[&ToSql]) -> Result<uint, PostgresDbError>;
866866

867-
/// A convenience function wrapping `try_update`.
867+
/// A convenience function wrapping `try_execute`.
868868
///
869869
/// # Failure
870870
///
871871
/// Fails if there was an error executing the statement.
872-
fn update(&self, params: &[&ToSql]) -> uint {
873-
match self.try_update(params) {
872+
fn execute(&self, params: &[&ToSql]) -> uint {
873+
match self.try_execute(params) {
874874
Ok(count) => count,
875-
Err(err) => fail!("Error running update\n{}", err.to_str())
875+
Err(err) => fail!("Error running query\n{}", err.to_str())
876876
}
877877
}
878878

@@ -1002,7 +1002,7 @@ impl<'conn> PostgresStatement for NormalPostgresStatement<'conn> {
10021002
self.result_desc.as_slice()
10031003
}
10041004

1005-
fn try_update(&self, params: &[&ToSql])
1005+
fn try_execute(&self, params: &[&ToSql])
10061006
-> Result<uint, PostgresDbError> {
10071007
match self.execute("", 0, params) {
10081008
Some(err) => return Err(err),
@@ -1080,8 +1080,8 @@ impl<'conn> PostgresStatement for TransactionalPostgresStatement<'conn> {
10801080
self.stmt.result_descriptions()
10811081
}
10821082

1083-
fn try_update(&self, params: &[&ToSql]) -> Result<uint, PostgresDbError> {
1084-
self.stmt.try_update(params)
1083+
fn try_execute(&self, params: &[&ToSql]) -> Result<uint, PostgresDbError> {
1084+
self.stmt.try_execute(params)
10851085
}
10861086

10871087
fn try_query<'a>(&'a self, params: &[&ToSql])

pool.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ impl PooledPostgresConnection {
130130
self.conn.get_ref().prepare(query)
131131
}
132132

133-
/// Like `PostgresConnection::try_update`.
134-
pub fn try_update(&self, query: &str, params: &[&ToSql])
133+
/// Like `PostgresConnection::try_execute`.
134+
pub fn try_execute(&self, query: &str, params: &[&ToSql])
135135
-> Result<uint, PostgresDbError> {
136-
self.conn.get_ref().try_update(query, params)
136+
self.conn.get_ref().try_execute(query, params)
137137
}
138138

139-
/// Like `PostgresConnection::update`.
140-
pub fn update(&self, query: &str, params: &[&ToSql]) -> uint {
141-
self.conn.get_ref().update(query, params)
139+
/// Like `PostgresConnection::execute`.
140+
pub fn execute(&self, query: &str, params: &[&ToSql]) -> uint {
141+
self.conn.get_ref().execute(query, params)
142142
}
143143

144144
/// Like `PostgresConnection::transaction`.

test.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ fn test_unknown_database() {
9797
#[test]
9898
fn test_transaction_commit() {
9999
let conn = PostgresConnection::connect("postgres://postgres@localhost", &NoSsl);
100-
conn.update("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []);
100+
conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []);
101101

102102
let trans = conn.transaction();
103-
trans.update("INSERT INTO foo (id) VALUES ($1)", [&1i32 as &ToSql]);
103+
trans.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32 as &ToSql]);
104104
drop(trans);
105105

106106
let stmt = conn.prepare("SELECT * FROM foo");
@@ -112,12 +112,12 @@ fn test_transaction_commit() {
112112
#[test]
113113
fn test_transaction_rollback() {
114114
let conn = PostgresConnection::connect("postgres://postgres@localhost", &NoSsl);
115-
conn.update("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []);
115+
conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []);
116116

117-
conn.update("INSERT INTO foo (id) VALUES ($1)", [&1i32 as &ToSql]);
117+
conn.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32 as &ToSql]);
118118

119119
let trans = conn.transaction();
120-
trans.update("INSERT INTO foo (id) VALUES ($1)", [&2i32 as &ToSql]);
120+
trans.execute("INSERT INTO foo (id) VALUES ($1)", [&2i32 as &ToSql]);
121121
trans.set_rollback();
122122
drop(trans);
123123

@@ -130,33 +130,33 @@ fn test_transaction_rollback() {
130130
#[test]
131131
fn test_nested_transactions() {
132132
let conn = PostgresConnection::connect("postgres://postgres@localhost", &NoSsl);
133-
conn.update("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []);
133+
conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []);
134134

135-
conn.update("INSERT INTO foo (id) VALUES (1)", []);
135+
conn.execute("INSERT INTO foo (id) VALUES (1)", []);
136136

137137
{
138138
let trans1 = conn.transaction();
139-
trans1.update("INSERT INTO foo (id) VALUES (2)", []);
139+
trans1.execute("INSERT INTO foo (id) VALUES (2)", []);
140140

141141
{
142142
let trans2 = trans1.transaction();
143-
trans2.update("INSERT INTO foo (id) VALUES (3)", []);
143+
trans2.execute("INSERT INTO foo (id) VALUES (3)", []);
144144
trans2.set_rollback();
145145
}
146146

147147
{
148148
let trans2 = trans1.transaction();
149-
trans2.update("INSERT INTO foo (id) VALUES (4)", []);
149+
trans2.execute("INSERT INTO foo (id) VALUES (4)", []);
150150

151151
{
152152
let trans3 = trans2.transaction();
153-
trans3.update("INSERT INTO foo (id) VALUES (5)", []);
153+
trans3.execute("INSERT INTO foo (id) VALUES (5)", []);
154154
trans3.set_rollback();
155155
}
156156

157157
{
158158
let trans3 = trans2.transaction();
159-
trans3.update("INSERT INTO foo (id) VALUES (6)", []);
159+
trans3.execute("INSERT INTO foo (id) VALUES (6)", []);
160160
}
161161
}
162162

@@ -177,8 +177,8 @@ fn test_nested_transactions() {
177177
#[test]
178178
fn test_query() {
179179
let conn = PostgresConnection::connect("postgres://postgres@localhost", &NoSsl);
180-
conn.update("CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY)", []);
181-
conn.update("INSERT INTO foo (id) VALUES ($1), ($2)",
180+
conn.execute("CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY)", []);
181+
conn.execute("INSERT INTO foo (id) VALUES ($1), ($2)",
182182
[&1i64 as &ToSql, &2i64 as &ToSql]);
183183
let stmt = conn.prepare("SELECT * from foo ORDER BY id");
184184
let result = stmt.query([]);
@@ -192,11 +192,11 @@ fn test_lazy_query() {
192192

193193
{
194194
let trans = conn.transaction();
195-
trans.update("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []);
195+
trans.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []);
196196
let stmt = trans.prepare("INSERT INTO foo (id) VALUES ($1)");
197197
let values = ~[0i32, 1, 2, 3, 4, 5];
198198
for value in values.iter() {
199-
stmt.update([value as &ToSql]);
199+
stmt.execute([value as &ToSql]);
200200
}
201201

202202
let stmt = trans.prepare("SELECT id FROM foo ORDER BY id");
@@ -298,11 +298,11 @@ fn test_text_params() {
298298
#[test]
299299
fn test_bpchar_params() {
300300
let conn = PostgresConnection::connect("postgres://postgres@localhost", &NoSsl);
301-
conn.update("CREATE TEMPORARY TABLE foo (
301+
conn.execute("CREATE TEMPORARY TABLE foo (
302302
id SERIAL PRIMARY KEY,
303303
b CHAR(5)
304304
)", []);
305-
conn.update("INSERT INTO foo (b) VALUES ($1), ($2), ($3)",
305+
conn.execute("INSERT INTO foo (b) VALUES ($1), ($2), ($3)",
306306
[&Some("12345") as &ToSql, &Some("123") as &ToSql,
307307
&None::<~str> as &ToSql]);
308308
let stmt = conn.prepare("SELECT b FROM foo ORDER BY id");
@@ -587,21 +587,21 @@ fn test_f64_nan_param() {
587587
#[should_fail]
588588
fn test_wrong_param_type() {
589589
let conn = PostgresConnection::connect("postgres://postgres@localhost", &NoSsl);
590-
conn.try_update("SELECT $1::VARCHAR", [&1i32 as &ToSql]);
590+
conn.try_execute("SELECT $1::VARCHAR", [&1i32 as &ToSql]);
591591
}
592592

593593
#[test]
594594
#[should_fail]
595595
fn test_too_few_params() {
596596
let conn = PostgresConnection::connect("postgres://postgres@localhost", &NoSsl);
597-
conn.try_update("SELECT $1::INT, $2::INT", [&1i32 as &ToSql]);
597+
conn.try_execute("SELECT $1::INT, $2::INT", [&1i32 as &ToSql]);
598598
}
599599

600600
#[test]
601601
#[should_fail]
602602
fn test_too_many_params() {
603603
let conn = PostgresConnection::connect("postgres://postgres@localhost", &NoSsl);
604-
conn.try_update("SELECT $1::INT, $2::INT", [&1i32 as &ToSql,
604+
conn.try_execute("SELECT $1::INT, $2::INT", [&1i32 as &ToSql,
605605
&2i32 as &ToSql,
606606
&3i32 as &ToSql]);
607607
}
@@ -638,12 +638,12 @@ fn test_custom_notice_handler() {
638638

639639
let conn = PostgresConnection::connect("postgres://postgres@localhost?client_min_messages=NOTICE", &NoSsl);
640640
conn.set_notice_handler(~Handler as ~PostgresNoticeHandler);
641-
conn.update("CREATE FUNCTION pg_temp.note() RETURNS INT AS $$
641+
conn.execute("CREATE FUNCTION pg_temp.note() RETURNS INT AS $$
642642
BEGIN
643643
RAISE NOTICE 'note';
644644
RETURN 1;
645645
END; $$ LANGUAGE plpgsql", []);
646-
conn.update("SELECT pg_temp.note()", []);
646+
conn.execute("SELECT pg_temp.note()", []);
647647

648648
assert_eq!(unsafe { count }, 1);
649649
}
@@ -669,10 +669,10 @@ fn test_notification_iterator_some() {
669669

670670
let conn = PostgresConnection::connect("postgres://postgres@localhost", &NoSsl);
671671
let mut it = conn.notifications();
672-
conn.update("LISTEN test_notification_iterator_one_channel", []);
673-
conn.update("LISTEN test_notification_iterator_one_channel2", []);
674-
conn.update("NOTIFY test_notification_iterator_one_channel, 'hello'", []);
675-
conn.update("NOTIFY test_notification_iterator_one_channel2, 'world'", []);
672+
conn.execute("LISTEN test_notification_iterator_one_channel", []);
673+
conn.execute("LISTEN test_notification_iterator_one_channel2", []);
674+
conn.execute("NOTIFY test_notification_iterator_one_channel, 'hello'", []);
675+
conn.execute("NOTIFY test_notification_iterator_one_channel2, 'world'", []);
676676

677677
check_notification(PostgresNotification {
678678
pid: 0,
@@ -686,7 +686,7 @@ fn test_notification_iterator_some() {
686686
}, it.next());
687687
assert!(it.next().is_none());
688688
689-
conn.update("NOTIFY test_notification_iterator_one_channel, '!'", []);
689+
conn.execute("NOTIFY test_notification_iterator_one_channel, '!'", []);
690690
check_notification(PostgresNotification {
691691
pid: 0,
692692
channel: ~"test_notification_iterator_one_channel",
@@ -707,7 +707,7 @@ fn test_cancel_query() {
707707
cancel_data).is_ok());
708708
}
709709

710-
match conn.try_update("SELECT pg_sleep(10)", []) {
710+
match conn.try_execute("SELECT pg_sleep(10)", []) {
711711
Err(PostgresDbError { code: QueryCanceled, .. }) => {}
712712
res => fail!("Unexpected result {:?}", res)
713713
}
@@ -718,15 +718,15 @@ fn test_require_ssl_conn() {
718718
let ctx = SslContext::new(Sslv3);
719719
let conn = PostgresConnection::connect("postgres://postgres@localhost",
720720
&RequireSsl(ctx));
721-
conn.update("SELECT 1::VARCHAR", []);
721+
conn.execute("SELECT 1::VARCHAR", []);
722722
}
723723

724724
#[test]
725725
fn test_prefer_ssl_conn() {
726726
let ctx = SslContext::new(Sslv3);
727727
let conn = PostgresConnection::connect("postgres://postgres@localhost",
728728
&PreferSsl(ctx));
729-
conn.update("SELECT 1::VARCHAR", []);
729+
conn.execute("SELECT 1::VARCHAR", []);
730730
}
731731

732732
#[test]

0 commit comments

Comments
 (0)