create_base function

This commit is contained in:
Difrex 2014-04-28 00:04:16 +04:00
parent fa8335b803
commit a3f935330e
2 changed files with 47 additions and 22 deletions

View File

@ -5,11 +5,58 @@ use DBI;
sub new { sub new {
my $class = shift; my $class = shift;
# Get home dir
my $home = $ENV{HOME};
my $self = { my $self = {
_home => $home;
}; };
bless $self, $class; bless $self, $class;
return $self; return $self;
} }
sub connect {
my ($self) = @_;
my $home = $self->{_home};
my $db_file = $home . "/.PM/db.sqlite";
my $dbh = DBI->connect("dbi:SQLite:dbname=$db_file","","");
return $dbh;
}
sub mdo {
my ($self) = @_;
my $dbh = $self->{_dbh};
}
sub create_base {
my ($self) = @_;
my $home = $self->{_home};
my $pm_dir = $home."/.PM/";
# Check dir
if !(-d $pm_dir) {
# Create dirrectory
@mkdir_cmd = ("mkdir", "$pm_dir");
system(@mkdir_cmd) == 0 or die "Cannot create dir $pm_dir: $!\n";
# Create DB file
@createdb_cmd = ("touch", "$pm_dir/db.sqlite");
system(@createdb_cmd) == 0 or die "Cannot create database file: $!\n";
# Create table. TODO: write this
my $dbh = DBI->connect("dbi:SQLite:dbname=$pm_dir/db.sqlite","","");
print "Create database schema\n";
my $q_table = "create table passwords(name VARCHAR(32), resource TEXT, password TEXT)";
return 0;
}
else {
print "Dirrectory is exist!\n";
return 0;
}
}
1; 1;

View File

@ -9,9 +9,6 @@ use Database;
sub new { sub new {
my $class = shift; my $class = shift;
# Get home dir
$home = $ENV{HOME};
my $self = { my $self = {
_home => $home, _home => $home,
}; };
@ -20,23 +17,4 @@ sub new {
return $self; return $self;
} }
sub create_base {
my $self = shift;
my $home = $self->{_home};
my $pm_dir = $home."/.PM/";
# Check dir
if !(-d $pm_dir) {
# Create dirrectory
@cmd_string = ("mkdir", "$pm_dir");
system(@cmd_string) == 0 or die "Cannot create dir $pm_dir: $!\n";
# Create database. TODO: write this
my $dbi = DBI->connect("DBD::sqlite");
}
else {
print "dirrectory is exist!\n";
return 0;
}
}
1; 1;