To use SQLite, one first requires the corresponding ruby gem:
require "rubygems" require "sqlite3"
Then, the database can be created:
fName="brol.fdb" if (File::exists?(fName)) sqldb = SQLite3::Database.open( fName ) else sqldb = SQLite3::Database.new( fName ) sqldb.execute <<SQL PRAGMA auto_vacuum = FULL SQL end
In this case only one SQL table is created in the database. The columns correspond to several data associated with each individual Results, and the BLOB corresponding to the Result itself:
sqldb.execute <<SQL CREATE TABLE IF NOT EXISTS dynam_results_1 ( lcName TEXT, scName TEXT, resName TEXT, tensorOrder INTEGER, intId1 INTEGER, intId2 INTEGER, realId1 REAL, realId2 REAL, size INTEGER, result BLOB, PRIMARY KEY(lcName,scName,resName) ); SQL
Finally, one loops on xdb attachment Results. For each load case and Result name, one extracts the Results corresponding to each subcase, and inserts it into the database:
db.attachXdb(xdbFileName) lcNames=db.getAttachmentLcNames(xdbFileName) scNames=db.getAttachmentScNames(xdbFileName) resNames=db.getAttachmentResNames(xdbFileName) lcNames.each do |lcName| resNames.each do |resName| results=db.getAttachmentResults(xdbFileName,lcName,scNames,resName) if (results) then results.each do |key,res| puts key sqldb.execute( "insert or replace into dynam_results_1 values (?,?,?,?,?,?,?,?,?,?)", lcName,key[1],resName,res.TensorOrder, res.getIntId(0),res.getIntId(1), res.getRealId(0),res.getRealId(1),res.Size, SQLite3::Blob.new(res.toBlob())) end else puts "NO FOR" + lcName + resName end end
The example is provided in file "RUBY/EX20/rehashDynamicResults.rb"