English 中文(简体)
检查两条row行是否平等最容易的方法是,使用gro鱼 s。
原标题:what is the easiest way to check for the equality of two db rows using groovy sql
  • 时间:2011-10-20 01:36:34
  •  标签:
  • groovy

是否有简单、简明的方式来检查某一表的两行是否包含所有栏目中的相同数据?

最佳回答

我对此进行了试验,但似乎最明显的解决办法是:

// get an Sql instance
def db = [url: jdbc:hsqldb:mem:testDB , user: sa , password:  ,
    driver: org.hsqldb.jdbcDriver ]
def sql = Sql.newInstance(db.url, db.user, db.password, db.driver)

// Get 2 rows
GroovyRowResults row1 = sql.firstRow("select * from user where id = 4")
GroovyRowResults row2 = sql.firstRow("select * from user where email =  me@example.org ")

// compare them
boolean identical = row1.equals(row2)
问题回答

具体来说,并不是格罗莫夫,但我是这样做的:

db.firstRow("SELECT COUNT(DISTINCT CONCAT(city,state,zip)) FROM Candidates WHERE id IN (1,2)")[0] == 0




相关问题
Groovy - how to exit each loop?

I m new to Grails/Groovy and am trying to find a node in a an xml file; I ve figured out how to iterate over all of them, but I want to exit the loop when the target node is found. I ve read that ...

Eclipse Spring Builder set properties with Groovy beans

I typically use groovy to construct simple bean but the Spring IDE plugin to eclipse fails to build when I try to set a property that is generated by groovy without an explicit setter. For example, ...

How can I get this snippet to work?

I d like to port a little piece of code from Ruby to Groovy, and I m stuck at this: def given(array,closure) { closure.delegate = array closure() } given([1,2,3,4]) { findAll { it > 4} ...

Changing the value in a map in Groovy

This is about a very basic program I m writing in Groovy. I have defined a map inside a method: def addItem() { print("Enter the item name: ") def itemName = reader.readLine() print(...

Is functional Clojure or imperative Groovy more readable?

OK, no cheating now. No, really, take a minute or two and try this out. What does "positions" do? Edit: simplified according to cgrand s suggestion. (defn redux [[current next] flag] [(if flag ...

热门标签