1

I have the following codes:

# my db connection is here:
# @connection = DriverManager.getConnection("jdbc:hsqldb:file:../db/rdata", "user", "user")

#the method recieves a array of hash {:rev,:time,:path,:result}
def create(list)
    st=@connection.createStatement()
    sql=""
    list.each do |i|
        sql.concat("INSERT INTO RESULTS_LOGIN (REVISION, TIMESTAMP, ARCHIVEPATH, RESULTS) VALUES (#{i[:rev]},'#{i[:time]}','#{i[:path]}','#{i[:result]}');\n")
    end
    p sql.lines.to_a.size
    st.execute(sql)
    st.close
end  

Problem:

The sql.lines.to_a.size is 128, which means I have 128 rows to be inserted. However, after rerunning for many times, I found that everytime I got different rows in the db. For example, this time the RESULT_LOGIN table has 114 rows, and next time it was 99.... There are also successful runs, which made 128 rows in the table.

I can't understand why such thing happens. No errors, no exceptions, and what's strange is that in my code there is a method right after the "create" method, whcih executes "select * from RESULTS_LOGIN" and print it, like this:

create(list) # insert rows
read_all # print all rows  

Everytime the "read_all" right after "create" prints out 128 rows and the correct data; However, if I run read_all seperately after closing and recreate the connection, or browse the db using HSQLDB's GUI management tool, there will be some rows missing....

Community
  • 1
  • 1
Dante WWWW
  • 2,729
  • 1
  • 17
  • 33

1 Answers1

1

For tests such as this, you need to add an extra setting either to URL or as an executed SQL statement. This is to ensure all unwritten data is persisted at the end of the test. See my answer to this question:

something funny with embedded hsql

Community
  • 1
  • 1
fredt
  • 24,044
  • 3
  • 40
  • 61
  • After adding both 'shutdown=true' and 'hsqldb.write_delay=false' the test succeeded for three times ---- which neven happened before. I think that's the problem. Thanks! – Dante WWWW Aug 23 '11 at 01:29