1

一旦我添加代码来访问我的 .sqlite 数据库,我就会收到一个奇怪的错误:

in 'total': uninitialized constant Test2::SQLite (NameError)

我的代码如下:

测试1.rb

require_relative 'Test2.rb'

co = Test2.new()
price = co.total

测试2.rb

require 'sqlite3'

class Test2

    def initialize()
            @items = []
    end

    def total()
        db = SQLite::Database.open "Database.sqlite"
        db.close()
        return 0
    end
end
4

1 回答 1

0

SQLite模块不存在,但它被命名SQLite3检查文档):

require 'sqlite3'

class Test2

    def initialize()
            @items = []
    end

    def total()
        db = SQLite3::Database.open "Database.sqlite"
        db.close()
        return 0
    end
end
于 2012-08-23T09:35:48.477 回答