尝试从网页中获取HTML并将其保存到我的活动记录对象时,我会遇到错误。我收到的消息是Unclosed quotation mark after the character string
。Ruby中是否有一个函数,或者需要进行检查,然后纠正在将记录保存到数据库之前发生的情况?TinyTDS的完整错误在下面...
ActiveRecord::StatementInvalid: TinyTds::Error: Unclosed quotation mark after the character string '
update
我的歉意,没有意识到我没有添加足够的信息。我会很高兴地添加任何请求。让我从日志开始,也要从正确地"逃脱我的数据"的一部分 - 它是从外部来源出发的html。因此,我想也许我要回到我的最初问题,这是我如何找到未锁定的引号在哪里,然后纠正它?
错误日志
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">ntttt<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>rn<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>nttt</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'
我能够纠正此问题的方式是通过执行以下代码来转换我试图从ISO-8859-1
保存到UTF-8
的字符串:my_string.encode!('UTF-8')
。这删除了引起和发行的无效字符。