@@ -129,11 +129,47 @@ function test_pg_int64(t, p)
129
129
p :put (conn )
130
130
end
131
131
132
+ function test_pg_decimal (t , p )
133
+ t :plan (8 )
134
+
135
+ -- Setup
136
+ conn = p :get ()
137
+ t :isnt (conn , nil , ' connection is established' )
138
+ local num = 4500
139
+ conn :execute (' CREATE TABLE dectest (num NUMERIC(7,2))' )
140
+ conn :execute ((' INSERT INTO dectest VALUES(%d)' ):format (num ))
141
+
142
+ local res , r , _
143
+ -- dec_cast is 'n'
144
+ t :is (conn .dec_cast , ' n' , ' decimal casting type is "n" by default' )
145
+ r , _ = conn :execute (' SELECT num FROM dectest' )
146
+ res = r [1 ][1 ][' num' ]
147
+ t :is (type (res ), ' number' , ' type is "number"' )
148
+ t :is (res , num , ' decimal number is correct' )
149
+ -- dec_cast is 's'
150
+ conn .dec_cast = ' s'
151
+ r , _ = conn :execute (' SELECT num FROM dectest' )
152
+ res = r [1 ][1 ][' num' ]
153
+ t :is (type (res ), ' string' , ' type is "string"' )
154
+ t :is (res , ' 4500.00' , ' decimal number is correct' )
155
+ -- dec_cast is 'd'
156
+ conn .dec_cast = ' d'
157
+ r , _ = conn :execute (' SELECT num FROM dectest' )
158
+ res = r [1 ][1 ][' num' ]
159
+ t :is (type (res ), ' cdata' , ' type is "decimal"' )
160
+ t :is (res , num , ' decimal number is correct' )
161
+
162
+ -- Teardown
163
+ conn :execute (' DROP TABLE dectest' )
164
+ p :put (conn )
165
+ end
166
+
132
167
tap .test (' connection old api' , test_old_api , conn )
133
168
local pool_conn = p :get ()
134
169
tap .test (' connection old api via pool' , test_old_api , pool_conn )
135
170
p :put (pool_conn )
136
171
tap .test (' test collection connections' , test_gc , p )
137
172
tap .test (' connection concurrent' , test_conn_concurrent , p )
138
173
tap .test (' int64' , test_pg_int64 , p )
174
+ tap .test (' decimal' , test_pg_decimal , p )
139
175
p :close ()
0 commit comments