7 use FreezeThaw qw(freeze thaw cmpStr);
17 FS::dbdef - Database objects
23 $dbdef = new FS::dbdef (@dbdef_table_objects);
24 $dbdef = load FS::dbdef "filename";
26 $dbdef->save("filename");
28 $dbdef->addtable($dbdef_table_object);
30 @table_names = $dbdef->tables;
32 $FS_dbdef_table_object = $dbdef->table;
36 FS::dbdef objects are collections of FS::dbdef_table objects and represnt
37 a database (a collection of tables).
43 =item new TABLE, TABLE, ...
45 Creates a new FS::dbdef object
50 my($proto,@tables)=@_;
51 my(%tables)=map { $_->name, $_ } @tables; #check for duplicates?
53 my($class) = ref($proto) || $proto;
58 bless ($self, $class);
64 Loads an FS::dbdef object from a file.
69 my($proto,$file)=@_; #use $proto ?
70 open(FILE,"<$file") or die "Can't open $file: $!";
71 my($string)=join('',<FILE>); #can $string have newlines? pry not?
72 close FILE or die "Can't close $file: $!";
73 my($self)=thaw $string;
80 Saves an FS::dbdef object to a file.
86 my($string)=freeze $self;
87 open(FILE,">$file") or die "Can't open $file: $!";
89 close FILE or die "Can't close file: $!";
90 my($check_self)=thaw $string;
91 die "Verify error: Can't freeze and thaw dbdef $self"
92 if (cmpStr($self,$check_self));
97 Adds this FS::dbdef_table object.
103 ${$self->{'tables'}}{$table->name}=$table; #check for dupliates?
108 Returns the names of all tables.
114 keys %{$self->{'tables'}};
117 =item table TABLENAME
119 Returns the named FS::dbdef_table object.
125 $self->{'tables'}->{$table};
130 Each FS::dbdef object should have a name which corresponds to its name within
131 the SQL database engine.
135 L<FS::dbdef_table>, L<FS::Record>,
139 beginning of abstraction into a class (not really)
141 ivan@sisd.com 97-dec-4
144 ivan@sisd.com 98-jan-20
146 added datatype (very kludgy and needs to be cleaned)
147 ivan@sisd.com 98-feb-21
149 perltrap (sigh) masked by mysql 3.20->3,21 ivan@sisd.com 98-mar-2
151 Change 'type' to 'atype' in agent_type
152 Changed attributes to special words which are changed in fs-setup
153 ie. double(10,2) <=> MONEYTYPE
154 Changed order of some of the field definitions because Pg6.3 is picky
155 Changed 'day' to 'daytime' in cust_main
156 Changed type of tax from tinyint to real
157 Change 'password' to '_password' in svc_acct
158 Pg6.3 does not allow 'field char(x) NULL'
159 bmccane@maxbaud.net 98-apr-3
161 rewrite: now properly OO. See also FS::dbdef_{table,column,unique,index}
163 ivan@sisd.com 98-apr-17
165 gained some extra functions ivan@sisd.com 98-may-11
167 now knows how to Freeze and Thaw itself ivan@sisd.com 98-jun-2
169 pod ivan@sisd.com 98-sep-23