Skip to content

Commit

Permalink
Add public column metadata to Cursor (#34)
Browse files Browse the repository at this point in the history
* feat: make column metadata public

* test: check column names

* test: don't fatalError on custom types

* test: add integration test protocol (prepare for swift testing :))

* test: fix teardown on skipped test

* test: minor addjustment

* chore: bump dependencies

* fix: adapt to latest dependency changes

* test: fix assertion
  • Loading branch information
lovetodream authored Jun 19, 2024
1 parent 94de1ac commit 90e89e8
Show file tree
Hide file tree
Showing 25 changed files with 709 additions and 433 deletions.
36 changes: 18 additions & 18 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/postgres-nio.git",
"state" : {
"revision" : "ee669e9de721086d2dd8eef83a3a3ddda6904ec2",
"version" : "1.21.4"
"revision" : "5c268768890b062803a49f1358becc478f954265",
"version" : "1.21.5"
}
},
{
"identity" : "swift-async-algorithms",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-async-algorithms.git",
"state" : {
"revision" : "da4e36f86544cdf733a40d59b3a2267e3a7bbf36",
"version" : "1.0.0"
"revision" : "6ae9a051f76b81cc668305ceed5b0e0a7fd93d20",
"version" : "1.0.1"
}
},
{
Expand All @@ -32,17 +32,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb",
"version" : "1.1.0"
"revision" : "ee97538f5b81ae89698fd95938896dec5217b148",
"version" : "1.1.1"
}
},
{
"identity" : "swift-crypto",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-crypto.git",
"state" : {
"revision" : "cc76b894169a3c86b71bac10c78a4db6beb7a9ad",
"version" : "3.2.0"
"revision" : "bc1c29221f6dfeb0ebbfbc98eb95cd3d4967868e",
"version" : "3.4.0"
}
},
{
Expand All @@ -68,44 +68,44 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "fc63f0cf4e55a4597407a9fc95b16a2bc44b4982",
"version" : "2.64.0"
"revision" : "e5a216ba89deba84356bad9d4c2eab99071c745b",
"version" : "2.67.0"
}
},
{
"identity" : "swift-nio-ssl",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-ssl.git",
"state" : {
"revision" : "7c381eb6083542b124a6c18fae742f55001dc2b5",
"version" : "2.26.0"
"revision" : "2b09805797f21c380f7dc9bedaab3157c5508efb",
"version" : "2.27.0"
}
},
{
"identity" : "swift-nio-transport-services",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-transport-services.git",
"state" : {
"revision" : "6cbe0ed2b394f21ab0d46b9f0c50c6be964968ce",
"version" : "1.20.1"
"revision" : "38ac8221dd20674682148d6451367f89c2652980",
"version" : "1.21.0"
}
},
{
"identity" : "swift-service-lifecycle",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swift-server/swift-service-lifecycle.git",
"state" : {
"revision" : "d7fe0e731499a8dcce53bf4cbbc812c8e565d3a7",
"version" : "2.4.1"
"revision" : "d58e6bf2b1ae2884cf204a8b5bcaaa7aae3c1ff0",
"version" : "2.6.0"
}
},
{
"identity" : "swift-system",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-system.git",
"state" : {
"revision" : "025bcb1165deab2e20d4eaba79967ce73013f496",
"version" : "1.2.1"
"revision" : "f9266c85189c2751589a50ea5aec72799797e471",
"version" : "1.3.0"
}
}
],
Expand Down
14 changes: 7 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ let package = Package(
)
],
dependencies: [
.package(url: "https://github.com/apple/swift-log.git", from: "1.4.4"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.58.0"),
.package(url: "https://github.com/apple/swift-nio-transport-services.git", from: "1.19.0"),
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.25.0"),
.package(url: "https://github.com/apple/swift-crypto.git", from: "3.2.0"),
.package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.4.1"),
.package(url: "https://github.com/vapor/postgres-nio.git", from: "1.21.4"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.67.0"),
.package(url: "https://github.com/apple/swift-nio-transport-services.git", from: "1.21.0"),
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.27.0"),
.package(url: "https://github.com/apple/swift-crypto.git", from: "3.4.0"),
.package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.6.0"),
.package(url: "https://github.com/vapor/postgres-nio.git", from: "1.21.5"),
],
targets: [
.target(name: "_PBKDF2", dependencies: [.product(name: "Crypto", package: "swift-crypto")]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct ExtendedQueryStateMachine {
)
/// Indicates that the current query was cancelled and we want to drain rows from the
/// connection ASAP.
case drain([DescribeInfo.Column])
case drain([OracleColumn])

case commandComplete
case error(OracleSQLError)
Expand Down Expand Up @@ -1095,7 +1095,7 @@ struct ExtendedQueryStateMachine {
case .json:
// TODO: OSON
// OSON has a UB4 length indicator instead of the usual UInt8
fatalError("not implemented")
fatalError("OSON is not yet implemented, will be added in the future")
case .vector:
let length = try buffer.throwingReadUB4()
if length > 0 {
Expand All @@ -1111,8 +1111,35 @@ struct ExtendedQueryStateMachine {
} else {
columnValue = .init(bytes: [0]) // empty buffer
}
case .intNamed:
let startIndex = buffer.readerIndex
if try buffer.throwingReadUB4() > 0 {
buffer.skipRawBytesChunked() // type oid
}
if try buffer.throwingReadUB4() > 0 {
buffer.skipRawBytesChunked() // oid
}
if try buffer.throwingReadUB4() > 0 {
buffer.skipRawBytesChunked() // snapshot
}
buffer.skipUB2() // version
let dataLength = try buffer.throwingReadUB4()
buffer.skipUB2() // flags
if dataLength > 0 {
buffer.skipRawBytesChunked() // data
}
let endIndex = buffer.readerIndex
buffer.moveReaderIndex(to: startIndex)
columnValue = ByteBuffer(integer: Constants.TNS_LONG_LENGTH_INDICATOR)
let length = (endIndex - startIndex) + (MemoryLayout<UInt32>.size * 2)
columnValue.reserveCapacity(minimumWritableBytes: length)
try columnValue.writeLengthPrefixed(as: UInt32.self) {
$0.writeImmutableBuffer(buffer.readSlice(length: endIndex - startIndex)!)
}
columnValue.writeInteger(0, as: UInt32.self) // chunk length of zero
default:
fatalError("not implemented")
fatalError(
"\(String(reflecting: oracleType)) is not implemented, please file a bug report")
}

if [.long, .longRAW].contains(oracleType) {
Expand Down
2 changes: 2 additions & 0 deletions Sources/OracleNIO/Data/Cursor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import NIOCore
/// The cursor can be executed once to receive it's results.
public struct Cursor {
public let id: UInt16
public var columns: [OracleColumn] { self.describeInfo.columns }

let isQuery: Bool
let describeInfo: DescribeInfo

Expand Down
2 changes: 2 additions & 0 deletions Sources/OracleNIO/Documentation.docc/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Oracle Database 12.1 or later.
- ``AuthenticationMode``
- ``OracleAccessToken``
- ``OracleServiceMethod``
- ``OracleVersion``

### Querying

Expand All @@ -44,6 +45,7 @@ Oracle Database 12.1 or later.
- ``OracleRowSequence``
- ``OracleRandomAccessRow``
- ``OracleCell``
- ``OracleColumn``
- ``QueryOptions``

### Encoding and Decoding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
import struct NIOCore.ByteBuffer

extension ByteBuffer {
mutating func readString(with charset: Int) throws -> String? {
mutating func readString(
with charset: Int = Constants.TNS_CS_IMPLICIT
) throws -> String {
checkPreconditions(charset: charset)
var stringSlice = try self.readOracleSpecificLengthPrefixedSlice()
return stringSlice.readString(length: stringSlice.readableBytes)
return stringSlice.readString(length: stringSlice.readableBytes)! // must work
}

private func checkPreconditions(charset: Int) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/OracleNIO/Helper/Crypto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func getDerivedKey(key: Data, salt: [UInt8], length: Int, iterations: Int) throw
/// encoding.
func getSignature(key: String, payload: String) throws -> String {
let payload = Array(payload.utf8)
return try _RSA.Signing.PrivateKey(pemRepresentation: key)
return try _RSA.Signing.PrivateKey(unsafePEMRepresentation: key)
.signature(for: payload, padding: .insecurePKCS1v1_5)
.rawRepresentation
.base64EncodedString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ private protocol ColumnMetadata {

extension OracleBindings.Metadata: ColumnMetadata {}

extension DescribeInfo.Column: ColumnMetadata {
extension OracleColumn: ColumnMetadata {
var isArray: Bool { false }
var maxArraySize: Int { 0 }
}
Expand Down
Loading

0 comments on commit 90e89e8

Please sign in to comment.