0

웹 페이지에서 html을 가져와 활성 레코드 개체에 저장하려고 할 때 오류가 발생합니다. 내가받는 메시지는 Unclosed quotation mark after the character string입니다. Ruby에 함수가 있습니까? 또는 데이터베이스에 레코드를 저장하기 전에 발생하는 인스턴스를 확인하고 수정하는 방법이 있습니까? TinyTDS에서 전체 오류가 나는 충분한 정보를 추가하지 않았 몰랐Ruby에서 '문자열 뒤에 숨겨진 인용 부호'를 처리하는 방법은 무엇입니까?

ActiveRecord::StatementInvalid: TinyTds::Error: Unclosed quotation mark after the character string ' 

업데이트

내 사과 ... 다음과 같습니다. 기꺼이 요청을 추가하겠습니다. 로그를 시작하고 "내 데이터 이스케이프"에 대한 부분부터 시작하겠습니다. 오류가 발생하는 외부 소스의 HTML입니다. 그래서 그 시점으로 아마도 제가 처음 질문으로 돌아가는 것이 겠지요. 그 질문은 닫히지 않은 인용 부호가있는 곳을 찾은 다음 그것을 수정하는 방법에 대해 어떻게 생각합니까? my_string.encode!('UTF-8') :

SQL (27.8ms) BEGIN TRANSACTION 
    SQL (2.8ms) EXEC sp_executesql N'UPDATE [school_player_scrapes] SET [biography_text] = @0, [headshot_url] = @1, [updated_at] = @2 WHERE [school_player_scrapes].[id] = @3; SELECT @@ROWCOUNT AS AffectedRows', N'@0 nvarchar(max), @1 nvarchar(4000), @2 datetime, @3 int', @0 = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> 
<html><body><td class="sm PlayerBioArticleContent" colspan="2"> 
       <p><strong><span style="font-family: arial, helvetica, sans-serif; font-size: small;">Butte College:�</span></strong><span style="font-family: arial, helvetica, sans-serif; font-size: small;">Attended Butte CC in 2015.</span></p> 
<p><strong><span style="font-family: arial, helvetica, sans-serif; font-size: small;">High School:�</span></strong><span style="font-family: arial, helvetica, sans-serif; font-size: small;">Attended North Little Rock High Scchool . . . Ranked a two-star recruit by Scout.com and 247 Sports . . . Recruited by schools such as Auburn, Georgia Tech and Minnesota among others.�</span></p> 
      </td></body></html> 
', @1 = N'http://image.cdnllnwnl.xosnetwork.com/pics33/200/IQ/IQQZSKTMHZNYBCD.20160807033143.jpg', @2 = '12-15-2016 08:24:50.657', @3 = 7444 [["biography_text", "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body><td class=\"sm PlayerBioArticleContent\" colspan=\"2\">\n\t\t\t\t<p><strong><span style=\"font-family: arial, helvetica, sans-serif; font-size: small;\">Butte College:\xA0</span></strong><span style=\"font-family: arial, helvetica, sans-serif; font-size: small;\">Attended Butte CC in 2015.</span></p>\r\n<p><strong><span style=\"font-family: arial, helvetica, sans-serif; font-size: small;\">High School:\xA0</span></strong><span style=\"font-family: arial, helvetica, sans-serif; font-size: small;\">Attended North Little Rock High Scchool . . . Ranked a two-star recruit by Scout.com and 247 Sports . . . Recruited by schools such as Auburn, Georgia Tech and Minnesota among others.\xA0</span></p>\n\t\t\t</td></body></html>\n"], ["headshot_url", "http://image.cdnllnwnl.xosnetwork.com/pics33/200/IQ/IQQZSKTMHZNYBCD.20160807033143.jpg"], ["updated_at", Thu, 15 Dec 2016 08:24:50 EST -05:00], ["id", 7444]] 
TinyTds::Error: Unclosed quotation mark after the character string '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> 
<html><body><td class="sm PlayerBioArticleContent" colspan="2"> 
       <p><strong><span style="font-family: arial, helvetica, sans-serif; font-size: small;">Butte College:'.: EXEC sp_executesql N'UPDATE [school_player_scrapes] SET [biography_text] = @0, [headshot_url] = @1, [updated_at] = @2 WHERE [school_player_scrapes].[id] = @3; SELECT @@ROWCOUNT AS AffectedRows', N'@0 nvarchar(max), @1 nvarchar(4000), @2 datetime, @3 int', @0 = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> 
<html><body><td class="sm PlayerBioArticleContent" colspan="2"> 
       <p><strong><span style="font-family: arial, helvetica, sans-serif; font-size: small;">Butte College:�</span></strong><span style="font-family: arial, helvetica, sans-serif; font-size: small;">Attended Butte CC in 2015.</span></p> 
<p><strong><span style="font-family: arial, helvetica, sans-serif; font-size: small;">High School:�</span></strong><span style="font-family: arial, helvetica, sans-serif; font-size: small;">Attended North Little Rock High Scchool . . . Ranked a two-star recruit by Scout.com and 247 Sports . . . Recruited by schools such as Auburn, Georgia Tech and Minnesota among others.�</span></p> 
      </td></body></html> 
