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....