Mercurial > hg > monetdb-perl
comparison DBD/t/26hge.t @ 28:e3e0159771c7
Test HUGEINT and DECIMAL(38,_)
author | Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com> |
---|---|
date | Thu, 17 Dec 2020 09:24:37 +0100 (2020-12-17) |
parents | |
children |
comparison
equal
deleted
inserted
replaced
27:536255410444 | 28:e3e0159771c7 |
---|---|
1 #!perl -I./t | |
2 | |
3 # This Source Code Form is subject to the terms of the Mozilla Public | |
4 # License, v. 2.0. If a copy of the MPL was not distributed with this | |
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
6 # | |
7 # Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V. | |
8 | |
9 $| = 1; | |
10 | |
11 use strict; | |
12 use warnings; | |
13 use DBI(); | |
14 use DBD_TEST(); | |
15 | |
16 use Test::More; | |
17 | |
18 if ( !defined $ENV{DBI_DSN} ) { | |
19 plan skip_all => 'Cannot test without DB info'; | |
20 } | |
21 | |
22 | |
23 my $dbh = DBI->connect or die "Connect failed: $DBI::errstr\n"; | |
24 $dbh->{RaiseError} = 1; | |
25 $dbh->{PrintError} = 0; | |
26 | |
27 my $chk128 = $dbh->prepare("SELECT * FROM sys.types WHERE systemname = 'hge'"); | |
28 $chk128->execute; | |
29 my $hgetypes = $chk128->fetchall_arrayref; | |
30 if (@{$hgetypes}) { | |
31 plan tests => 11; | |
32 } else { | |
33 plan skip_all => "no hge support"; | |
34 } | |
35 | |
36 ok($dbh->do('DROP TABLE IF EXISTS perl_dec38;'), 'DROP TABLE'); | |
37 ok($dbh->do(qq{ | |
38 CREATE TABLE perl_dec38 ( | |
39 h HUGEINT, | |
40 d38_0 DECIMAL(38,0), | |
41 d38_19 DECIMAL(38,19), | |
42 d38_38 DECIMAL(38,38) | |
43 );}), | |
44 'CREATE TABLE'); | |
45 ok($dbh->do(qq{INSERT INTO perl_dec38 VALUES ( | |
46 12345678901234567899876543210987654321, | |
47 12345678901234567899876543210987654321, | |
48 1234567890123456789.9876543210987654321, | |
49 .12345678901234567899876543210987654321 | |
50 );}), | |
51 'INSERT'); | |
52 | |
53 | |
54 my ($hge, $s0, $s19, $s38) = $dbh->selectrow_array(qq{ | |
55 SELECT | |
56 h, | |
57 CAST(d38_0 AS TEXT) AS s0, | |
58 CAST(d38_19 AS TEXT) AS s19, | |
59 CAST(d38_38 AS TEXT) AS s38 | |
60 FROM perl_dec38;}); | |
61 is("$hge", '12345678901234567899876543210987654321', 'selectrow_array huge 12345678901234567899876543210987654321'); | |
62 is("$s0", '12345678901234567899876543210987654321', 'selectrow_array dec 12345678901234567899876543210987654321'); | |
63 is("$s19", '1234567890123456789.9876543210987654321', 'selectrow_array dec 1234567890123456789.9876543210987654321'); | |
64 is("$s38", '0.12345678901234567899876543210987654321', 'selectrow_array dec 0.12345678901234567899876543210987654321'); | |
65 | |
66 | |
67 | |
68 | |
69 my $rowref = $dbh->selectrow_arrayref(qq{ | |
70 SELECT | |
71 h, | |
72 CAST(d38_0 AS TEXT) AS s0, | |
73 CAST(d38_19 AS TEXT) AS s19, | |
74 CAST(d38_38 AS TEXT) AS s38 | |
75 FROM perl_dec38;}); | |
76 is("$rowref->[0]", '12345678901234567899876543210987654321', 'selectrow_array huge 12345678901234567899876543210987654321'); | |
77 is("$rowref->[1]", '12345678901234567899876543210987654321', 'selectrow_array dec 12345678901234567899876543210987654321'); | |
78 is("$rowref->[2]", '1234567890123456789.9876543210987654321', 'selectrow_array dec 1234567890123456789.9876543210987654321'); | |
79 is("$rowref->[3]", '0.12345678901234567899876543210987654321', 'selectrow_array dec 0.12345678901234567899876543210987654321'); | |
80 | |
81 |