From e3b694c7d5e980522185817fca4ae686f0c1664e Mon Sep 17 00:00:00 2001 From: Sergei Patiakin Date: Thu, 16 May 2024 18:39:05 +0200 Subject: [PATCH 1/5] Empty commit From 0f742e4544a654f6e68f36ffd427072e8ebfb0d1 Mon Sep 17 00:00:00 2001 From: Sergei Patiakin Date: Thu, 16 May 2024 18:42:31 +0200 Subject: [PATCH 2/5] Expose type modifier in Column struct --- tokio-postgres/src/prepare.rs | 1 + tokio-postgres/src/statement.rs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/tokio-postgres/src/prepare.rs b/tokio-postgres/src/prepare.rs index 07fb45694..c0596e113 100644 --- a/tokio-postgres/src/prepare.rs +++ b/tokio-postgres/src/prepare.rs @@ -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); diff --git a/tokio-postgres/src/statement.rs b/tokio-postgres/src/statement.rs index c5d657738..ae98691dd 100644 --- a/tokio-postgres/src/statement.rs +++ b/tokio-postgres/src/statement.rs @@ -67,6 +67,7 @@ pub struct Column { pub(crate) name: String, pub(crate) table_oid: Option, pub(crate) column_id: Option, + pub(crate) type_modifier: i32, pub(crate) r#type: Type, } @@ -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 From 66cb5da8256714ad5087bec172910e431310c574 Mon Sep 17 00:00:00 2001 From: Sergei Patiakin Date: Thu, 16 May 2024 18:49:48 +0200 Subject: [PATCH 3/5] Unit test --- tokio-postgres/tests/test/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tokio-postgres/tests/test/main.rs b/tokio-postgres/tests/test/main.rs index 737f46631..2dca4b74a 100644 --- a/tokio-postgres/tests/test/main.rs +++ b/tokio-postgres/tests/test/main.rs @@ -161,6 +161,7 @@ async fn pipelined_prepare() { assert_eq!(statement2.params()[0], Type::INT8); assert_eq!(statement2.columns()[0].type_(), &Type::INT8); + assert_eq!(statement2.columns()[0].type_modifier(), -1); } #[tokio::test] From f8ac135951030b50969b4462eb551b3661a99af2 Mon Sep 17 00:00:00 2001 From: Sergei Patiakin Date: Thu, 16 May 2024 18:54:54 +0200 Subject: [PATCH 4/5] Separate unit test --- tokio-postgres/tests/test/main.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tokio-postgres/tests/test/main.rs b/tokio-postgres/tests/test/main.rs index 2dca4b74a..3fbc655b5 100644 --- a/tokio-postgres/tests/test/main.rs +++ b/tokio-postgres/tests/test/main.rs @@ -161,7 +161,23 @@ async fn pipelined_prepare() { assert_eq!(statement2.params()[0], Type::INT8); assert_eq!(statement2.columns()[0].type_(), &Type::INT8); - assert_eq!(statement2.columns()[0].type_modifier(), -1); +} + +#[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(); + + 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); + assert_eq!(statement.columns()[2].type_(), &Type::VARCHAR); + assert_eq!(statement.columns()[2].type_modifier(), 101); } #[tokio::test] From 88c2c7714a4558aed6a63e2e2b140a8359568858 Mon Sep 17 00:00:00 2001 From: Sergei Patiakin Date: Thu, 16 May 2024 19:02:06 +0200 Subject: [PATCH 5/5] Fix expected values --- tokio-postgres/tests/test/main.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tokio-postgres/tests/test/main.rs b/tokio-postgres/tests/test/main.rs index 3fbc655b5..8841b657f 100644 --- a/tokio-postgres/tests/test/main.rs +++ b/tokio-postgres/tests/test/main.rs @@ -172,12 +172,19 @@ async fn prepare_type_modifier() { .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); + 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); + assert_eq!( + statement.columns()[2].type_modifier(), + 101 + varlena_header_length + ); } #[tokio::test]