@@ -21,111 +21,108 @@ class PostgreSQLConnectionTests: XCTestCase {
21
21
XCTFail ( " Results count not large enough: \( results. count) " )
22
22
}
23
23
}
24
- //
25
- // func testParse() throws {
26
- // let (client, eventLoop) = try PostgreSQLConnection.makeTest()
27
- // let query = """
28
- // select * from "pg_type" where "typlen" = $1 or "typlen" = $2
29
- // """
30
- // let rows = try client.query(query, [
31
- // .int32(1),
32
- // .int32(2),
33
- // ]).await(on: eventLoop)
34
- //
35
- // for row in rows {
36
- // XCTAssert(row["typlen"]?.int == 1 || row["typlen"]?.int == 2)
37
- // }
38
- // }
39
- //
40
- // func testTypes() throws {
41
- // let (client, eventLoop) = try PostgreSQLConnection.makeTest()
42
- // let createQuery = """
43
- // create table kitchen_sink (
44
- // "smallint" smallint,
45
- // "integer" integer,
46
- // "bigint" bigint,
47
- // "decimal" decimal,
48
- // "numeric" numeric,
49
- // "real" real,
50
- // "double" double precision,
51
- // "varchar" varchar(64),
52
- // "char" char(4),
53
- // "text" text,
54
- // "bytea" bytea,
55
- // "timestamp" timestamp,
56
- // "date" date,
57
- // "time" time,
58
- // "boolean" boolean,
59
- // "point" point
60
- // -- "line" line,
61
- // -- "lseg" lseg,
62
- // -- "box" box,
63
- // -- "path" path,
64
- // -- "polygon" polygon,
65
- // -- "circle" circle,
66
- // -- "cidr" cidr,
67
- // -- "inet" inet,
68
- // -- "macaddr" macaddr,
69
- // -- "bit" bit(16),
70
- // -- "uuid" uuid
71
- // );
72
- // """
73
- // _ = try client.query("drop table if exists kitchen_sink;").await(on: eventLoop)
74
- // let createResult = try client.query(createQuery).await(on: eventLoop)
75
- // XCTAssertEqual(createResult.count, 0)
76
- //
77
- // let insertQuery = """
78
- // insert into kitchen_sink values (
79
- // 1, -- "smallint" smallint
80
- // 2, -- "integer" integer
81
- // 3, -- "bigint" bigint
82
- // 4, -- "decimal" decimal
83
- // 5.3, -- "numeric" numeric
84
- // 6, -- "real" real
85
- // 7, -- "double" double precision
86
- // '9', -- "varchar" varchar(64)
87
- // '10', -- "char" char(4)
88
- // '11', -- "text" text
89
- // '12', -- "bytea" bytea
90
- // now(), -- "timestamp" timestamp
91
- // current_date, -- "date" date
92
- // localtime, -- "time" time
93
- // true, -- "boolean" boolean
94
- // point(13.5,14) -- "point" point,
95
- // -- "line" line,
96
- // -- "lseg" lseg,
97
- // -- "box" box,
98
- // -- "path" path,
99
- // -- "polygon" polygon,
100
- // -- "circle" circle,
101
- // -- "cidr" cidr,
102
- // -- "inet" inet,
103
- // -- "macaddr" macaddr,
104
- // -- "bit" bit(16),
105
- // -- "uuid" uuid
106
- // );
107
- // """
108
- // let insertResult = try! client.query(insertQuery).await(on: eventLoop)
109
- // XCTAssertEqual(insertResult.count, 0)
110
- // let queryResult = try client.query("select * from kitchen_sink").await(on: eventLoop)
111
- // if queryResult.count == 1 {
112
- // let row = queryResult[0]
113
- // XCTAssertEqual(row["smallint"], .int16(1))
114
- // XCTAssertEqual(row["integer"], .int32(2))
115
- // XCTAssertEqual(row["bigint"], .int64(3))
116
- // XCTAssertEqual(row["decimal"], .string("4"))
117
- // XCTAssertEqual(row["real"], .float(6))
118
- // XCTAssertEqual(row["double"], .double(7))
119
- // XCTAssertEqual(row["varchar"], .string("9"))
120
- // XCTAssertEqual(row["char"], .string("10 "))
121
- // XCTAssertEqual(row["text"], .string("11"))
122
- // XCTAssertEqual(row["bytea"], .data(Data([0x31, 0x32])))
123
- // XCTAssertEqual(row["boolean"], .int8(0x01))
124
- // XCTAssertEqual(row["point"], .point(x: 13.5, y: 14))
125
- // } else {
126
- // XCTFail("query result count is: \(queryResult.count)")
127
- // }
128
- // }
24
+
25
+ func testParse( ) throws {
26
+ let ( client, eventLoop) = try PostgreSQLConnection . makeTest ( )
27
+ let query = """
28
+ select * from " pg_type " where " typlen " = $1 or " typlen " = $2
29
+ """
30
+ let rows = try client. query ( query, [ 1 , 2 ] ) . await ( on: eventLoop)
31
+
32
+ for row in rows {
33
+ try XCTAssert ( row [ " typlen " ] ? . decode ( Int . self) == 1 || row [ " typlen " ] ? . decode ( Int . self) == 2 )
34
+ }
35
+ }
36
+
37
+ func testTypes( ) throws {
38
+ let ( client, eventLoop) = try PostgreSQLConnection . makeTest ( )
39
+ let createQuery = """
40
+ create table kitchen_sink (
41
+ " smallint " smallint,
42
+ " integer " integer,
43
+ " bigint " bigint,
44
+ " decimal " decimal,
45
+ " numeric " numeric,
46
+ " real " real,
47
+ " double " double precision,
48
+ " varchar " varchar(64),
49
+ " char " char(4),
50
+ " text " text,
51
+ " bytea " bytea,
52
+ " timestamp " timestamp,
53
+ " date " date,
54
+ " time " time,
55
+ " boolean " boolean,
56
+ " point " point
57
+ -- " line " line,
58
+ -- " lseg " lseg,
59
+ -- " box " box,
60
+ -- " path " path,
61
+ -- " polygon " polygon,
62
+ -- " circle " circle,
63
+ -- " cidr " cidr,
64
+ -- " inet " inet,
65
+ -- " macaddr " macaddr,
66
+ -- " bit " bit(16),
67
+ -- " uuid " uuid
68
+ );
69
+ """
70
+ _ = try client. query ( " drop table if exists kitchen_sink; " ) . await ( on: eventLoop)
71
+ let createResult = try client. query ( createQuery) . await ( on: eventLoop)
72
+ XCTAssertEqual ( createResult. count, 0 )
73
+
74
+ let insertQuery = """
75
+ insert into kitchen_sink values (
76
+ 1, -- " smallint " smallint
77
+ 2, -- " integer " integer
78
+ 3, -- " bigint " bigint
79
+ 4, -- " decimal " decimal
80
+ 5.3, -- " numeric " numeric
81
+ 6, -- " real " real
82
+ 7, -- " double " double precision
83
+ '9', -- " varchar " varchar(64)
84
+ '10', -- " char " char(4)
85
+ '11', -- " text " text
86
+ '12', -- " bytea " bytea
87
+ now(), -- " timestamp " timestamp
88
+ current_date, -- " date " date
89
+ localtime, -- " time " time
90
+ true, -- " boolean " boolean
91
+ point(13.5,14) -- " point " point,
92
+ -- " line " line,
93
+ -- " lseg " lseg,
94
+ -- " box " box,
95
+ -- " path " path,
96
+ -- " polygon " polygon,
97
+ -- " circle " circle,
98
+ -- " cidr " cidr,
99
+ -- " inet " inet,
100
+ -- " macaddr " macaddr,
101
+ -- " bit " bit(16),
102
+ -- " uuid " uuid
103
+ );
104
+ """
105
+ let insertResult = try ! client. query ( insertQuery) . await ( on: eventLoop)
106
+ XCTAssertEqual ( insertResult. count, 0 )
107
+ let queryResult = try client. query ( " select * from kitchen_sink " ) . await ( on: eventLoop)
108
+ if queryResult. count == 1 {
109
+ let row = queryResult [ 0 ]
110
+ try XCTAssertEqual ( row [ " smallint " ] ? . decode ( Int16 . self) , 1 )
111
+ try XCTAssertEqual ( row [ " integer " ] ? . decode ( Int32 . self) , 2 )
112
+ try XCTAssertEqual ( row [ " bigint " ] ? . decode ( Int64 . self) , 3 )
113
+ try XCTAssertEqual ( row [ " decimal " ] ? . decode ( String . self) , " 4 " )
114
+ try XCTAssertEqual ( row [ " real " ] ? . decode ( Float . self) , 6 )
115
+ try XCTAssertEqual ( row [ " double " ] ? . decode ( Double . self) , 7 )
116
+ try XCTAssertEqual ( row [ " varchar " ] ? . decode ( String . self) , " 9 " )
117
+ try XCTAssertEqual ( row [ " char " ] ? . decode ( String . self) , " 10 " )
118
+ try XCTAssertEqual ( row [ " text " ] ? . decode ( String . self) , " 11 " )
119
+ try XCTAssertEqual ( row [ " bytea " ] ? . decode ( Data . self) , Data ( [ 0x31 , 0x32 ] ) )
120
+ try XCTAssertEqual ( row [ " boolean " ] ? . decode ( Bool . self) , true )
121
+ // try XCTAssertEqual(row["point"]?.decode(Int16.self), .point(x: 13.5, y: 14)) // FIXME: decode point?
122
+ } else {
123
+ XCTFail ( " query result count is: \( queryResult. count) " )
124
+ }
125
+ }
129
126
//
130
127
// func testParameterizedTypes() throws {
131
128
// let (client, eventLoop) = try PostgreSQLConnection.makeTest()
0 commit comments