Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Expose type modifier in Column struct#1141

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
SergeiPatiakin wants to merge5 commits intorust-postgres:masterfromSergeiPatiakin:feat/type-modifier
Closed
Show file tree
Hide file tree
Changes fromall 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 deletionstokio-postgres/src/prepare.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -99,6 +99,7 @@ pub async fn prepare(
name: field.name().to_string(),
table_oid: Some(field.table_oid()).filter(|n| *n != 0),
column_id: Some(field.column_id()).filter(|n| *n != 0),
type_modifier: field.type_modifier(),
r#type: type_,
};
columns.push(column);
Expand Down
6 changes: 6 additions & 0 deletionstokio-postgres/src/statement.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -67,6 +67,7 @@ pub struct Column {
pub(crate) name: String,
pub(crate) table_oid: Option<u32>,
pub(crate) column_id: Option<i16>,
pub(crate) type_modifier: i32,
pub(crate) r#type: Type,
}

Expand All@@ -86,6 +87,11 @@ impl Column {
self.column_id
}

/// Return the type modifier
pub fn type_modifier(&self) -> i32 {
self.type_modifier
}

/// Returns the type of the column.
pub fn type_(&self) -> &Type {
&self.r#type
Expand Down
24 changes: 24 additions & 0 deletionstokio-postgres/tests/test/main.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -163,6 +163,30 @@ async fn pipelined_prepare() {
assert_eq!(statement2.columns()[0].type_(), &Type::INT8);
}

#[tokio::test]
async fn prepare_type_modifier() {
let client = connect("user=postgres").await;

let statement = client
.prepare("SELECT $1::BIGINT, $2::VARCHAR(7), $3::VARCHAR(101)")
.await
.unwrap();

let varlena_header_length = 4;
assert_eq!(statement.columns()[0].type_(), &Type::INT8);
assert_eq!(statement.columns()[0].type_modifier(), -1);
assert_eq!(statement.columns()[1].type_(), &Type::VARCHAR);
assert_eq!(
statement.columns()[1].type_modifier(),
7 + varlena_header_length
);
assert_eq!(statement.columns()[2].type_(), &Type::VARCHAR);
assert_eq!(
statement.columns()[2].type_modifier(),
101 + varlena_header_length
);
}

#[tokio::test]
async fn insert_select() {
let client = connect("user=postgres").await;
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp