Friends,

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. (Yes I know I am having to reinvent the wheel, but my boss is a ignorant bureaucrat impervious to logic). 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.

In reply to use SDBM_File like a database by Plankton

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.