加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – SQLite3 :: Database和SQLite3 :: Statement的初始化方

发布时间:2020-12-17 02:13:02 所属栏目:百科 来源:网络整理
导读:我是一名经验丰富的程序员,学习 Ruby(并且喜欢它). 我正在使用SQLite3设置数据库. 为了更好地学习Ruby,我正在追踪SQLite3. 我不明白的是,数据库和语句类的#new代码在哪里. 实际上,我期望不是#new方法,而是#initialize方法. SQLite3::Database.new(file,optio
我是一名经验丰富的程序员,学习 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 )

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

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

感谢您考虑这个问题.

解决方法

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扩展甚至已经编译了调试支持),因此它会跳过它们.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读