Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sqlx-core/src/postgres/connection/establish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ impl PgConnection {
cache_type_oid: HashMap::new(),
cache_type_info: HashMap::new(),
log_settings: options.log_settings.clone(),
override_row_limit: options.override_row_limit,
})
}
}
6 changes: 5 additions & 1 deletion sqlx-core/src/postgres/connection/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,11 @@ impl PgConnection {
// the protocol-level limit acts nearly identically to the `LIMIT` in SQL
self.stream.write(message::Execute {
portal: None,
limit: limit.into(),
limit: if self.override_row_limit {
0
} else {
limit.into()
},
});

// finally, [Sync] asks postgres to process the messages that we sent and respond with
Expand Down
2 changes: 2 additions & 0 deletions sqlx-core/src/postgres/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ pub struct PgConnection {
pub(crate) transaction_depth: usize,

log_settings: LogSettings,

override_row_limit: bool,
}

impl PgConnection {
Expand Down
13 changes: 13 additions & 0 deletions sqlx-core/src/postgres/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub struct PgConnectOptions {
pub(crate) statement_cache_capacity: usize,
pub(crate) application_name: Option<String>,
pub(crate) log_settings: LogSettings,
pub(crate) override_row_limit: bool,
}

impl Default for PgConnectOptions {
Expand Down Expand Up @@ -138,6 +139,7 @@ impl PgConnectOptions {
statement_cache_capacity: 100,
application_name: var("PGAPPNAME").ok(),
log_settings: Default::default(),
override_row_limit: false,
}
}

Expand Down Expand Up @@ -296,6 +298,17 @@ impl PgConnectOptions {
self
}

/// Request all rows from the backend when calling `fetch_one` and
/// `fetch_optional`. This is a workaround for a issue in which
/// CockroachDB reports that sqlx is using multiple portals.
/// See https://github.com/launchbadge/sqlx/issues/933 anad
/// https://github.com/cockroachdb/cockroach/issues/40195?version=v20.1 for
/// more details.
pub fn override_row_limit(&mut self, override_row_limit: bool) -> &mut Self {
self.override_row_limit = override_row_limit;
self
}

/// We try using a socket if hostname starts with `/` or if socket parameter
/// is specified.
pub(crate) fn fetch_socket(&self) -> Option<String> {
Expand Down