', @1 = N'http://image.cdnllnwnl.xosnetwork.com/pics33/200/IQ/IQQZSKTMHZNYBCD.20160807033143.jpg', @2 = '12-15-2016 08:24:50.657', @3 = 7444 
    SQL (0.8ms) IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION 
Performed ScrapeSchoolRosterJob from Sidekiq(high_priority) in 2787.93ms 
ActiveRecord::StatementInvalid: TinyTds::Error: Unclosed quotation mark after the character string '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> 
<html><body><td class="sm PlayerBioArticleContent" colspan="2"> 
       <p><strong><span style="font-family: arial, helvetica, sans-serif; font-size: small;">Butte College:'.: EXEC sp_executesql N'UPDATE [school_player_scrapes] SET [biography_text] = @0, [headshot_url] = @1, [updated_at] = @2 WHERE [school_player_scrapes].[id] = @3; SELECT @@ROWCOUNT AS AffectedRows', N'@0 nvarchar(max), @1 nvarchar(4000), @2 datetime, @3 int', @0 = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> 
<html><body><td class="sm PlayerBioArticleContent" colspan="2"> 
       <p><strong><span style="font-family: arial, helvetica, sans-serif; font-size: small;">Butte College:�</span></strong><span style="font-family: arial, helvetica, sans-serif; font-size: small;">Attended Butte CC in 2015.</span></p> 
<p><strong><span style="font-family: arial, helvetica, sans-serif; font-size: small;">High School:�</span></strong><span style="font-family: arial, helvetica, sans-serif; font-size: small;">Attended North Little Rock High Scchool . . . Ranked a two-star recruit by Scout.com and 247 Sports . . . Recruited by schools such as Auburn, Georgia Tech and Minnesota among others.�</span></p> 
      </td></body></html> 
', @1 = N'http://image.cdnllnwnl.xosnetwork.com/pics33/200/IQ/IQQZSKTMHZNYBCD.20160807033143.jpg', @2 = '12-15-2016 08:24:50.657', @3 = 7444 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activerecord-sqlserver-adapter-4.2.3/lib/active_record/connection_adapters/sqlserver/database_statements.rb:336:in `each' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activerecord-sqlserver-adapter-4.2.3/lib/active_record/connection_adapters/sqlserver/database_statements.rb:336:in `handle_to_names_and_values_dblib' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activerecord-sqlserver-adapter-4.2.3/lib/active_record/connection_adapters/sqlserver/database_statements.rb:325:in `handle_to_names_and_values' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activerecord-sqlserver-adapter-4.2.3/lib/active_record/connection_adapters/sqlserver/database_statements.rb:300:in `_raw_select' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activerecord-sqlserver-adapter-4.2.3/lib/active_record/connection_adapters/sqlserver/database_statements.rb:295:in `block in raw_select' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `block in log' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract_adapter.rb:460:in `log' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activerecord-sqlserver-adapter-4.2.3/lib/active_record/connection_adapters/sqlserver/database_statements.rb:295:in `raw_select' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activerecord-sqlserver-adapter-4.2.3/lib/active_record/connection_adapters/sqlserver/database_statements.rb:244:in `sp_executesql' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activerecord-sqlserver-adapter-4.2.3/lib/active_record/connection_adapters/sqlserver/database_statements.rb:19:in `exec_query' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:95:in `exec_update' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activerecord-sqlserver-adapter-4.2.3/lib/active_record/connection_adapters/sqlserver/database_statements.rb:39:in `exec_update' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:114:in `update' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `update' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/relation.rb:88:in `_update_record' 
... 57 levels... 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:337:in `call' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:337:in `block in simple' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:92:in `call' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:92:in `_run_callbacks' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:734:in `_run_perform_callbacks' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:81:in `run_callbacks' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activejob-4.2.0/lib/active_job/execution.rb:31:in `perform_now' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/activejob-4.2.0/lib/active_job/execution.rb:16:in `perform_now' 
    from (irb):2 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/commands/console.rb:110:in `start' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/commands/console.rb:9:in `start' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:68:in `console' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!' 
    from /home/deploy/bane/shared/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>' 
    from bin/rails:4:in `require' 
+1

주어진 노력을 기울이지 않아도 오류에 대한 명확한 설명이 없으며 원본 콘텐츠에 대한 참조가 제공되지 않으며 질문 자체가 즉시 '+ 1'을받습니다. 나는 사회자의주의를 끌기 위해 그것을 표시했다. – mudasobwa

+0

전체 오류 로그를 보여주십시오. 또한 로그에 불평하는 곳을 표시합니다. – uday

+1

이것이 데이터베이스 질문 인 경우 답은 거의 항상 ** 데이터를 올바르게 벗어납니다 **. 자리 표시 자 값으로 준비된 문을 사용하지 않고 모든 문제의 원인이 될 가능성이 큽니다. – tadman

답변

1

나는이 문제를 해결 할 수 있었다 방법 오류 로그에 다음 코드를 수행하여 내가 UTF-8ISO-8859-1에서 구하려고 한 내 문자열로 변환되었다. 이로 인해 발생했거나 발행 한 잘못된 문자가 제거되었습니다.