Class: Catori::Db

Inherits:
Object
  • Object
show all
Defined in:
lib/catori/Db.rb

Constant Summary collapse

@@db =
nil

Class Method Summary collapse

Class Method Details

.actualizarAlbumFecha(oInfo) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/catori/Db.rb', line 65

def self.actualizarAlbumFecha(oInfo)
	sAlbum=oInfo.album
	sFecha=oInfo.year
	sArtist=oInfo.artist
	sql="UPDATE album SET album_year=? WHERE artist_id=? and album_id=?"
	@@db.execute(sql,sFecha,sArtist.crearSha,sAlbum.crearSha)
end

.actualizarArchivo(oInfo) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/catori/Db.rb', line 72

def self.actualizarArchivo(oInfo)
	sPathId=oInfo.sFile.crearSha();
	sAlbum=oInfo.album.crearSha
	sArtist=oInfo.artist.crearSha
	sSong=oInfo.title.crearSha
	raise "Error con el id de archivo" if (@@db.select_one("SELECT COUNT(*) from file WHERE cd_id=? AND file_id=?",oInfo.cd,sPathId).to_s=="0")
	sql="UPDATE file SET artist_id=?,album_id=?,song_id=? WHERE cd_id=? AND file_id=?"
	@@db.execute(sql,sArtist,sAlbum,sSong,oInfo.cd,sPathId)
end

.conectarObject



12
13
14
15
16
17
18
# File 'lib/catori/Db.rb', line 12

def self.conectar
	if @@db.nil?
		data=self.data_conexion
		@@db=DBI.connect('DBI:Mysql:'+data['database'], data['user'], data['password'])
	end
	@@db
end

.data_conexionObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/catori/Db.rb', line 19

def self.data_conexion
	if(File.exists?(Catori::CONFIG_FILE))
		data={}
		require 'yaml'
		File.open( Catori::CONFIG_FILE ) { |yf| data=YAML::load( yf ) }
	else
		raise "Install the application using catori --install"
	end
	data
end

.llenarAlbum(oInfo) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/catori/Db.rb', line 55

def self.llenarAlbum(oInfo)
	sAlbum=oInfo.album
	sFecha=oInfo.year
	sArtist=oInfo.artist
	if(@@db.select_one("select COUNT(*) from album WHERE artist_id=? AND album_id=?",sArtist.crearSha,sAlbum.crearSha).to_s=="0")
		#puts "Agregar album #{sAlbum}"
		sql="INSERT INTO album (artist_id,album_id,album_name,album_year) VALUES (?,?,?,?)"
		@@db.execute(sql,sArtist.crearSha,sAlbum.crearSha,sAlbum,sFecha)
	end
end

.llenarArtista(oInfo) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/catori/Db.rb', line 47

def self.llenarArtista(oInfo)
	sArtist=oInfo.artist
	if(@@db.select_one("select COUNT(*) from artist WHERE artist_id=?",sArtist.crearSha).to_s=="0")
		#puts "Agregar artista #{sArtist}"
		sql="INSERT INTO artist (artist_id,artist_name) VALUES (?,?)"
		@@db.execute(sql,sArtist.crearSha,sArtist)
	end
end

.llenarCancion(oInfo) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/catori/Db.rb', line 29

def self.llenarCancion(oInfo)
	sSong=oInfo.title
	if(@@db.select_one("select COUNT(*) from song WHERE song_id=?",sSong.crearSha).to_s=="0")
		#puts "Agregar cancion #{sSong}"
		sql="INSERT INTO song (song_id,song_name) VALUES (?,?)"
		@@db.execute(sql,sSong.crearSha,sSong)
	end
	sAlbum=oInfo.album
	sArtist=oInfo.artist
	if(@@db.select_one("select COUNT(*) from album_song WHERE artist_id=? AND album_id=? and song_id=?",sArtist.crearSha,sAlbum.crearSha,sSong.crearSha).to_s=="0")
		#puts "Agregar cancion en album #{sSong}"
		sql="INSERT INTO album_song (artist_id,album_id,song_id,as_track) VALUES (?,?,?,?)"
		@@db.execute(sql, sArtist.crearSha, sAlbum.crearSha, sSong.crearSha, oInfo.tracknumber)
	elsif(@@db.select_one("SELECT COUNT(*) from album_song WHERE as_track!=? and artist_id=? and album_id=? and song_id=?",oInfo.tracknumber, sArtist.crearSha, sAlbum.crearSha, sSong.crearSha))
		sql="UPDATE album_song SET as_track=? WHERE artist_id=? and album_id=? and song_id=?"
		@@db.execute(sql,oInfo.tracknumber,sArtist.crearSha, sAlbum.crearSha, sSong.crearSha)
	end
end