49
|
1 use strict;
|
|
2 package IMPL::SQL::Schema::Type;
|
165
|
3 use parent qw(IMPL::Object IMPL::Object::Autofill);
|
49
|
4 use IMPL::Class::Property;
|
|
5 use IMPL::Class::Property::Direct;
|
|
6
|
|
7 BEGIN {
|
165
|
8 public _direct property name => prop_get;
|
|
9 public _direct property maxLength => prop_get;
|
|
10 public _direct property scale => prop_get;
|
|
11 public _direct property unsigned => prop_get;
|
|
12 public _direct property zerofill => prop_get;
|
|
13 public _direct property tag => prop_get;
|
49
|
14 }
|
|
15
|
|
16 __PACKAGE__->PassThroughArgs;
|
|
17
|
|
18 sub CTOR {
|
|
19 my $this = shift;
|
|
20
|
165
|
21 $this->{$scale} = 0 if not $this->{$scale};
|
49
|
22 }
|
|
23
|
|
24 sub isEquals {
|
|
25 my ($a,$b) = @_;
|
|
26
|
|
27 if (defined $a and defined $b) {
|
|
28 return $a == $b;
|
|
29 } else {
|
|
30 if (defined $a or defined $b) {
|
|
31 return 0;
|
|
32 } else {
|
|
33 return 1;
|
|
34 }
|
|
35 }
|
|
36 }
|
|
37
|
|
38 sub isSame {
|
|
39 my ($this,$other) = @_;
|
|
40
|
165
|
41 return ($this->{$name} eq $other->{$name} and isEquals($this->{$maxLength},$other->{$maxLength}) and isEquals($this->{$scale},$other->{$scale}));
|
49
|
42 }
|
|
43
|
|
44 1;
|
165
|
45
|
|
46 __END__
|
|
47
|
|
48 =pod
|
|
49
|
|
50 =head1 NAME
|
|
51
|
|
52 C<IMPL::SQL::Schema::Type> Описывает SQL типы данных
|
|
53
|
|
54 =head1 SYNOPSIS
|
|
55
|
|
56 =begin code
|
|
57
|
|
58 use IMPL::SQL::Schema::Type;
|
|
59
|
|
60 my $varchar_t = new IMPL::SQL::Schema::Type( name => 'varchar', maxLength => 255 );
|
|
61
|
|
62 my $real_t = new IMPL::SQL::Schema::Type( name => 'float', maxLength=> 10, scale => 4); # mysql: float(10,4)
|
|
63
|
|
64 =end
|
|
65
|
|
66 Данный класс используется для стандатрного описания SQL типов данных. В зависимости
|
|
67 от движка БД эти объекты могут быть представлены различными строковыми представлениями.
|
|
68
|
|
69 =head1 MEMBERS
|
|
70
|
|
71 =over
|
|
72
|
|
73 =item C<CTOR(%props)>
|
|
74
|
|
75 Конструктор, заполняет объект значениями которые были переданы в конструкторе.
|
|
76
|
|
77 =item C<[get]name>
|
|
78
|
|
79 Имя типа. Обязательно.
|
|
80
|
|
81 =item C<[get]maxLength>
|
|
82
|
|
83 Максимальная длина, используется только для типов, имеющих длину (либо переменную,
|
|
84 либо постоянную).
|
|
85
|
|
86 =item C<[get]scale>
|
|
87
|
|
88 Точность, количество знаков после запятой. Используется вместе с C<maxLength>.
|
|
89
|
|
90 =item C<[get]unsigned>
|
|
91
|
|
92 Используется с числовыми данными, обозначает беззнаковые типы.
|
|
93
|
|
94 =item C<[get]zerofill>
|
|
95
|
|
96 Нестандартный атрибут дополняющий числа лидирующими нулями до C<maxLength>.
|
|
97
|
|
98 =item C<[get]tag>
|
|
99
|
|
100 Хеш с дополнительными опциями.
|
|
101
|
|
102 =back
|
|
103
|
|
104 =cut |