comparison DBD/t/12ins_q.t @ 0:cedccb7e0143

Copy of clients/perl directory without Tests from MonetDB changeset 4d2d4532228a.
author Sjoerd Mullender <sjoerd@acm.org>
date Mon, 19 Sep 2016 15:15:52 +0200 (2016-09-19)
parents
children a0ec9e080a5b
comparison
equal deleted inserted replaced
-1:000000000000 0:cedccb7e0143
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 - 2016 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 my $tbl = $DBD_TEST::table_name;
19 my @col = sort keys %DBD_TEST::TestFieldInfo;
20 my $dat = [
21 [ 1,'A123' ,'A' x 12,'1998-05-13']
22 , [ 2,'B12' ,'B' x 2,'1998-05-14']
23 , [ 3,'C1234' ,'C' x 22,'1998-05-15']
24 , [ 4,'D12345','D' x 32,'1998-05-16']
25 ];
26 if ( defined $ENV{DBI_DSN} ) {
27 plan tests => 4 + ( 2 + 2 * @$dat ) * @col;
28 } else {
29 plan skip_all => 'Cannot test without DB info';
30 }
31
32 pass('Insert tests (quoted literals)');
33
34 my $dbh = DBI->connect or die "Connect failed: $DBI::errstr\n";
35 $dbh->{RaiseError} = 1;
36 $dbh->{PrintError} = 0;
37 $dbh->{ChopBlanks} = 1;
38 pass('Database connection created');
39
40 ok( DBD_TEST::tab_create( $dbh ),"CREATE TABLE $tbl");
41
42 for my $i ( 0..$#col ) {
43 ok( $dbh->do( $_ ),"do $i: $_") for "DELETE FROM $tbl";
44 my $ti = DBD_TEST::get_type_for_column( $dbh, $col[$i] );
45 for ( @$dat ) {
46 my $v = $dbh->quote( $_->[$i], $ti->{DATA_TYPE} );
47 ok( $dbh->do( $_ ),"do $i: $_") for "INSERT INTO $tbl( $col[$i] ) VALUES( $v )";
48 }
49 my $a = $dbh->selectcol_arrayref("SELECT $col[$i] FROM $tbl");
50 ok( defined $a,"selectcol_arrayref $i: $#$a");
51 @$a = sort @$a;
52 is( $a->[$_], $dat->[$_][$i],"compare: $dat->[$_][$i]") for 0..$#$dat;
53 }
54 ok( $dbh->disconnect,'Disconnect');