Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.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 sqlite错误';确保在insert_行中';:未定义的局部变量或方法';stmt&x27;_Ruby_Sqlite_Exception_Prepare_Sqlbindparameter - Fatal编程技术网

ruby sqlite错误';确保在insert_行中';:未定义的局部变量或方法';stmt&x27;

ruby sqlite错误';确保在insert_行中';:未定义的局部变量或方法';stmt&x27;,ruby,sqlite,exception,prepare,sqlbindparameter,Ruby,Sqlite,Exception,Prepare,Sqlbindparameter,我在dbmgr ruby类中有以下方法,我在循环中使用该方法将csv中的数据插入sqlite3数据库: def insert_row(aRow) begin @db = SQLite3::Database.open("#{@dbn}") rhash = aRow.row_hash stm = @db.prepare("INSERT INTO programs (programName, episodeName) VALUES (? , ? )")

我在dbmgr ruby类中有以下方法,我在循环中使用该方法将csv中的数据插入sqlite3数据库:

  def insert_row(aRow)
    begin
    @db = SQLite3::Database.open("#{@dbn}")
    rhash = aRow.row_hash

    stm = @db.prepare("INSERT INTO programs (programName, episodeName) VALUES (? , ? )")
        stm.bind_param(1, '#{rhash["Program"]}' )
        stm.bind_param(2, '#{rhash["Episode Name"]}' )
        stmt.execute()
        programId = @db.last_insert_row_id


     rescue SQLite3::Exception => e
        puts "Exception occured"
        puts e.message
        puts e.backtrace

    ensure
        stmt.close if stmt
        @db.close if @db

    end #db
当我在第一次插入后在控制台上执行此操作时,会出现以下错误:

  `ensure in insert_row': undefined local variable or method `stmt' for #<Dbmgr:0x007f9511050188> (NameError)
`Sure in insert_row':未定义的局部变量或#的方法'stmt'(NameError)
起初,我没有使用RubyforSQLite的prepare和bind_参数特性。但是,在我插入生成的异常的文本中的一些字符(如“”)之后,我在某个地方读到,使用bind_参数将清除输入,因此我使用bind_参数。但是现在我得到了这个错误

有人能帮忙吗

谢谢

stm=@db.prepare(“插入到程序(程序名,代码名)值(?,)”)
stm.bind_参数(1,'.{rhash[“程序”]}')
stm.bind_参数(2,,{rhash[“集名”]})

stmt.execute()#天哪。这就是它,感谢XCode没有自动保存我对代码的编辑。哈哈,现在我觉得这样问很愚蠢。
stm = @db.prepare("INSERT INTO programs (programName, episodeName) VALUES (? , ? )")
    stm.bind_param(1, '#{rhash["Program"]}' )
    stm.bind_param(2, '#{rhash["Episode Name"]}' )
    stmt.execute() # <-- you're referring to stmt instead of stm here
    programId = @db.last_insert_row_id