Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby SQLite3::Database和SQLite3::语句的初始化方法在哪里_Ruby_Sqlite_Rubygems_Sqlite3 Ruby - Fatal编程技术网

Ruby SQLite3::Database和SQLite3::语句的初始化方法在哪里

Ruby SQLite3::Database和SQLite3::语句的初始化方法在哪里,ruby,sqlite,rubygems,sqlite3-ruby,Ruby,Sqlite,Rubygems,Sqlite3 Ruby,我是一个有经验的程序员,学习Ruby(并且非常喜欢它)。 我正在使用SQLite3建立一个数据库。 为了更好地学习Ruby,我将跟踪SQLite3。 我不明白的是,数据库和语句类的新代码在哪里。 实际上,我期望的不是一个#新方法,而是一个#初始化方法 SQLite3::Database.new(file, options = {}) SQLite3::Statement.new(db, sql) 上述两项声明来自文件。 但在我的代码中,当我试图追踪这个 $db = SQLite3::Datab

我是一个有经验的程序员,学习Ruby(并且非常喜欢它)。 我正在使用SQLite3建立一个数据库。 为了更好地学习Ruby,我将跟踪SQLite3。 我不明白的是,数据库和语句类的新代码在哪里。 实际上,我期望的不是一个#新方法,而是一个#初始化方法

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 )
但同样没有运气。它只是跨过它

我已经搜索了源代码,进行了搜索等,但是我找不到正在调用的初始化方法。他们在哪里

感谢您考虑这个问题。

在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)
同样适用于:


Ruby调试器不知道如何单步执行C函数(假设SQLite3扩展已经通过调试支持编译),因此它跳过了这些函数。

谢谢。但它提出了新的问题。首先,Ruby如何解析“#xxx.new”?例如,它是否首先在Ruby文件中查找#initialize方法,然后在失败时查找“C”代码?第二,C代码是如何链接的?它是SQLite3的gem文件夹中的obj文件还是库?ps(我是stackOverflow新手)-我的上述评论合适吗?还是应该是聊天,甚至是单独的问题?谢谢(我正在研究我的观点!)@WilliamSmith:如果你查看C文件的底部,你会看到将东西粘合在一起的
rb\u define\u方法
调用。C文件被编译到库中,并根据需要动态加载。你应该可以通过谷歌搜索找到一个C扩展教程。评论很好,我们大多数人都很友好(或者至少假装友好)。谢谢你的回复。同时,我相信我在《实用程序员指南》的上述评论中找到了我自己问题的一些答案,在“扩展Ruby:[-感谢stackOverflow,这是一个伟大的社区,也是一个非常酷的实现”。我希望能够成为一个贡献者,而不仅仅是一个消费者。
/* 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)