首页 文章

SQLite3 :: Database和SQLite3 :: Statement的初始化方法在哪里?

提问于
浏览
4

我是一名经验丰富的程序员,学习Ruby(并且喜欢它) . 我正在使用SQLite3设置数据库 . 为了更好地学习Ruby,我正在追踪SQLite3 . 我不明白的是,数据库和语句类的#new代码在哪里 . 实际上,我期望不是#new方法,而是#initialize方法 .

SQLite3::Database.new(file, options = {})
SQLite3::Statement.new(db, sql)

以上两个陈述来自文档 . 但在我的代码中,当我试图追踪到这一点

$db = SQLite3::Database.new"MyDBfile"

它只是跨过了 .

然后,当我试图追踪到

#$db.execute

我确实进入了Database.rb文件中的#execute方法,但是它调用#prepare方法,我尝试进入

stmt = SQLite3::Statement.new( self, sql )

但又没有运气 . 它只是跨过它 .

我已经搜索了源代码,完成了搜索等但我找不到正在调用的初始化方法 . 他们在哪 ?

感谢您考虑这个问题 .

1 回答

  • 2

    initialize method for SQLite3::Database在C中实现:

    /* call-seq: SQLite3::Database.new(file, options = {})
     *
     * Create a new Database object that opens the given file. If utf16
     * is +true+, the filename is interpreted as a UTF-16 encoded string.
     *
     * By default, the new database will return result rows as arrays
     * (#results_as_hash) and has type translation disabled (#type_translation=).
     */
    static VALUE initialize(int argc, VALUE *argv, VALUE self)
    

    同样适用于SQLite3::Statement

    /* call-seq: SQLite3::Statement.new(db, sql)
     *
     * Create a new statement attached to the given Database instance, and which
     * encapsulates the given SQL text. If the text contains more than one
     * statement (i.e., separated by semicolons), then the #remainder property
     * will be set to the trailing text.
     */
    static VALUE initialize(VALUE self, VALUE db, VALUE sql)
    

    Ruby调试器不知道如何进入C函数(假设SQLite3扩展甚至已经编译了调试支持),因此它会跳过它们 .

相关问题