File: 621-output-get-schema-create-mysql-innodb-backticks.t

package info (click to toggle)
libparse-dia-sql-perl 0.31-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 924 kB
  • sloc: perl: 3,865; makefile: 2
file content (152 lines) | stat: -rw-r--r-- 5,973 bytes parent folder | download | duplicates (6)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#   $Id: 620-output-get-schema-create.t,v 1.2 2009/04/01 08:10:43 aff Exp $

use warnings;
use strict;

use Data::Dumper;
#use Test::More;
use Test::More qw/no_plan/;
use Test::Exception;
use File::Spec::Functions;
use lib catdir qw ( blib lib );

#plan tests => 23;

use lib q{lib};
use_ok ('Parse::Dia::SQL');
use_ok ('Parse::Dia::SQL::Output');
use_ok ('Parse::Dia::SQL::Output::DB2');

# 1. parse input
my $db = 'mysql-innodb';
my $diasql =  Parse::Dia::SQL->new( file => catfile(qw(t data TestERD.dia)), db => $db, backticks => 1 );
isa_ok($diasql, q{Parse::Dia::SQL}, q{Expect a Parse::Dia::SQL object});
is($diasql->convert(), 1, q{Expect convert to return 1});

# 2. get output instance
my $subclass   = undef;
lives_ok(sub { $subclass = $diasql->get_output_instance(); },
  q{get_output_instance (db2) should not die});

isa_ok($subclass, 'Parse::Dia::SQL::Output');
isa_ok($subclass, 'Parse::Dia::SQL::Output::MySQL::InnoDB');
can_ok($subclass, 'get_schema_create');

# 3. create sql
my $create_table = $subclass->get_schema_create();

# 4. Check for backticks presence
like($create_table, qr|.*
  create \s+ table \s+ `imageInfo` \s* \(
     \s* `id` \s+ numeric \s* \(18\) \s+ not \s+ null \s* ,
     \s* `insertionDate` \s+ timestamp \s+ not \s+ null \s* ,
     \s* `md5sum` \s+ char \s* \(32\) \s+ not \s+ null \s* ,
     \s* `binaryType` \s+ varchar \s* \(16\) \s+ default \s+ 'jpg' \s+ null \s* ,
     \s* `name` \s+ varchar \s* \(64\) \s+ not \s+ null \s* ,
     \s* `locationList` \s+ varchar \s* \(128\) \s+ default \s+ '//imgserver.org' \s* ,
     \s* `description` \s+ varchar \s* \(128\) \s+ null \s* ,
     \s* constraint \s+ pk_\w+ \s+ primary \s+ key \s* \(id\) \s*
  \)
.*|six, q{Check syntax for sql create table imageInfo});

__END__

like($create_table, qr|.*
  create \s+ table \s+ subImageInfo \s* \(
     \s* imageInfo_id \s+ numeric \s* \(18\) \s+ not \s+ null \s* ,
     \s* pixSize \s+ integer \s+ not \s+ null \s* ,
     \s* constraint \s+ pk_\w+ \s+ primary \s+ key \s* \(imageInfo_id \s* , \s* pixSize\) 
     \s* \) \s* (;)?
.*|six, q{Check syntax for sql create table SubimageInfo});

like($create_table, qr|.*
  create \s+ table \s+ imageCategoryList \s* \(
    \s* imageInfo_id \s+ numeric \s* \(18\) \s+ not \s+ null \s* ,
    \s* name \s+ varchar \s* \(32\) \s+ not \s+ null \s* ,
    \s* constraint \s+ \w+ \s+ primary \s+ key \s* \(imageInfo_id \s* , \s* name\)
    \s* \) \s* (;)?
.*|six, q{Check syntax for sql create table imageCategoryList});

like($create_table, qr|.*
  create \s+ table \s+ categoryNames \s* \(
    \s* name \s+ varchar \s* \(32\) \s+ not \s+ null \s* ,
    \s* constraint \s+ pk_\w+ \s+ primary \s+ key \s* \(name\)
    \s* \) \s* (;)?
.*|six, q{Check syntax for sql create table categoryNames});

