File: spot-check-05.t

package info (click to toggle)
librose-db-object-perl 1%3A0.815-1%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,048 kB
  • sloc: perl: 79,670; sql: 28; makefile: 7
file content (111 lines) | stat: -rwxr-xr-x 2,193 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/perl -w

use strict;

use Test::More tests => 3;

BEGIN 
{
  require 't/test-lib.pl';
  use_ok('Rose::DB::Object::Loader');
}

our %Have;

#
# Tests
#

#$Rose::DB::Object::Manager::Debug = 1;

foreach my $db_type (qw(mysql))
{
  SKIP:
  {
    skip("$db_type tests", 2)  unless($Have{$db_type});
  }

  next  unless($Have{$db_type});

  Rose::DB->default_type($db_type);

  my $class_prefix = ucfirst($db_type);

  my $loader = 
    Rose::DB::Object::Loader->new(
      db           => Rose::DB->new,
      class_prefix => $class_prefix);

  my @classes = $loader->make_classes(include_tables => 'rdbo_company_vote');

  is(scalar @classes, 2, "uppercase keys - $db_type");

  my $o = Mysql::RdboCompanyVote->new;

  if($db_type eq 'mysql')
  {
    is($o->meta->column('canmeet')->perl_hash_definition,
       q(canmeet => { type => 'enum', check_in => [ 'YES', 'NO' ], default => 'YES', not_null => 1 }),
       "enum column defintion - $db_type");
  }
  else { ok(1, "non-mysql - $db_type") }
}

BEGIN
{
  #
  # MySQL
  #

  my $dbh;

  eval 
  {
    my $db = Rose::DB->new('mysql_admin');
    $dbh = $db->retain_dbh or die Rose::DB->error;

    # Drop existing tables, ignoring errors
    {
      local $dbh->{'RaiseError'} = 0;
      local $dbh->{'PrintError'} = 0;
      $dbh->do('DROP TABLE rdbo_company_vote CASCADE');
    }
  };

  if(!$@ && $dbh)
  {
    $Have{'mysql'} = 1;

    $dbh->do(<<"EOF");
CREATE TABLE rdbo_company_vote 
(
  vote_id      INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
  company_id   INT(10) UNSIGNED NOT NULL DEFAULT '0',
  question_id  INT(10) UNSIGNED NOT NULL DEFAULT '0',
  rating_num   TINYINT(3) UNSIGNED DEFAULT NULL ,
  comment      VARCHAR(255) DEFAULT NULL,
  canmeet      ENUM('YES','NO') NOT NULL DEFAULT 'YES',
  PRIMARY KEY (vote_id, company_id, question_id),
  UNIQUE KEY IDX_company_rating1 (company_id, question_id),
  KEY IDX_company_vote2 (company_id) ,
  KEY IDX_company_vote3 (question_id) 
)
EOF

    $dbh->disconnect;
  }

}

END
{
  if($Have{'mysql'})
  {
    my $dbh = Rose::DB->new('mysql_admin')->retain_dbh()
      or die Rose::DB->error;

    $dbh->do('DROP TABLE rdbo_company_vote CASCADE');

    $dbh->disconnect;
  }
}