Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

database without mysql

by darkblackblue (Novice)
on Dec 16, 2017 at 14:23 UTC ( #1205678=perlmeditation: print w/replies, xml ) Need Help??


2017-12-30 Original content restored by Athanasius:

hi , I was asked "how to create database without mysql or cvs" befeor a few week ago. Thanks for answers. I tried and create a program. Maybe you want to add new properties for good program. (there aren't some properties. example delete record from table , or update data in table , ....)
#!/use/perl/bin print " #create database: CREATE TABLE dbismi\n #create database with +table: CREATE TABLE dbname tablename\n #veritaban&#305; olu&#351;turm +a ve table ekleme : CREATE TABLE dbname tablename colonname colonname + int chartext #delete database : DELETE dbname \n #delete table: DELE +TE dbname tabloname \n #insert values : INSERT INTO dbname tablename +colonname value colonname value colonname value \n #show database : F +IND ALL_DATABASES \n #show all tables in databases : FIND dbismi \n # +show values in table in database : SHOW dbname tablename \n #search v +alue in table and show record: SEARCH dbname tablename key_word\n" ; use utf8; binmode(STDOUT,":utf8"); if((uc(@ARGV[0]) eq 'CREATE') && uc(@ARGV[1]) eq 'TABLE' ){ chomp(my $dir = @ARGV[2]); my $dir = "../Desktop/$dir"; mkdir( $dir ,0755); print "Directory created successfully\n"; if(@ARGV[3]){ my $d_p = @ARGV[2]; my $file_name = @ARGV[3].".txt"; my $file = "../Desktop/$d_p/$file_name"; unless(open FILE, '>'.$file) { die "\nUnable to create $file\n"; } } my $numArgs = $#ARGV + 1; foreach my $argnum (4 .. (4+($#ARGV-4)*1/2)) { print FILE "$ARGV[$argnum]\t"; } print FILE "\n"; close FILE; } if((uc(@ARGV[0]) eq 'DELETE') ){ my $numArgs = @ARGV ; if($numArgs == 2 ){ my $del= @ARGV[1].'/*.txt'; my $deleted = unlink glob $del; print "$deleted files were removed\n"; my $dir = '../Desktop/'.@ARGV[1].''; rmdir( $dir ) or die "Couldn't remove $dir directory, $!"; print "Directory removed successfully\n"; } if($numArgs eq 3 ){ my $del= @ARGV[1].'/'.@ARGV[2].'.txt'; my $deleted = unlink $del; } } if((uc(@ARGV[0]) eq 'INSERT') and uc(@ARGV[1]) eq 'INTO' ){ my $filename = @ARGV[2].'/'.@ARGV[3].'.txt'; open(my $fh, '>>', $filename) or die "Could not open file '$filena +me' $!"; my $numArgs = $#ARGV + 1; foreach my $argnum (5 .. $#ARGV) { if($argnum%2 eq 0){ } else{ print $fh "$ARGV[$argnum]\t"; } } print $fh "\n"; close $fh; #print "done\n"; } if((uc(@ARGV[0]) eq 'FIND') ){ if(uc(@ARGV[1]) eq 'ALL_DATABASES' ){ my $path = '../Desktop'; die "Please specify which directory to search" unless -d $path +; my $num =1; opendir( my $DIR, $path ); while ( my $entry = readdir $DIR ) { next unless -d $path . '/' . $entry; next if $entry eq '.' or $entry eq '..'; print "$num ) $entry\n"; $num++; } closedir $DIR; } if(uc(@ARGV[1]) ne 'ALL_DATABASES' ){ my $dir = '../Desktop/'.@ARGV[1].''; opendir DIR,$dir; my @dir = readdir(DIR); close DIR; my $temp=1; foreach(@dir){ if (-f $dir . "/" . $_ ){ print "$temp ) Table : ".$_."\n"; } } } } if(uc(@ARGV[0]) eq 'SHOW'){ my $file =@ARGV[1].'/'.@ARGV[2].'.txt'; open my $info, $file or die "Could not open $file: $!"; while( my $line = <$info>) { print $line; } close $info; } if((uc(@ARGV[0]) eq 'SEARCH') ){ my $file =@ARGV[1].'/'.@ARGV[2].'.txt'; my $str =@ARGV[3]; chomp($str); open(my $file, '<', $file) or die "Could not open file '$filen' $!"; while(my $line = <$file>){ if($line=~/$str/){ print $line; } } close ($file); }

Replies are listed 'Best First'.
Re: database without mysql
by marto (Archbishop) on Dec 16, 2017 at 18:14 UTC

    Just in case you haven't seen it, you may want to take a look at DBD::SQLite:

    "DBD::SQLite is a Perl DBI driver for SQLite, that includes the entire thing in the distribution. So in order to get a fast transaction capable RDBMS working for your perl project you simply have to install this module, and nothing else."

Re: database without mysql <applause>
by erix (Parson) on Dec 16, 2017 at 14:43 UTC

    What is cvs? Did you mean csv? I can see why you want to avoid oracle's mysql but why avoid csv (which is just a text format)?

    As so often, the question becomes: what are you trying to achieve? And what do the intended queries look like?

    I'd just install postgres [1], or at least use the DBI module with DBD's, and maybe csv text files are good enough. (I had some fun putting together Re^3: perl create database with folder system )


      I edited (cvs to csv). Yeah it can make DBI simple.There are a lot of packet for that and you can use sql comments for that. But I research , how to make folder and txt files. It was my post (perl create database with folder).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://1205678]
Approved by herveus
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2018-07-17 22:49 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (379 votes). Check out past polls.