0

我在数据导入配置文件的实体标签中尝试了以下 SQL:

<entity name="Page" dataSource="a1" query="SELECT &amp;apos;26484-&amp;apos;&amp;amp;`book`.id&amp;amp;&amp;apos;-&amp;apos;&amp;amp;`book`.page&amp;amp;&amp;apos;-&amp;apos;&amp;amp;`book`.part AS PageID, `book`.id AS pid, `book`.nass AS Content, `book`.part AS Part, `book`.page AS PageNum FROM `book` ORDER BY `book`.id, `book`.page">

Sql 查询包含的字符应在 xml 中转义,' and &. 但是,我在日志中收到以下错误:

 DocBuilder     Exception while processing: Page document : SolrInputDocument(fields: []):org.apache.solr.handler.dataimport.DataImportHandlerException: Unable to execute query: SELECT '26484-'&`book`.id&'-'&`book`.page&'-'&`book`.part AS PageID,​ `book`.id AS pid,​ `book`.nass AS Content,​ `book`.part AS Part,​ `book`.page AS PageNum FROM `book` ORDER BY `book`.id,​ `book`.page Processing Document # 1 

DataImporter    Full Import failed:java.lang.RuntimeException: java.lang.RuntimeException: org.apache.solr.handler.dataimport.DataImportHandlerException: Unable to execute query: SELECT '26484-'&`book`.id&'-'&`book`.page&'-'&`book`.part AS PageID,​ `book`.id AS pid,​ `book`.nass AS Content,​ `book`.part AS Part,​ `book`.page AS PageNum FROM `book` ORDER BY `book`.id,​ `book`.page Processing Document # 1 

我使用 jdbc 驱动程序。

当我尝试从 SQL 查询中删除连接时,删除转义字符时,我没有收到此错误,但我收到了有关重复唯一键的 solrWriter 警告。我理解这个警告。但是,我怎样才能编写使用上面显示的 Sql 查询?

4

1 回答 1

2
  1. 不需要转义单引号,'直接放入查询即可。

  2. &每个转义字符都需要A。所以你需要&amp;apos;&amp;&apos;.

破坏您的查询的事实应该是(2)。

<entity name="Page" dataSource="a1" query="SELECT &amp;'26484-&amp;'&amp;&amp;`book`.id&amp;&amp;&amp;'-&amp;'&amp;&amp;`book`.page&amp;&amp;&amp;'-&amp;'&amp;&amp;`book`.part AS PageID, `book`.id AS pid, `book`.nass AS Content, `book`.part AS Part, `book`.page AS PageNum FROM `book` ORDER BY `book`.id, `book`.page">
于 2014-10-09T07:42:46.013 回答