return '(Cover:' + info.join(',') + ')'
end
+ def read_image(filename)
+ open(filename, 'rb') do |fd|
+ @data = fd.read()
+ end
+ end
+
def to_s
return inspect
end
- def writeImage(outputDir, baseName)
+ def write_image(outputDir, baseName)
filename = baseName + getExt()
open(outputDir + '/' + filename, 'wb') do |fd|
fd.write(@data)
return nil
end
+ def load_author(id)
+ sqlSelect = "SELECT grouping, reading, sort FROM Authors WHERE id=$1"
+ args = [id]
+ @conn.exec_params(sqlSelect, args) do |rs|
+ if rs.ntuples != 1
+ raise "Expected 1 row for " + id + " but got " + rs.ntuples + ": " + sqlSelect
+ end
+ row = rs[0]
+ return Author.new(row['grouping'], row['reading'], row['sort'])
+ end
+ end
+
def store_author(author)
id = find_author(author)
if nil == id
return find_author(author)
end
+ def load_book(id)
+ sql = "SELECT author, cover, description, path, series, title, volume FROM Books WHERE id=$1;"
+ book = nil
+
+ begin
+ @conn.exec_params(sql, [id]) do |rs|
+ if 1 != rs.ntuples
+ raise 'Expected one row in Books for id ' + id + ', but found ' + rs.length + '.'
+ return nil
+ end
+ row = rs[0]
+
+ book = Book.new()
+ book.author = load_author(row['author'])
+ book.cover = load_cover(row['cover'])
+ book.description = row['description']
+ book.path = row['path']
+ book.series = row['series']
+ book.title = row['title']
+ book.volume = row['volume']
+ end
+ rescue Exception => e
+ puts sql + ": " + id
+ puts e.message
+ end
+
+ return book
+ end
+
def store_book(book)
sql = "INSERT INTO Books (author, cover, description, path, series, title, volume) VALUES ($1, $2, $3, $4, $5, $6, $7);"
end
end
+ def load_cover(id)
+ (efspath, efsname) = construct_efs_path(id)
+ efspath = @basepath + '/' + efspath
+ cover = Cover.new()
+ cover.load_image(efspath + '/' + efsname)
+ return cover
+ end
+
def store_cover(book)
efs_id = nil
cover = book.cover()
FileUtils.mkdir_p(efspath)
- (filepath, mimetype) = cover.writeImage(efspath, efsname)
+ (filepath, mimetype) = cover.write_image(efspath, efsname)
sql = "INSERT INTO efs VALUES ($1, $2)"
begin