-
-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allowed CStr to be used as SPI commands #1864
Merged
workingjubilee
merged 3 commits into
pgcentralfoundation:develop
from
YohDeadfall:cstr-as-query
Sep 21, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
pgrx-tests/tests/compile-fail/spi-prepare-prepared-statement.rs.ignored
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use pgrx::prelude::*; | ||
|
||
fn main() {} | ||
|
||
#[pg_extern] | ||
pub fn cast_function() { | ||
Spi::connect(|client| { | ||
let stmt = client.prepare(c"SELECT 1", None)?; | ||
|
||
client.prepare(stmt, None); | ||
|
||
Ok(()) | ||
}); | ||
} |
18 changes: 18 additions & 0 deletions
18
pgrx-tests/tests/compile-fail/spi-prepare-prepared-statement.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
error[E0277]: the trait bound `PreparedStatement<'_>: spi::query::PreparableQuery<'_>` is not satisfied | ||
--> tests/compile-fail/spi-prepare-prepared-statement.rs:10:24 | ||
| | ||
10 | client.prepare(stmt, None); | ||
| ------- ^^^^ the trait `spi::query::PreparableQuery<'_>` is not implemented for `PreparedStatement<'_>` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= help: the following other types implement trait `spi::query::PreparableQuery<'conn>`: | ||
&CStr | ||
&CString | ||
&std::string::String | ||
&str | ||
note: required by a bound in `SpiClient::<'conn>::prepare` | ||
--> $WORKSPACE/pgrx/src/spi/client.rs | ||
| | ||
| pub fn prepare<Q: PreparableQuery<'conn>>( | ||
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `SpiClient::<'conn>::prepare` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably seems obvious but can you explain how this distinguishes from Query?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To distinguish from the prepared statements which should not be used by the prepare methods of the SPI client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, not entirely sure what the benefit is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably obvious to you, it's just been ages since I've looked at the Query API and my main dread is it being cemented further, because I would rather it... not exist, tbh. Not in its current form anyway. It's... overly cutesy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem that trait solves is prohibiting
PreparedStatement<'conn>
from being used withprepare
andprepare_mut
methods of theSqlClient<'conn>
, so the following code will result in a compiler error:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I played with the CI and observed that my UI test fails only for PostgreSQL versions 12, 13 and 14, but not for others. That's totally weird. See #1870.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...huh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...oh, I remember. They introduced a type named String in PostgreSQL. Can you defer the test to opening an issue instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one, right? https://doxygen.postgresql.org/structString.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.