like($create_table, qr|.*
  create \s+ table \s+ imageAttribute \s* \(
    \s* imageInfo_id \s+ numeric \s* \(18\) \s+ not \s+ null \s* ,
    \s* attributeCategory_id \s+ numeric \s* \(18\) \s+ not \s+ null \s* ,
    \s* numValue \s+ numeric \s* \(8\) \s* ,
    \s* category \s+ numeric \s* \(4\) \s* ,
    \s* constraint \s+ pk_\w+ \s+ primary \s+ key \s* \(imageInfo_id,attributeCategory_id\)
    \s* \) \s* (;)?
.*|six, q{Check syntax for sql create table imageAttribute});

like($create_table, qr|.*
  create \s+ table \s+ userInfo \s* \(
    \s* id \s+ numeric \s* \(18\) \s+ not \s+ null \s* ,
    \s* insertionDate \s+ timestamp \s* ,
    \s* md5sum \s+ char \s* \(32\) \s* ,
    \s* birthDate \s+ timestamp \s* ,
    \s* gender \s+ char \s* \(1\) \s* ,
    \s* name \s+ varchar \s* \(32\) \s* ,
    \s* email \s+ varchar \s* \(96\) \s* ,
    \s* currentCategory \s+ varchar \s* \(32\) \s* ,
    \s* lastDebitDate \s+ timestamp \s* ,
    \s* acctBalance \s+ numeric \s* \(10,2\) \s* ,
    \s* active \s+ integer \s* ,
    \s* constraint \s+ pk_\w+ \s+ primary \s+ key \s* \(id\)
    \s* \) \s* (;)?
.*|six, q{Check syntax for sql create table userInfo});

like($create_table, qr|.*
  create \s+ table \s+ userAttribute \s* \(
    \s* userInfo_id \s+ numeric \s* \(18\) \s+ not \s+ null \s* ,
    \s* attributeCategory_id \s+ numeric \s* \(18\) \s+ not \s+ null \s* ,
    \s* numValue \s+ numeric \s* \(5,4\) \s* ,
    \s* constraint \s+ pk_\w+ \s+ primary \s+ key \s* \(userInfo_id,attributeCategory_id\)
    \s* \) \s* (;)?
.*|six, q{Check syntax for sql create table userAttribute});

like($create_table, qr|.*
  create \s+ table \s+ userImageRating \s* \(
    \s* userInfo_id \s+ numeric \s* \(18\) \s+ not \s+ null \s* ,
    \s* imageInfo_id \s+ numeric \s* \(15\) \s+ not \s+ null \s* ,
    \s* rating \s+ integer \s* ,
    \s* constraint \s+ pk_\w+ \s+ primary \s+ key \s* \(userInfo_id,imageInfo_id\)
    \s* \) \s* (;)?
.*|six, q{Check syntax for sql create table userAttribute});


like($create_table, qr|.*
  create \s+ table \s+ attributeCategory \s* \(
    \s* id \s+ numeric \s* \(18\) \s+ not \s+ null \s* ,
    \s* attributeDesc \s+ varchar \s* \(128\) \s* ,
    \s* constraint \s+ pk_\w+ \s+ primary \s+ key \s* \(id\)
    \s* \) \s* (;)?
.*|six, q{Check syntax for sql create table userAttribute});

like($create_table, qr|.*
  create \s+ table \s+ userSession \s* \(
    \s* userInfo_id \s+ numeric \s* \(18\) \s+ not \s+ null \s* ,
    \s* md5sum \s+ char \s* \(32\) \s+ not \s+ null \s* ,
    \s* insertionDate \s+ timestamp \s* ,
    \s* expireDate \s+ timestamp \s* ,
    \s* ipAddress \s+ varchar \s* \(24\) \s* ,
    \s* constraint \s+ pk_\w+ \s+ primary \s+ key \s* \(userInfo_id,md5sum\)
    \s* \) \s* (;)?
.*|six, q{Check syntax for sql create table userAttribute});

like($create_table, qr|.*
create \s+ table \s+ extremes \s* \(
    \s+ name \s+ varchar \s* \(32\) \s+ not \s+ null \s* ,
    \s+ colName \s+ varchar \s* \(64\) \s* ,
    \s+ minVal \s+ numeric \s* \(15\) \s* ,
    \s+ maxVal \s+ numeric \s* \(15\) \s* ,
		\s+ constraint \s+ pk_\w+ \s+ primary \s+ key  \s* \(name\)
    \s* \) \s* (;)?
.*|six, q{Check syntax for sql create table extremes});

__END__