Skip to content
Merged
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
13 changes: 6 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Install curl for Codecov
run: apt-get update -y -q && apt-get install -y curl
- name: Check out package
uses: actions/checkout@v5
uses: actions/checkout@v6
- name: Run unit tests with Thread Sanitizer
run: |
swift test --filter='^(PostgresNIOTests|ConnectionPoolModuleTests)' --sanitize=thread --enable-code-coverage
Expand Down Expand Up @@ -92,15 +92,15 @@ jobs:
[[ -z "${SWIFT_VERSION}" ]] && SWIFT_VERSION="$(cat /.swift_tag 2>/dev/null || true)"
printf 'OS: %s\nTag: %s\nVersion:\n' "${SWIFT_PLATFORM}-${RUNNER_ARCH}" "${SWIFT_VERSION}" && swift --version
- name: Check out package
uses: actions/checkout@v5
uses: actions/checkout@v6
with: { path: 'postgres-nio' }
- name: Run integration tests
run: swift test --package-path postgres-nio --filter=^IntegrationTests
- name: Check out postgres-kit dependent
uses: actions/checkout@v5
uses: actions/checkout@v6
with: { repository: 'vapor/postgres-kit', path: 'postgres-kit' }
- name: Check out fluent-postgres-driver dependent
uses: actions/checkout@v5
uses: actions/checkout@v6
with: { repository: 'vapor/fluent-postgres-driver', path: 'fluent-postgres-driver' }
- name: Use local package in dependents
run: |
Expand Down Expand Up @@ -136,7 +136,6 @@ jobs:
POSTGRES_PASSWORD: 'test_password'
POSTGRES_DB: 'postgres'
POSTGRES_AUTH_METHOD: ${{ matrix.postgres-auth }}
POSTGRES_SOCKET: '/tmp/.s.PGSQL.5432'
POSTGRES_FORMULA: ${{ matrix.postgres-formula }}
steps:
- name: Select latest available Xcode
Expand All @@ -151,7 +150,7 @@ jobs:
pg_ctl start --wait
timeout-minutes: 15
- name: Checkout code
uses: actions/checkout@v5
uses: actions/checkout@v6
- name: Run all tests
run: swift test --enable-code-coverage
- name: Submit code coverage
Expand All @@ -165,7 +164,7 @@ jobs:
container: swift:noble
steps:
- name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v6
with:
fetch-depth: 0
# https://github.com/actions/checkout/issues/766
Expand Down
6 changes: 4 additions & 2 deletions Sources/PostgresNIO/Data/PostgresData+Numeric.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import struct Foundation.Decimal
public struct PostgresNumeric: CustomStringConvertible, CustomDebugStringConvertible, ExpressibleByStringLiteral {
/// The number of digits after this metadata
internal var ndigits: Int16
/// How many of the digits are before the decimal point (always add 1)
/// How many positions before or after the deicmal point the value is offset by
internal var weight: Int16
/// If 0x4000, this number is negative. See NUMERIC_NEG in
/// https://github.com/postgres/postgres/blob/master/src/backend/utils/adt/numeric.c
Expand Down Expand Up @@ -159,8 +159,10 @@ public struct PostgresNumeric: CustomStringConvertible, CustomDebugStringConvert
let offset: Int16
if self.weight > 0 {
offset = (self.weight + 1) - self.ndigits
} else if self.weight < 0 {
offset = abs(self.weight + 1)
} else {
offset = abs(self.weight) - self.ndigits
offset = 0
}
if offset > 0 {
for _ in 0..<offset {
Expand Down
32 changes: 30 additions & 2 deletions Tests/IntegrationTests/PostgresNIOTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -619,24 +619,52 @@ final class PostgresNIOTests: XCTestCase {
let b = PostgresNumeric(string: "-123456.789123")!
let c = PostgresNumeric(string: "3.14159265358979")!
let d = PostgresNumeric(string: "1234567898765")!
let e = PostgresNumeric(string: "0.00000080216390553684")!
let f = PostgresNumeric(string: "0.0000080216390553684")!
let g = PostgresNumeric(string: "0.000080216390553684")!
let h = PostgresNumeric(string: "802163905536840000.0")!
let i = PostgresNumeric(string: "8021639055368400000.0")!
let j = PostgresNumeric(string: "80216390553684000000.0")!
let k = PostgresNumeric(string: "802163905536840000.000080216390553684")!
var rows: PostgresQueryResult?
XCTAssertNoThrow(rows = try conn?.query("""
select
$1::numeric as a,
$2::numeric as b,
$3::numeric as c,
$4::numeric as d
$4::numeric as d,
$5::numeric as e,
$6::numeric as f,
$7::numeric as g,
$8::numeric as h,
$9::numeric as i,
$10::numeric as j,
$11::numeric as k
""", [
.init(numeric: a),
.init(numeric: b),
.init(numeric: c),
.init(numeric: d)
.init(numeric: d),
.init(numeric: e),
.init(numeric: f),
.init(numeric: g),
.init(numeric: h),
.init(numeric: i),
.init(numeric: j),
.init(numeric: k)
]).wait())
let row = rows?.first?.makeRandomAccess()
XCTAssertEqual(row?[data: "a"].decimal, Decimal(string: "123456.789123")!)
XCTAssertEqual(row?[data: "b"].decimal, Decimal(string: "-123456.789123")!)
XCTAssertEqual(row?[data: "c"].decimal, Decimal(string: "3.14159265358979")!)
XCTAssertEqual(row?[data: "d"].decimal, Decimal(string: "1234567898765")!)
XCTAssertEqual(row?[data: "e"].decimal, Decimal(string: "0.00000080216390553684")!)
XCTAssertEqual(row?[data: "f"].decimal, Decimal(string: "0.0000080216390553684")!)
XCTAssertEqual(row?[data: "g"].decimal, Decimal(string: "0.000080216390553684")!)
XCTAssertEqual(row?[data: "h"].decimal, Decimal(string: "802163905536840000.0")!)
XCTAssertEqual(row?[data: "i"].decimal, Decimal(string: "8021639055368400000.0")!)
XCTAssertEqual(row?[data: "j"].decimal, Decimal(string: "80216390553684000000.0")!)
XCTAssertEqual(row?[data: "k"].decimal, Decimal(string: "802163905536840000.000080216390553684")!)
}

func testDecimalStringSerialization() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import NIOCore
class Decimal_PSQLCodableTests: XCTestCase {

func testRoundTrip() {
let values: [Decimal] = [1.1, .pi, -5e-12]
let values: [Decimal] = [1.1, .pi, -5e-12, 0.00000080216390553684]

for value in values {
var buffer = ByteBuffer()
Expand Down