【问题标题】:How to escape the less than symbol for SQL insertion in DataMapper如何在 DataMapper 中转义 SQL 插入的小于符号
【发布时间】:2013-07-29 18:48:38
【问题描述】:

我试图在其中插入一个带有< 符号的值,但每次它只是切断字符串的其余部分:

winecheap = Tag.first_or_create(:tag_type => tt, :value => "Wine & Spirits <$65")

  DEBUG -  (0.000828) SELECT "uuid", "created_at", "updated_at", "value", "es_indexed", "tag_type_uuid" FROM "tags" WHERE ("tag_type_uuid" = 'a932f2c1-e8bb-44cc-9120-791097474b77' AND "value" = 'Wine & Spirits <$65') ORDER BY "uuid" LIMIT 1
  DEBUG -  (0.001027) INSERT INTO "tags" ("created_at", "updated_at", "uuid", "value", "es_indexed", "tag_type_uuid") VALUES ('2013-07-29T20:03:32+00:00', '2013-07-29T20:03:32+00:00', '76a5b023-41b6-4e6b-9f2b-e9fbe51ee1b0', 'Wine & Spirits ', FALSE, 'a932f2c1-e8bb-44cc-9120-791097474b77')
 => #<Tag @created_at=Mon, 29 Jul 2013 20:03:32 +0000 @updated_at=Mon, 29 Jul 2013 20:03:32 +0000 @uuid=#<UUID:0x3fdb200f4e6c UUID:76a5b023-41b6-4e6b-9f2b-e9fbe51ee1b0> @value="Wine & Spirits " @es_indexed=false @tag_type_uuid=#<UUID:0x3fdb1f2b8290 UUID:a932f2c1-e8bb-44cc-9120-791097474b77>>
1.9.3-p286 :079 
> winecheap.value
 => "Wine & Spirits "

这是怎么回事?

【问题讨论】:

    标签: sql datamapper


    【解决方案1】:

    这工作正常。

    repository(:default).adapter.execute('UPDATE "tags" SET "value"=\'Wine & Spirits <$65\' WHERE "uuid" = \'0cfa3a0c-adfb-4b67-92af-a7ee46d9289c\'')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-07
      • 2012-08-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多