Class: ItunesController::SQLite3DatabaseBackend

Inherits:
DatabaseBackend show all
Defined in:
lib/itunesController/database/sqlite3_backend.rb

Instance Method Summary collapse

Constructor Details

#initialize(dbPath = nil) ⇒ SQLite3DatabaseBackend

Returns a new instance of SQLite3DatabaseBackend.



32
33
34
35
36
37
38
39
40
41
# File 'lib/itunesController/database/sqlite3_backend.rb', line 32

def initialize(dbPath=nil)
    if (dbPath==nil)
        dbPath=ItunesController::Platform::getUserHomeDir()+"/.itunesController/database.db"
    end
    if (!File.directory?(File.dirname(dbPath)))
        FileUtils::mkdir_p(File.dirname(dbPath))
    end
    ItunesController::ItunesControllerLogging::info("Database path #{dbPath}")
    @db=SQLite3::Database.new( dbPath )
end

Instance Method Details

#closeObject



63
64
65
# File 'lib/itunesController/database/sqlite3_backend.rb', line 63

def close()
    @db.close()
end

#execute(sql) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/itunesController/database/sqlite3_backend.rb', line 55

def execute(sql)
    begin
        return @db.execute(sql)
    rescue SQLite3::ConstraintException => e
        raise ItunesController::DatabaseConstraintException, e.message
    end
end

#executeStatement(stmt, *args) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/itunesController/database/sqlite3_backend.rb', line 47

def executeStatement(stmt,*args)
    begin
        return stmt.execute(*args)
    rescue SQLite3::ConstraintException => e
        raise ItunesController::DatabaseConstraintException, e.message
    end
end

#prepare(sql) ⇒ Object



43
44
45
# File 'lib/itunesController/database/sqlite3_backend.rb', line 43

def prepare(sql)
   return @db.prepare(sql)         
end