a90e76b1e4b4ed0d5baf8a90b65ed767557799aa
[freeside.git] / site_perl / Record.pm
1 package FS::Record;
2
3 use strict;
4 use vars qw($dbdef_file $dbdef $setup_hack $AUTOLOAD @ISA @EXPORT_OK);
5 use subs qw(reload_dbdef);
6 use Exporter;
7 use Carp;
8 use File::CounterFile;
9 use FS::UID qw(dbh checkruid swapuid getotaker datasrc);
10 use FS::dbdef;
11
12 @ISA = qw(Exporter);
13 @EXPORT_OK = qw(dbh fields hfields qsearch qsearchs dbdef);
14
15 $File::CounterFile::DEFAULT_DIR = "/var/spool/freeside/counters" ;
16
17 $dbdef_file = "/var/spool/freeside/dbdef.". datasrc;
18
19 reload_dbdef unless $setup_hack;
20
21 =head1 NAME
22
23 FS::Record - Database record objects
24
25 =head1 SYNOPSIS
26
27     use FS::Record;
28     use FS::Record qw(dbh fields hfields qsearch qsearchs dbdef);
29
30     $record = new FS::Record 'table', \%hash;
31     $record = new FS::Record 'table', { 'column' => 'value', ... };
32
33     $record  = qsearchs FS::Record 'table', \%hash;
34     $record  = qsearchs FS::Record 'table', { 'column' => 'value', ... };
35     @records = qsearch  FS::Record 'table', \%hash; 
36     @records = qsearch  FS::Record 'table', { 'column' => 'value', ... };
37
38     $table = $record->table;
39     $dbdef_table = $record->dbdef_table;
40
41     $value = $record->get('column');
42     $value = $record->getfield('column');
43     $value = $record->column;
44
45     $record->set( 'column' => 'value' );
46     $record->setfield( 'column' => 'value' );
47     $record->column('value');
48
49     %hash = $record->hash;
50
51     $hashref = $record->hashref;
52
53     $error = $record->add;
54
55     $error = $record->del;
56
57     $error = $new_record->rep($old_record);
58
59     $value = $record->unique('column');
60
61     $value = $record->ut_float('column');
62     $value = $record->ut_number('column');
63     $value = $record->ut_numbern('column');
64     $value = $record->ut_money('column');
65     $value = $record->ut_text('column');
66     $value = $record->ut_textn('column');
67     $value = $record->ut_alpha('column');
68     $value = $record->ut_alphan('column');
69     $value = $record->ut_phonen('column');
70     $value = $record->ut_anythingn('column');
71
72     $dbdef = reload_dbdef;
73     $dbdef = reload_dbdef "/non/standard/filename";
74     $dbdef = dbdef;
75
76     $quoted_value = _quote($value,'table','field');
77
78     #depriciated
79     $fields = hfields('table');
80     if ( $fields->{Field} ) { # etc.
81
82     @fields = fields 'table';
83
84
85 =head1 DESCRIPTION
86
87 (Mostly) object-oriented interface to database records.  Records are currently
88 implemented on top of DBI.  FS::Record is intended as a base class for
89 table-specific classes to inherit from, i.e. FS::cust_main.
90
91 =head1 METHODS
92
93 =over 4
94
95 =item new TABLE, HASHREF
96
97 Creates a new record.  It doesn't store it in the database, though.  See
98 L<"add"> for that.
99
100 Note that the object stores this hash reference, not a distinct copy of the
101 hash it points to.  You can ask the object for a copy with the I<hash> 
102 method.
103
104 =cut
105
106 sub new { 
107   my($proto,$table,$hashref) = @_;
108   confess "Second arguement to FS::Record->new is not a HASH ref: ",
109           ref($hashref), " ", $hashref, "\n"
110     unless ref($hashref) eq 'HASH'; #bad practice?
111
112   #check to make sure $table exists? (ask dbdef)
113
114   foreach my $field ( FS::Record::fields $table ) { 
115      $hashref->{$field}='' unless defined $hashref->{$field};
116   }
117
118   # mySQL must rtrim the inbound text strings or store them z-terminated
119   # I simulate this for Postgres below
120   # Turned off in favor of ChopBlanks in UID.pm (see man DBI)
121   #if (datasrc =~ m/Pg/)
122   #{
123   #  foreach my $index (keys %$hashref)
124   #  {
125   #    $$hashref{$index} = unpack("A255", $$hashref{$index})
126   #     if ($$hashref{$index} =~ m/ $/) ;
127   #  }
128   #}
129
130   foreach my $column ( FS::Record::fields $table ) { 
131     #trim the '$' from money fields for Pg (beong HERE?)
132     #(what about Pg i18n?)
133     if ( datasrc =~ m/Pg/ 
134          && $dbdef->table($table)->column($column)->type eq 'money' ) {
135       ${$hashref}{$column} =~ s/^\$//;
136     }
137     #foreach my $column ( grep $dbdef->table($table)->column($_)->type eq 'money', keys %{$hashref} ) {
138     #  ${$hashref}{$column} =~ s/^\$//;
139     #}
140   }
141
142   my $class = ref($proto) || $proto;
143   my $self = { 'Table' => $table,
144                'Hash' => $hashref,
145              };
146
147   bless ($self, $class);
148
149 }
150
151 =item qsearch TABLE, HASHREF
152
153 Searches the database for all records matching (at least) the key/value pairs
154 in HASHREF.  Returns all the records found as `FS::TABLE' objects if that
155 module is loaded (i.e. via `use FS::cust_main;'), otherwise returns FS::Record
156 objects.
157
158 =cut
159
160 # Usage: @records = &FS::Search::qsearch($table,\%hash);
161 # Each element of @records is a FS::Record object.
162 sub qsearch {
163   my($table,$record) = @_;
164   my($dbh) = dbh;
165
166   my(@fields)=grep exists($record->{$_}), fields($table);
167
168   my($sth);
169   my($statement) = "SELECT * FROM $table". ( @fields
170     ? " WHERE ". join(' AND ',
171         map("$_ = ". _quote($record->{$_},$table,$_), @fields)
172       )
173     : ''
174   );
175   $sth=$dbh->prepare($statement)
176     or croak $dbh->errstr; #is that a little too harsh?  hmm.
177
178   if ( eval ' scalar(@FS::'. $table. '::ISA);' ) {
179     map {
180       eval 'create FS::'. $table. ' ( $sth->fetchrow_hashref );';
181     } ( 1 .. $sth->execute );
182   } else {
183     carp "qsearch: warning: FS::$table not loaded; returning generic FS::Record objects";
184     map {
185       new FS::Record ($table,$sth->fetchrow_hashref);
186     } ( 1 .. $sth->execute );
187   }
188
189 }
190
191 =item qsearchs TABLE, HASHREF
192
193 Same as qsearch, except that if more than one record matches, it B<carp>s but
194 returns the first.  If this happens, you either made a logic error in asking
195 for a single item, or your data is corrupted.
196
197 =cut
198
199 sub qsearchs { # $result_record = &FS::Record:qsearchs('table',\%hash);
200   my(@result) = qsearch(@_);
201   carp "Multiple records in scalar search!" if scalar(@result) > 1;
202     #should warn more vehemently if the search was on a primary key?
203   $result[0];
204 }
205
206 =item table
207
208 Returns the table name.
209
210 =cut
211
212 sub table {
213   my($self) = @_;
214   $self -> {'Table'};
215 }
216
217 =item dbdef_table
218
219 Returns the FS::dbdef_table object for the table.
220
221 =cut
222
223 sub dbdef_table {
224   my($self)=@_;
225   my($table)=$self->table;
226   $dbdef->table($table);
227 }
228
229 =item get, getfield COLUMN
230
231 Returns the value of the column/field/key COLUMN.
232
233 =cut
234
235 sub get {
236   my($self,$field) = @_;
237   # to avoid "Use of unitialized value" errors
238   if ( defined ( $self->{Hash}->{$field} ) ) {
239     $self->{Hash}->{$field};
240   } else { 
241     '';
242   }
243 }
244 sub getfield {
245   get(@_);
246 }
247
248 =item set, setfield COLUMN, VALUE
249
250 Sets the value of the column/field/key COLUMN to VALUE.  Returns VALUE.
251
252 =cut
253
254 sub set { 
255   my($self,$field,$value) = @_;
256   $self->{'Hash'}->{$field} = $value;
257 }
258 sub setfield {
259   set(@_);
260 }
261
262 =item AUTLOADED METHODS
263
264 $record->column is a synonym for $record->get('column');
265
266 $record->column('value') is a synonym for $record->set('column','value');
267
268 =cut
269
270 sub AUTOLOAD {
271   my($self,$value)=@_;
272   my($field)=$AUTOLOAD;
273   $field =~ s/.*://;
274   if ( defined($value) ) {
275     $self->setfield($field,$value);
276   } else {
277     $self->getfield($field);
278   }    
279 }
280
281 =item hash
282
283 Returns a list of the column/value pairs, usually for assigning to a new hash.
284
285 To make a distinct duplicate of an FS::Record object, you can do:
286
287     $new = new FS::Record ( $old->table, { $old->hash } );
288
289 =cut
290
291 sub hash {
292   my($self) = @_;
293   %{ $self->{'Hash'} }; 
294 }
295
296 =item hashref
297
298 Returns a reference to the column/value hash.
299
300 =cut
301
302 sub hashref {
303   my($self) = @_;
304   $self->{'Hash'};
305 }
306
307 =item add
308
309 Adds this record to the database.  If there is an error, returns the error,
310 otherwise returns false.
311
312 =cut
313
314 sub add {
315   my($self) = @_;
316   my($dbh)=dbh;
317   my($table)=$self->table;
318
319   #single-field unique keys are given a value if false
320   #(like MySQL's AUTO_INCREMENT)
321   foreach ( $dbdef->table($table)->unique->singles ) {
322     $self->unique($_) unless $self->getfield($_);
323   }
324   #and also the primary key
325   my($primary_key)=$dbdef->table($table)->primary_key;
326   $self->unique($primary_key) 
327     if $primary_key && ! $self->getfield($primary_key);
328
329   my (@fields) =
330     grep defined($self->getfield($_)) && $self->getfield($_) ne "",
331     fields($table)
332   ;
333
334   my($sth);
335   my($statement)="INSERT INTO $table ( ".
336       join(', ',@fields ).
337     ") VALUES (".
338       join(', ',map(_quote($self->getfield($_),$table,$_), @fields)).
339     ")"
340   ;
341   $sth = $dbh->prepare($statement) or return $dbh->errstr;
342
343   local $SIG{HUP} = 'IGNORE';
344   local $SIG{INT} = 'IGNORE';
345   local $SIG{QUIT} = 'IGNORE'; 
346   local $SIG{TERM} = 'IGNORE';
347   local $SIG{TSTP} = 'IGNORE';
348
349   $sth->execute or return $sth->errstr;
350
351   '';
352 }
353
354 =item del
355
356 Delete this record from the database.  If there is an error, returns the error,
357 otherwise returns false.
358
359 =cut
360
361 sub del {
362   my($self) = @_;
363   my($dbh)=dbh;
364   my($table)=$self->table;
365
366   my($sth);
367   my($statement)="DELETE FROM $table WHERE ". join(' AND ',
368     map {
369       $self->getfield($_) eq ''
370         ? "$_ IS NULL"
371         : "$_ = ". _quote($self->getfield($_),$table,$_)
372     } ( $dbdef->table($table)->primary_key )
373           ? ($dbdef->table($table)->primary_key)
374           : fields($table)
375   );
376   $sth = $dbh->prepare($statement) or return $dbh->errstr;
377
378   local $SIG{HUP} = 'IGNORE';
379   local $SIG{INT} = 'IGNORE';
380   local $SIG{QUIT} = 'IGNORE'; 
381   local $SIG{TERM} = 'IGNORE';
382   local $SIG{TSTP} = 'IGNORE';
383
384   my($rc);
385   $rc=$sth->execute or return $sth->errstr;
386   #not portable #return "Record not found, statement:\n$statement" if $rc eq "0E0";
387
388   undef $self; #no need to keep object!
389
390   '';
391 }
392
393 =item rep OLD_RECORD
394
395 Replace the OLD_RECORD with this one in the database.  If there is an error,
396 returns the error, otherwise returns false.
397
398 =cut
399
400 sub rep {
401   my($new,$old)=@_;
402   my($dbh)=dbh;
403   my($table)=$old->table;
404   my(@fields)=fields($table);
405   my(@diff)=grep $new->getfield($_) ne $old->getfield($_), @fields;
406
407   if ( scalar(@diff) == 0 ) {
408     carp "Records identical";
409     return '';
410   }
411
412   return "Records not in same table!" unless $new->table eq $table;
413
414   my($sth);
415   my($statement)="UPDATE $table SET ". join(', ',
416     map {
417       "$_ = ". _quote($new->getfield($_),$table,$_) 
418     } @diff
419   ). ' WHERE '.
420     join(' AND ',
421       map {
422         $old->getfield($_) eq ''
423           ? "$_ IS NULL"
424           : "$_ = ". _quote($old->getfield($_),$table,$_)
425 #      } @fields
426 #      } ( primary_key($table) ? (primary_key($table)) : @fields )
427       } ( $dbdef->table($table)->primary_key 
428             ? ($dbdef->table($table)->primary_key)
429             : @fields
430         )
431     )
432   ;
433   #warn $statement;
434   $sth = $dbh->prepare($statement) or return $dbh->errstr;
435
436   local $SIG{HUP} = 'IGNORE';
437   local $SIG{INT} = 'IGNORE';
438   local $SIG{QUIT} = 'IGNORE'; 
439   local $SIG{TERM} = 'IGNORE';
440   local $SIG{TSTP} = 'IGNORE';
441
442   my($rc);
443   $rc=$sth->execute or return $sth->errstr;
444   #not portable #return "Record not found (or records identical)." if $rc eq "0E0";
445
446   '';
447
448 }
449
450 =item unique COLUMN
451
452 Replaces COLUMN in record with a unique number.  Called by the B<add> method
453 on primary keys and single-field unique columns (see L<FS::dbdef_table>).
454 Returns the new value.
455
456 =cut
457
458 sub unique {
459   my($self,$field) = @_;
460   my($table)=$self->table;
461
462   croak("&FS::UID::checkruid failed") unless &checkruid;
463
464   croak "Unique called on field $field, but it is ",
465         $self->getfield($field),
466         ", not null!"
467     if $self->getfield($field);
468
469   #warn "table $table is tainted" if is_tainted($table);
470   #warn "field $field is tainted" if is_tainted($field);
471
472   &swapuid;
473   my($counter) = new File::CounterFile "$table.$field",0;
474 # hack for web demo
475 #  getotaker() =~ /^([\w\-]{1,16})$/ or die "Illegal CGI REMOTE_USER!";
476 #  my($user)=$1;
477 #  my($counter) = new File::CounterFile "$user/$table.$field",0;
478 # endhack
479
480   my($index)=$counter->inc;
481   $index=$counter->inc
482     while qsearchs($table,{$field=>$index}); #just in case
483   &swapuid;
484
485   $index =~ /^(\d*)$/;
486   $index=$1;
487
488   $self->setfield($field,$index);
489
490 }
491
492 =item ut_float COLUMN
493
494 Check/untaint floating point numeric data: 1.1, 1, 1.1e10, 1e10.  May not be
495 null.  If there is an error, returns the error, otherwise returns false.
496
497 =cut
498
499 sub ut_float {
500   my($self,$field)=@_ ;
501   ($self->getfield($field) =~ /^(\d+\.\d+)$/ ||
502    $self->getfield($field) =~ /^(\d+)$/ ||
503    $self->getfield($field) =~ /^(\d+\.\d+e\d+)$/ ||
504    $self->getfield($field) =~ /^(\d+e\d+)$/)
505     or return "Illegal or empty (float) $field!";
506   $self->setfield($field,$1);
507   '';
508 }
509
510 =item ut_number COLUMN
511
512 Check/untaint simple numeric data (whole numbers).  May not be null.  If there
513 is an error, returns the error, otherwise returns false.
514
515 =cut
516
517 sub ut_number {
518   my($self,$field)=@_;
519   $self->getfield($field) =~ /^(\d+)$/
520     or return "Illegal or empty (numeric) $field!";
521   $self->setfield($field,$1);
522   '';
523 }
524
525 =item ut_numbern COLUMN
526
527 Check/untaint simple numeric data (whole numbers).  May be null.  If there is
528 an error, returns the error, otherwise returns false.
529
530 =cut
531
532 sub ut_numbern {
533   my($self,$field)=@_;
534   $self->getfield($field) =~ /^(\d*)$/
535     or return "Illegal (numeric) $field!";
536   $self->setfield($field,$1);
537   '';
538 }
539
540 =item ut_money COLUMN
541
542 Check/untaint monetary numbers.  May be negative.  Set to 0 if null.  If there
543 is an error, returns the error, otherwise returns false.
544
545 =cut
546
547 sub ut_money {
548   my($self,$field)=@_;
549   $self->getfield($field) =~ /^(\-)? ?(\d*)(\.\d{2})?$/
550     or return "Illegal (money) $field!";
551   $self->setfield($field,"$1$2$3" || 0);
552   '';
553 }
554
555 =item ut_text COLUMN
556
557 Check/untaint text.  Alphanumerics, spaces, and the following punctuation
558 symbols are currently permitted: ! @ # $ % & ( ) - + ; : ' " , . ? /
559 May not be null.  If there is an error, returns the error, otherwise returns
560 false.
561
562 =cut
563
564 sub ut_text {
565   my($self,$field)=@_;
566   $self->getfield($field) =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/]+)$/
567     or return "Illegal or empty (text) $field";
568   $self->setfield($field,$1);
569   '';
570 }
571
572 =item ut_textn COLUMN
573
574 Check/untaint text.  Alphanumerics, spaces, and the following punctuation
575 symbols are currently permitted: ! @ # $ % & ( ) - + ; : ' " , . ? /
576 May be null.  If there is an error, returns the error, otherwise returns false.
577
578 =cut
579
580 sub ut_textn {
581   my($self,$field)=@_;
582   $self->getfield($field) =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/]*)$/
583     or return "Illegal (text) $field";
584   $self->setfield($field,$1);
585   '';
586 }
587
588 =item ut_alpha COLUMN
589
590 Check/untaint alphanumeric strings (no spaces).  May not be null.  If there is
591 an error, returns the error, otherwise returns false.
592
593 =cut
594
595 sub ut_alpha {
596   my($self,$field)=@_;
597   $self->getfield($field) =~ /^(\w+)$/
598     or return "Illegal or empty (alphanumeric) $field!";
599   $self->setfield($field,$1);
600   '';
601 }
602
603 =item ut_alpha COLUMN
604
605 Check/untaint alphanumeric strings (no spaces).  May be null.  If there is an
606 error, returns the error, otherwise returns false.
607
608 =cut
609
610 sub ut_alphan {
611   my($self,$field)=@_;
612   $self->getfield($field) =~ /^(\w*)$/ 
613     or return "Illegal (alphanumeric) $field!";
614   $self->setfield($field,$1);
615   '';
616 }
617
618 =item ut_phonen COLUMN
619
620 Check/untaint phone numbers.  May be null.  If there is an error, returns
621 the error, otherwise returns false.
622
623 =cut
624
625 sub ut_phonen {
626   my($self,$field)=@_;
627   my $phonen = $self->getfield($field);
628   if ( $phonen eq '' ) {
629     $self->setfield($field,'');
630   } else {
631     $phonen =~ s/\D//g;
632     $phonen =~ /^(\d{3})(\d{3})(\d{4})(\d*)$/
633       or return "Illegal (phone) $field!";
634     $phonen = "$1-$2-$3";
635     $phonen .= " x$4" if $4;
636     $self->setfield($field,$phonen);
637   }
638   '';
639 }
640
641 =item ut_anything COLUMN
642
643 Untaints arbitrary data.  Be careful.
644
645 =cut
646
647 sub ut_anything {
648   my($self,$field)=@_;
649   $self->getfield($field) =~ /^(.*)$/ or return "Illegal $field!";
650   $self->setfield($field,$1);
651   '';
652 }
653
654
655 =head1 SUBROUTINES
656
657 =over 4
658
659 =item reload_dbdef([FILENAME])
660
661 Load a database definition (see L<FS::dbdef>), optionally from a non-default
662 filename.  This command is executed at startup unless
663 I<$FS::Record::setup_hack> is true.  Returns a FS::dbdef object.
664
665 =cut
666
667 sub reload_dbdef {
668   my $file = shift || $dbdef_file;
669   $dbdef = load FS::dbdef ($file);
670 }
671
672 =item dbdef
673
674 Returns the current database definition.  See L<FS::dbdef>.
675
676 =cut
677
678 sub dbdef { $dbdef; }
679
680 =item _quote VALUE, TABLE, COLUMN
681
682 This is an internal function used to construct SQL statements.  It returns
683 VALUE DBI-quoted (see L<DBI/"quote">) unless VALUE is a number and the column
684 type (see L<dbdef_column>) does not end in `char' or `binary'.
685
686 =cut
687
688 sub _quote {
689   my($value,$table,$field)=@_;
690   my($dbh)=dbh;
691   if ( $value =~ /^\d+(\.\d+)?$/ && 
692 #       ! ( datatype($table,$field) =~ /^char/ ) 
693        ! ( $dbdef->table($table)->column($field)->type =~ /(char|binary)$/i ) 
694   ) {
695     $value;
696   } else {
697     $dbh->quote($value);
698   }
699 }
700
701 =item hfields TABLE
702
703 This is depriciated.  Don't use it.
704
705 It returns a hash-type list with the fields of this record's table set true.
706
707 =cut
708
709 sub hfields {
710   carp "hfields is depriciated";
711   my($table)=@_;
712   my(%hash);
713   foreach (fields($table)) {
714     $hash{$_}=1;
715   }
716   \%hash;
717 }
718
719 =item fields TABLE
720
721 This returns a list of the columns in this record's table
722 (See L<dbdef_table>).
723
724 =cut
725
726 # Usage: @fields = fields($table);
727 sub fields {
728   my($table) = @_;
729   #my(@fields) = $dbdef->table($table)->columns;
730   croak "Usage: \@fields = fields(\$table)" unless $table;
731   my($table_obj) = $dbdef->table($table);
732   croak "Unknown table $table" unless $table_obj;
733   $table_obj->columns;
734 }
735
736 #sub _dump {
737 #  my($self)=@_;
738 #  join("\n", map {
739 #    "$_: ". $self->getfield($_). "|"
740 #  } (fields($self->table)) );
741 #}
742
743 #sub DESTROY {
744 #  my $self = shift;
745 #  #use Carp qw(cluck);
746 #  #cluck "DESTROYING $self";
747 #  warn "DESTROYING $self";
748 #}
749
750 #sub is_tainted {
751 #             return ! eval { join('',@_), kill 0; 1; };
752 #         }
753
754 =back
755
756 =head1 BUGS
757
758 This module should probably be renamed, since much of the functionality is
759 of general use.  It is not completely unlike Adapter::DBI (see below).
760
761 Exported qsearch and qsearchs should be depriciated in favor of method calls
762 (against an FS::Record object like the old search and searchs that qsearch
763 and qsearchs were on top of.)
764
765 The whole fields / hfields mess should be removed.
766
767 The various WHERE clauses should be subroutined.
768
769 table string should be depriciated in favor of FS::dbdef_table.
770
771 No doubt we could benefit from a Tied hash.  Documenting how exists / defined
772 true maps to the database (and WHERE clauses) would also help.
773
774 The ut_ methods should ask the dbdef for a default length.
775
776 ut_sqltype (like ut_varchar) should all be defined
777
778 A fallback check method should be provided whith uses the dbdef.
779
780 The ut_money method assumes money has two decimal digits.
781
782 The Pg money kludge in the new method only strips `$'.
783
784 The ut_phonen method assumes US-style phone numbers.
785
786 The _quote function should probably use ut_float instead of a regex.
787
788 All the subroutines probably should be methods, here or elsewhere.
789
790 =head1 SEE ALSO
791
792 L<FS::dbdef>, L<FS::UID>, L<DBI>
793
794 Adapter::DBI from Ch. 11 of Advanced Perl Programming by Sriram Srinivasan.
795
796 =head1 HISTORY
797
798 ivan@voicenet.com 97-jun-2 - 9, 19, 25, 27, 30
799
800 DBI version
801 ivan@sisd.com 97-nov-8 - 12
802
803 cleaned up, added autoloaded $self->any_field calls, moved DBI login stuff
804 to FS::UID
805 ivan@sisd.com 97-nov-21-23
806
807 since AUTO_INCREMENT is MySQL specific, use my own unique number generator
808 (again)
809 ivan@sisd.com 97-dec-4
810
811 untaint $user in unique (web demo hack...bah)
812 make unique skip multiple-field unique's from dbdef
813 ivan@sisd.com 97-dec-11
814
815 merge with FS::Search, which after all was just alternate constructors for
816 FS::Record objects.  Makes lots of things cleaner.  :)
817 ivan@sisd.com 97-dec-13
818
819 use FS::dbdef::primary key in replace searches, hopefully for all practical 
820 purposes the string/number problem in SQL statements should be gone?
821 (SQL bites)
822 ivan@sisd.com 98-jan-20
823
824 Put all SQL statments in $statment before we $sth=$dbh->prepare( them,
825 for debugging reasons (warn $statement) ivan@sisd.com 98-feb-19
826
827 (sigh)... use dbdef type (char, etc.) instead of a regex to decide
828 what to quote in _quote (more sillines...)  SQL bites.
829 ivan@sisd.com 98-feb-20
830
831 more friendly error messages ivan@sisd.com 98-mar-13
832
833 Added import of datasrc from FS::UID to allow Pg6.3 to work
834 Added code to right-trim strings read from Pg6.3 databases
835 Modified 'add' to only insert fields that actually have data
836 Added ut_float to handle floating point numbers (for sales tax).
837 Pg6.3 does not have a "SHOW FIELDS" statement, so I faked it 8).
838         bmccane@maxbaud.net     98-apr-3
839
840 commented out Pg wrapper around `` Modified 'add' to only insert fields that
841 actually have data '' ivan@sisd.com 98-apr-16
842
843 dbdef usage changes ivan@sisd.com 98-jun-1
844
845 sub fields now asks dbdef, not database ivan@sisd.com 98-jun-2
846
847 added debugging method ->_dump ivan@sisd.com 98-jun-16
848
849 use FS::dbdef::primary key in delete searches as well as replace
850 searches (SQL still bites) ivan@sisd.com 98-jun-22
851
852 sub dbdef_table ivan@sisd.com 98-jun-28
853
854 removed Pg wrapper around `` Modified 'add' to only insert fields that
855 actually have data '' ivan@sisd.com 98-jul-14
856
857 sub fields croaks on errors ivan@sisd.com 98-jul-17
858
859 $rc eq '0E0' doesn't mean we couldn't delete for all rdbmss 
860 ivan@sisd.com 98-jul-18
861
862 commented out code to right-trim strings read from Pg6.3 databases;
863 ChopBlanks is in UID.pm ivan@sisd.com 98-aug-16
864
865 added code (with Pg wrapper) to deal with Pg money fields
866 ivan@sisd.com 98-aug-18
867
868 added pod documentation ivan@sisd.com 98-sep-6
869
870 ut_phonen got ''; at the end ivan@sisd.com 98-sep-27
871
872 $Log: Record.pm,v $
873 Revision 1.4  1998-11-10 07:45:25  ivan
874 doc clarification
875
876 Revision 1.2  1998/11/07 05:17:18  ivan
877 In sub new, Pg wrapper for money fields from dbdef (FS::Record::fields $table),
878 not keys of supplied hashref.
879
880
881 =cut
882
883 1;
884