Skip to content

Commit

Permalink
fix polling with unixODBC
Browse files Browse the repository at this point in the history
  • Loading branch information
pacman82 committed Oct 3, 2022
1 parent a77ccfa commit 1643384
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 29 deletions.
1 change: 1 addition & 0 deletions odbc-api/src/buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod indicator;
mod item;
mod text_column;

#[allow(deprecated)]
pub use self::{
any_buffer::{
AnyBuffer, AnyColumnBuffer, AnyColumnSliceMut, AnyColumnView, AnySlice, AnySliceMut,
Expand Down
5 changes: 2 additions & 3 deletions odbc-api/src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
error::ExtendResult,
handles::{AsStatementRef, SqlResult, State, Statement, StatementRef},
parameter::{VarBinarySliceMut, VarCharSliceMut},
sleep::{poll_until_completed, Sleep},
sleep::{wait_for, Sleep},
Error, OutputParameter, ResultSetMetadata,
};

Expand Down Expand Up @@ -567,8 +567,7 @@ where
) -> Result<Option<&B>, Error> {
let mut stmt = self.cursor.as_stmt_ref();
unsafe {
let mut result = stmt.fetch();
poll_until_completed(&mut result, "SQLFetch", &mut stmt, &mut sleep).await?;
let result = wait_for(|| stmt.fetch(), &mut sleep).await;
let has_row = error_handling_for_fetch(result, stmt, error_for_truncation)?;
Ok(has_row.then_some(&self.buffer))
}
Expand Down
14 changes: 5 additions & 9 deletions odbc-api/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::intrinsics::transmute;
use crate::{
handles::{AsStatementRef, SqlText, Statement},
parameter::Blob,
sleep::{poll_until_completed, wait_for},
sleep::wait_for,
CursorImpl, CursorPolling, Error, ParameterCollectionRef, Sleep,
};

Expand Down Expand Up @@ -145,16 +145,14 @@ where
S: AsStatementRef,
{
let mut stmt = statement.as_stmt_ref();
let mut result = if let Some(sql) = query {
let result = if let Some(sql) = query {
// We execute an unprepared "one shot query"
stmt.exec_direct(sql)
wait_for(|| stmt.exec_direct(sql), &mut sleep).await
} else {
// We execute a prepared query
stmt.execute()
wait_for(|| stmt.execute(), &mut sleep).await
};

poll_until_completed(&mut result, "execute", &mut stmt, &mut sleep).await?;

// If delayed parameters (e.g. input streams) are bound we might need to put data in order to
// execute.
let need_data =
Expand All @@ -171,9 +169,7 @@ where
let blob_ref = &mut *blob_ptr;
// Loop over all batches within each blob
while let Some(batch) = blob_ref.next_batch().map_err(Error::FailedReadingInput)? {
let mut result = stmt.put_binary_batch(batch);
poll_until_completed(&mut result, "put_binary_batch", &mut stmt, &mut sleep)
.await?;
let result = wait_for(|| stmt.put_binary_batch(batch), &mut sleep).await;
result.into_result(&stmt)?;
}
}
Expand Down
18 changes: 1 addition & 17 deletions odbc-api/src/sleep.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use std::future::Future;

use crate::{
handles::{SqlResult, Statement},
Error,
};
use crate::handles::SqlResult;

/// Governs the behaviour of of polling in async functions.
///
Expand Down Expand Up @@ -41,16 +38,3 @@ where
}
ret
}

pub async fn poll_until_completed(
result: &mut SqlResult<()>,
function_name: &'static str,
stmt: &mut impl Statement,
sleep: &mut impl Sleep,
) -> Result<(), Error> {
while *result == SqlResult::StillExecuting {
sleep.next_poll().await;
*result = stmt.complete_async(function_name).into_result(stmt)?;
}
Ok(())
}

0 comments on commit 1643384

Please sign in to comment.