Skip to content

Commit c6333f0

Browse files
committed
Fix transaction batch_execute
1 parent d094aa6 commit c6333f0

File tree

5 files changed

+37
-22
lines changed

5 files changed

+37
-22
lines changed

src/lib/lib.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ pub struct PostgresNotifications<'conn> {
300300
impl<'conn> Iterator<PostgresNotification> for PostgresNotifications<'conn> {
301301
/// Returns the oldest pending notification or `None` if there are none.
302302
///
303-
/// # Note
303+
/// ## Note
304304
///
305305
/// `next` may return `Some` notification after returning `None` if a new
306306
/// notification was received.
@@ -330,7 +330,7 @@ pub struct PostgresCancelData {
330330
/// Only the host and port of the connetion info are used. See
331331
/// `PostgresConnection::connect` for details of the `params` argument.
332332
///
333-
/// # Example
333+
/// ## Example
334334
///
335335
/// ```rust,no_run
336336
/// # use postgres::{PostgresConnection, NoSsl};
@@ -694,7 +694,7 @@ impl PostgresConnection {
694694
/// should be created manually and passed in. Note that Postgres does not
695695
/// support SSL over Unix sockets.
696696
///
697-
/// # Examples
697+
/// ## Examples
698698
///
699699
/// ```rust,no_run
700700
/// # use postgres::{PostgresConnection, NoSsl};
@@ -759,7 +759,7 @@ impl PostgresConnection {
759759
/// The statement is associated with the connection that created it and may
760760
/// not outlive that connection.
761761
///
762-
/// # Example
762+
/// ## Example
763763
///
764764
/// ```rust,no_run
765765
/// # use postgres::{PostgresConnection, NoSsl};
@@ -784,11 +784,11 @@ impl PostgresConnection {
784784
/// the connection for the duration of the transaction. The transaction
785785
/// is active until the `PostgresTransaction` object falls out of scope.
786786
///
787-
/// # Note
787+
/// ## Note
788788
/// A transaction will roll back by default. Use the `set_commit` method to
789789
/// set the transaction to commit.
790790
///
791-
/// # Example
791+
/// ## Example
792792
///
793793
/// ```rust,no_run
794794
/// # use postgres::{PostgresConnection, NoSsl};
@@ -837,14 +837,14 @@ impl PostgresConnection {
837837
/// execution of batches of non-dynamic statements - for example, creation
838838
/// of a schema for a fresh database.
839839
///
840-
/// # Warning
840+
/// ## Warning
841841
///
842842
/// Prepared statements should be used for any SQL statement which contains
843843
/// user-specified data, as it provides functionality to safely embed that
844844
/// data in the statment. Do not form statements via string concatenation
845845
/// and feed them into this method.
846846
///
847-
/// # Example
847+
/// ## Example
848848
///
849849
/// ```rust,no_run
850850
/// # use postgres::{PostgresConnection, PostgresResult};
@@ -982,10 +982,11 @@ impl<'conn> PostgresTransaction<'conn> {
982982

983983
/// Like `PostgresConnection::batch_execute`.
984984
pub fn batch_execute(&self, query: &str) -> PostgresResult<()> {
985-
if self.conn.conn.borrow().trans_depth != self.depth {
985+
let mut conn = self.conn.conn.borrow_mut();
986+
if conn.trans_depth != self.depth {
986987
return Err(PgWrongTransaction);
987988
}
988-
self.conn.batch_execute(query)
989+
conn.quick_query(query).map(|_| ())
989990
}
990991

991992
/// Like `PostgresConnection::transaction`.
@@ -1184,7 +1185,7 @@ impl<'conn> PostgresStatement<'conn> {
11841185
///
11851186
/// If the statement does not modify any rows (e.g. SELECT), 0 is returned.
11861187
///
1187-
/// # Example
1188+
/// ## Example
11881189
///
11891190
/// ```rust,no_run
11901191
/// # use postgres::{PostgresConnection, NoSsl};
@@ -1231,7 +1232,7 @@ impl<'conn> PostgresStatement<'conn> {
12311232
/// Executes the prepared statement, returning an iterator over the
12321233
/// resulting rows.
12331234
///
1234-
/// # Example
1235+
/// ## Example
12351236
///
12361237
/// ```rust,no_run
12371238
/// # use postgres::{PostgresConnection, NoSsl};
@@ -1422,12 +1423,12 @@ impl<'stmt> PostgresRow<'stmt> {
14221423
/// A field can be accessed by the name or index of its column, though
14231424
/// access by index is more efficient. Rows are 0-indexed.
14241425
///
1425-
/// # Failure
1426+
/// ## Failure
14261427
///
14271428
/// Fails if the index does not reference a column or the return type is
14281429
/// not compatible with the Postgres type.
14291430
///
1430-
/// # Example
1431+
/// ## Example
14311432
///
14321433
/// ```rust,no_run
14331434
/// # use postgres::{PostgresConnection, NoSsl};

src/lib/pool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl InnerConnectionPool {
2222
///
2323
/// It can be shared across tasks.
2424
///
25-
/// # Example
25+
/// ## Example
2626
///
2727
/// ```rust,no_run
2828
/// # use postgres::NoSsl;

src/lib/types/array.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ pub trait Array<T> {
1919

2020
/// Slices into this array, returning an immutable view of a subarray.
2121
///
22-
/// # Failure
22+
/// ## Failure
2323
///
2424
/// Fails if the array is one-dimensional or the index is out of bounds.
2525
fn slice<'a>(&'a self, idx: int) -> ArraySlice<'a, T>;
2626

2727
/// Retrieves an immutable reference to a value in this array.
2828
///
2929
///
30-
/// # Failure
30+
/// ## Failure
3131
///
3232
/// Fails if the array is multi-dimensional or the index is out of bounds.
3333
fn get<'a>(&'a self, idx: int) -> &'a T;
@@ -37,15 +37,15 @@ pub trait Array<T> {
3737
pub trait MutableArray<T> : Array<T> {
3838
/// Slices into this array, returning a mutable view of a subarray.
3939
///
40-
/// # Failure
40+
/// ## Failure
4141
///
4242
/// Fails if the array is one-dimensional or the index is out of bounds.
4343
fn slice_mut<'a>(&'a mut self, idx: int) -> MutArraySlice<'a, T>;
4444

4545
/// Retrieves a mutable reference to a value in this array.
4646
///
4747
///
48-
/// # Failure
48+
/// ## Failure
4949
///
5050
/// Fails if the array is multi-dimensional or the index is out of bounds.
5151
fn get_mut<'a>(&'a mut self, idx: int) -> &'a mut T;
@@ -82,7 +82,7 @@ impl<T> ArrayBase<T> {
8282
/// The data array should be provided in the higher-dimensional equivalent
8383
/// of row-major order.
8484
///
85-
/// # Failure
85+
/// ## Failure
8686
///
8787
/// Fails if there are 0 dimensions or the number of elements provided does
8888
/// not match the number of elements specified.
@@ -129,7 +129,7 @@ impl<T> ArrayBase<T> {
129129
/// For example, if `[3,4]` is pushed onto `[[1,2]]`, the result is
130130
/// `[[1,2],[3,4]]`.
131131
///
132-
/// # Failure
132+
/// ## Failure
133133
///
134134
/// Fails if the other array does not have dimensions identical to the
135135
/// dimensions of a slice of this array.

src/lib/types/range.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use time::Timespec;
99
/// The `quote!` macro can make it easier to create ranges. It roughly mirrors
1010
/// traditional mathematic range syntax.
1111
///
12-
/// # Example
12+
/// ## Example
1313
///
1414
/// ```rust
1515
/// #[feature(phase)];

src/test/test.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,20 @@ fn test_batch_execute_error() {
355355
}
356356
}
357357

358+
#[test]
359+
fn test_transaction_batch_execute() {
360+
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
361+
let trans = or_fail!(conn.transaction());
362+
let query = "CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY);
363+
INSERT INTO foo (id) VALUES (10);";
364+
or_fail!(trans.batch_execute(query));
365+
366+
let stmt = or_fail!(trans.prepare("SELECT * from foo ORDER BY id"));
367+
let result = or_fail!(stmt.query([]));
368+
369+
assert_eq!(vec![10i64], result.map(|row| row.get(0u)).collect());
370+
}
371+
358372
#[test]
359373
fn test_query() {
360374
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));

0 commit comments

Comments
 (0)