4

私は経験豊富なプログラマーで、Ruby を学んでいます (そしてとても気に入っています)。SQLite3 を使用してデータベースのセットアップに取り組んでいます。Ruby をよりよく学ぶために、SQLite3 にトレースしています。私が理解していないのは、Database クラスと Statement クラスの #new のコードがどこにあるのかということです。実際には、#new メソッドではなく、#initialize メソッドを期待しています。

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

上記の 2 つのステートメントは、ドキュメントからのものです。しかし、これをトレースしようとすると、私のコードでは

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

踏み越えるだけです。

その後、トレースしようとすると

#$db.execute 

Database.rb ファイルの #execute メソッドに入りますが、#prepare メソッドを呼び出してステップインしようとします。

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

しかし、再び運がありません。それをまたぐだけです。

ソース コードを調べたり、検索を行ったりしましたが、呼び出されている初期化メソッドが見つかりません。彼らはどこにいる ?

この質問を検討していただきありがとうございます。

4

1 に答える 1

2

initializeメソッド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 拡張機能がデバッグ サポート付きでコンパイルされていると仮定して)、それらをスキップします。

于 2012-03-30T06:25:56.723 に答える