Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1293 dpurdie 1
###############################################################################
2
# Codestriker: Copyright (c) 2001, 2002 David Sitsky.  All rights reserved.
3
# sits@users.sourceforge.net
4
#
5
# This program is free software; you can redistribute it and modify it under
6
# the terms of the GPL.
7
 
8
# Object which represents a column specification for a database table.
9
 
10
package Codestriker::DB::Column;
11
 
12
use strict;
13
 
14
# Export the type values.
15
use vars qw ( $TYPE );
16
 
17
# List of column datatypes that can be used in specifying a column.
18
$Codestriker::DB::Column::TYPE = {
19
    TEXT => 0,
20
    VARCHAR => 1,
21
    INT32 => 2,
22
    INT16 => 3,
23
    DATETIME => 4,
24
    FLOAT => 5
25
};
26
 
27
# A column object consists of a name, type, optional type parameter and
28
# an indication as to whether it is an autoincrement field or not (integer
29
# types only), whether the field is a part of the primary key and whether the
30
# field is mandatory.  By default, the field is mandatory.
31
#
32
# usage: Column->new({name=>"id", type=>INT32_TYPE, autoincrement=>1,
33
#                     pk=>1, mandatory=>1});
34
#
35
sub new {
36
    my $type = shift;
37
    my %params = @_;
38
 
39
    my $self = {};
40
    $self->{name} = $params{name};
41
    $self->{type} = $params{type};
42
 
43
    if ($self->{type} == $Codestriker::DB::Column::TYPE->{VARCHAR}) {
44
	$self->{length} = $params{length};
45
    }
46
 
47
    if (exists $params{autoincrement}) {
48
	$self->{autoincrement} = $params{autoincrement};
49
    } else {
50
	$self->{autoincrement} = 0;
51
    }
52
 
53
    if (exists $params{autoincr}) {
54
	$self->{autoincrement} = $params{autoincr};
55
    } else {
56
	$self->{autoincrement} = 0;
57
    }
58
 
59
    if (exists $params{pk}) {
60
	$self->{pk} = $params{pk};
61
    } else {
62
	$self->{pk} = 0;
63
    }
64
 
65
    if (exists $params{mandatory}) {
66
	$self->{mandatory} = $params{mandatory};
67
    } else {
68
	$self->{mandatory} = 1;
69
    }
70
 
71
    return bless $self, $type;
72
}
73
 
74
# Return the name of the column.
75
sub get_name {
76
    my $self = shift;
77
    return $self->{name};
78
}
79
 
80
# Return the type of the column.
81
sub get_type {
82
    my $self = shift;
83
    return $self->{type};
84
}
85
 
86
# Indicate if the column is an autoincrement or not.
87
sub is_autoincrement {
88
    my $self = shift;
89
    return $self->{autoincrement};
90
}
91
 
92
# Indicate if the column is a part of the primary key.
93
sub is_primarykey {
94
    my $self = shift;
95
    return $self->{pk};
96
}
97
 
98
# Indicate if the column is mandatory.
99
sub is_mandatory {
100
    my $self = shift;
101
    return $self->{mandatory};
102
}
103
 
104
# Return the varchar length.
105
sub get_length {
106
    my $self = shift;
107
    return $self->{length};
108
}
109
 
110
1;