Fix transaction batch_execute
This commit is contained in:
parent
d094aa615b
commit
c6333f09a4
@ -300,7 +300,7 @@ pub struct PostgresNotifications<'conn> {
|
||||
impl<'conn> Iterator<PostgresNotification> for PostgresNotifications<'conn> {
|
||||
/// Returns the oldest pending notification or `None` if there are none.
|
||||
///
|
||||
/// # Note
|
||||
/// ## Note
|
||||
///
|
||||
/// `next` may return `Some` notification after returning `None` if a new
|
||||
/// notification was received.
|
||||
@ -330,7 +330,7 @@ pub struct PostgresCancelData {
|
||||
/// Only the host and port of the connetion info are used. See
|
||||
/// `PostgresConnection::connect` for details of the `params` argument.
|
||||
///
|
||||
/// # Example
|
||||
/// ## Example
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # use postgres::{PostgresConnection, NoSsl};
|
||||
@ -694,7 +694,7 @@ impl PostgresConnection {
|
||||
/// should be created manually and passed in. Note that Postgres does not
|
||||
/// support SSL over Unix sockets.
|
||||
///
|
||||
/// # Examples
|
||||
/// ## Examples
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # use postgres::{PostgresConnection, NoSsl};
|
||||
@ -759,7 +759,7 @@ impl PostgresConnection {
|
||||
/// The statement is associated with the connection that created it and may
|
||||
/// not outlive that connection.
|
||||
///
|
||||
/// # Example
|
||||
/// ## Example
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # use postgres::{PostgresConnection, NoSsl};
|
||||
@ -784,11 +784,11 @@ impl PostgresConnection {
|
||||
/// the connection for the duration of the transaction. The transaction
|
||||
/// is active until the `PostgresTransaction` object falls out of scope.
|
||||
///
|
||||
/// # Note
|
||||
/// ## Note
|
||||
/// A transaction will roll back by default. Use the `set_commit` method to
|
||||
/// set the transaction to commit.
|
||||
///
|
||||
/// # Example
|
||||
/// ## Example
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # use postgres::{PostgresConnection, NoSsl};
|
||||
@ -837,14 +837,14 @@ impl PostgresConnection {
|
||||
/// execution of batches of non-dynamic statements - for example, creation
|
||||
/// of a schema for a fresh database.
|
||||
///
|
||||
/// # Warning
|
||||
/// ## Warning
|
||||
///
|
||||
/// Prepared statements should be used for any SQL statement which contains
|
||||
/// user-specified data, as it provides functionality to safely embed that
|
||||
/// data in the statment. Do not form statements via string concatenation
|
||||
/// and feed them into this method.
|
||||
///
|
||||
/// # Example
|
||||
/// ## Example
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # use postgres::{PostgresConnection, PostgresResult};
|
||||
@ -982,10 +982,11 @@ impl<'conn> PostgresTransaction<'conn> {
|
||||
|
||||
/// Like `PostgresConnection::batch_execute`.
|
||||
pub fn batch_execute(&self, query: &str) -> PostgresResult<()> {
|
||||
if self.conn.conn.borrow().trans_depth != self.depth {
|
||||
let mut conn = self.conn.conn.borrow_mut();
|
||||
if conn.trans_depth != self.depth {
|
||||
return Err(PgWrongTransaction);
|
||||
}
|
||||
self.conn.batch_execute(query)
|
||||
conn.quick_query(query).map(|_| ())
|
||||
}
|
||||
|
||||
/// Like `PostgresConnection::transaction`.
|
||||
@ -1184,7 +1185,7 @@ impl<'conn> PostgresStatement<'conn> {
|
||||
///
|
||||
/// If the statement does not modify any rows (e.g. SELECT), 0 is returned.
|
||||
///
|
||||
/// # Example
|
||||
/// ## Example
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # use postgres::{PostgresConnection, NoSsl};
|
||||
@ -1231,7 +1232,7 @@ impl<'conn> PostgresStatement<'conn> {
|
||||
/// Executes the prepared statement, returning an iterator over the
|
||||
/// resulting rows.
|
||||
///
|
||||
/// # Example
|
||||
/// ## Example
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # use postgres::{PostgresConnection, NoSsl};
|
||||
@ -1422,12 +1423,12 @@ impl<'stmt> PostgresRow<'stmt> {
|
||||
/// A field can be accessed by the name or index of its column, though
|
||||
/// access by index is more efficient. Rows are 0-indexed.
|
||||
///
|
||||
/// # Failure
|
||||
/// ## Failure
|
||||
///
|
||||
/// Fails if the index does not reference a column or the return type is
|
||||
/// not compatible with the Postgres type.
|
||||
///
|
||||
/// # Example
|
||||
/// ## Example
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # use postgres::{PostgresConnection, NoSsl};
|
||||
|
@ -22,7 +22,7 @@ impl InnerConnectionPool {
|
||||
///
|
||||
/// It can be shared across tasks.
|
||||
///
|
||||
/// # Example
|
||||
/// ## Example
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # use postgres::NoSsl;
|
||||
|
@ -19,7 +19,7 @@ pub trait Array<T> {
|
||||
|
||||
/// Slices into this array, returning an immutable view of a subarray.
|
||||
///
|
||||
/// # Failure
|
||||
/// ## Failure
|
||||
///
|
||||
/// Fails if the array is one-dimensional or the index is out of bounds.
|
||||
fn slice<'a>(&'a self, idx: int) -> ArraySlice<'a, T>;
|
||||
@ -27,7 +27,7 @@ pub trait Array<T> {
|
||||
/// Retrieves an immutable reference to a value in this array.
|
||||
///
|
||||
///
|
||||
/// # Failure
|
||||
/// ## Failure
|
||||
///
|
||||
/// Fails if the array is multi-dimensional or the index is out of bounds.
|
||||
fn get<'a>(&'a self, idx: int) -> &'a T;
|
||||
@ -37,7 +37,7 @@ pub trait Array<T> {
|
||||
pub trait MutableArray<T> : Array<T> {
|
||||
/// Slices into this array, returning a mutable view of a subarray.
|
||||
///
|
||||
/// # Failure
|
||||
/// ## Failure
|
||||
///
|
||||
/// Fails if the array is one-dimensional or the index is out of bounds.
|
||||
fn slice_mut<'a>(&'a mut self, idx: int) -> MutArraySlice<'a, T>;
|
||||
@ -45,7 +45,7 @@ pub trait MutableArray<T> : Array<T> {
|
||||
/// Retrieves a mutable reference to a value in this array.
|
||||
///
|
||||
///
|
||||
/// # Failure
|
||||
/// ## Failure
|
||||
///
|
||||
/// Fails if the array is multi-dimensional or the index is out of bounds.
|
||||
fn get_mut<'a>(&'a mut self, idx: int) -> &'a mut T;
|
||||
@ -82,7 +82,7 @@ impl<T> ArrayBase<T> {
|
||||
/// The data array should be provided in the higher-dimensional equivalent
|
||||
/// of row-major order.
|
||||
///
|
||||
/// # Failure
|
||||
/// ## Failure
|
||||
///
|
||||
/// Fails if there are 0 dimensions or the number of elements provided does
|
||||
/// not match the number of elements specified.
|
||||
@ -129,7 +129,7 @@ impl<T> ArrayBase<T> {
|
||||
/// For example, if `[3,4]` is pushed onto `[[1,2]]`, the result is
|
||||
/// `[[1,2],[3,4]]`.
|
||||
///
|
||||
/// # Failure
|
||||
/// ## Failure
|
||||
///
|
||||
/// Fails if the other array does not have dimensions identical to the
|
||||
/// dimensions of a slice of this array.
|
||||
|
@ -9,7 +9,7 @@ use time::Timespec;
|
||||
/// The `quote!` macro can make it easier to create ranges. It roughly mirrors
|
||||
/// traditional mathematic range syntax.
|
||||
///
|
||||
/// # Example
|
||||
/// ## Example
|
||||
///
|
||||
/// ```rust
|
||||
/// #[feature(phase)];
|
||||
|
@ -355,6 +355,20 @@ fn test_batch_execute_error() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_transaction_batch_execute() {
|
||||
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
|
||||
let trans = or_fail!(conn.transaction());
|
||||
let query = "CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY);
|
||||
INSERT INTO foo (id) VALUES (10);";
|
||||
or_fail!(trans.batch_execute(query));
|
||||
|
||||
let stmt = or_fail!(trans.prepare("SELECT * from foo ORDER BY id"));
|
||||
let result = or_fail!(stmt.query([]));
|
||||
|
||||
assert_eq!(vec![10i64], result.map(|row| row.get(0u)).collect());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query() {
|
||||
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
|
||||
|
Loading…
Reference in New Issue
Block a user