Ejemplo n.º 1
0
        public string IntiDatabase()
        {
            var conn = _sqlService.GetConnection();

            try
            {
                conn.Open();
                var sql = @"create table if not exists books(
bid int unsigned auto_increment,
class varchar(20),
title varchar(20) not null,
publish varchar(20),
pubyear int,
author varchar(20),
price decimal(10, 2),
total int not null,
stock int not null,
primary key(bid)
) default CHARSET=utf8;";
                var cmd = new MySqlCommand(sql, conn);
                cmd.ExecuteNonQuery();

                sql = @"create table if not exists cards(
cid int unsigned auto_increment,
name varchar(20) not null,
company varchar(20),
class varchar(20) not null,
password varchar(20) not null,
primary key(cid)
) default CHARSET=utf8;";
                cmd = new MySqlCommand(sql, conn);
                cmd.ExecuteNonQuery();
                sql = @"create table if not exists records(
rid int unsigned auto_increment,
cid int unsigned not null,
bid int unsigned not null,
borrow date,
back date,
primary key(rid),
foreign key(cid) references cards(cid) on delete cascade ,
foreign key(bid) references books(bid) on delete cascade 
) default CHARSET=utf8;";
                cmd = new MySqlCommand(sql, conn);
                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            finally
            {
                conn.Close();
            }

            return("Initialize Database");
        }
Ejemplo n.º 2
0
 public DatabaseService(ISqlService sqlService)
 {
     _connection = sqlService.GetConnection();
 }
Ejemplo n.º 3
0
 public Repository(ISqlService sqlService)
 {
     Connection = sqlService.GetConnection();
 }