For reason beyond my control I must use SDBM_File ( and no other database like package ) to track "request" information. I don't seem to be catching on to how SDBM_File is suppose to work. I am trying to make a package that mimics a RDBMS.
. So I am trying to write subs like create, insert, select, update, delete ... Here's what I got so far.
#!/usr/local/bin/perl -w
use strict;
use Fcntl; # For O_RDWR, O_CREAT, etc.
use SDBM_File;
# Name Null? Type
# ----------------------------------------- -------- -----------------
+-----------
# REQ NOT NULL NUMBER
# INQFILE NOT NULL VARCHAR2(200)
# SENT NOT NULL DATE
# RECVD DATE
# STATUS NUMBER
sub create_table {
my $table_name = shift;
my %h;
tie(%h, 'SDBM_File', $table_name, O_CREAT, 0666)
or die "Couldn't tie SDBM file $table_name: $!; aborting";
untie %h;
}
sub insert {
my $table_name = shift;
my $cols_vals = shift; # ref to hash
my %h;
tie(%h, 'SDBM_File', $table_name, O_WRONLY , 0666)
or die "Couldn't tie SDBM file $table_name: $!; aborting";
%h = %$cols_vals;;
untie %h;
}
sub select_all {
my $table_name = shift;
my %h;
tie(%h, 'SDBM_File', $table_name, O_RDONLY , 0666)
or die "Couldn't tie SDBM file $table_name: $!; aborting";
for my $i ( keys %h ) {
print "$i -> $h{$i}\n";
}
}
my $table = shift;
if (!$table) {
print "usage: $0 <tablename>\n";
exit 1;
}
create_table( $table );
my $rec = {
'REQ' => 123, # NOT NULL NUMBER
'INQFILE' => 'HAHA_THE_FILE.txt', # NOT NULL VARCHAR2(20
+0)
'SENT' => '20031202121200' , # NOT NULL DATE
'RECVD' => undef , # DATE
'STATUS' => 0 # NUMBER
};
insert( $table, $rec );
#select_all ( $table );
$rec = {
'REQ' => 124, # NOT NULL NUMBER
'INQFILE' => '124.txt', # NOT NULL VARCHAR2(200)
'SENT' => '20031202121124' , # NOT NULL DATE
'RECVD' => undef , # DATE
'STATUS' => 0 # NUMBER
};
insert( $table, $rec );
#select_all ( $table );
$rec = {
'REQ' => 125, # NOT NULL NUMBER
'INQFILE' => '125.txt', # NOT NULL VARCHAR2(200)
'SENT' => '20031202121125' , # NOT NULL DATE
'RECVD' => '20030808080000' , # DATE
'STATUS' => 1 # NUMBER
};
insert( $table, $rec );
select_all ( $table );
The problem I am having is that everytime I do a insert the previously inserted record get over written. I just don't understand what I am suppose to do here.
| Plankton: 1% Evil, 99% Hot Gas. |