To meet the business needs of an organization, a server is built for data storage. Because the data stream is small, the access database is used as the database. It was okay at first, but later I found a problem with the access database, that is, the tablespace will become larger and larger as it is used, even if there is no data in the table. Because the content stored in a table at a time is very small, it will be deleted every few minutes and then
To meet the business needs of an organization, a server is built for data storage. Because the data stream is small, the access database is used as the database. It was okay at first, but later I found a problem with the access database, that is, the tablespace will become larger and larger as it is used, even if there is no data in the table. Because the content stored in a table at a time is very small, it will be deleted every few minutes and then
To meet the business needs of an organization, a server is built for data storage. Because the data stream is small, the access database is used as the database. It was okay at first, but later I found a problem with the access database, that is, the tablespace will become larger and larger as it is used, even if there is no data in the table. Because the content stored in a table at a time is very small, it will be deleted every few minutes and then written, so the table will become larger and larger!
Originally, it was a compression software written in VB. Because it was M $'s own language, it naturally had good support for the Office series. Later, it was found that ruby could also access the Jet engine through Win32ole, why not use ruby? This is because the previous code was used by the magic horse class, which is slightly exaggerated, but the effect is good.
#hb table write by hopy 2012 require 'win32ole'require 'oci8'class Hb def initialize @oci = OCI8.new("xxx","***","xxx") end def open unless @acs conn_str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=#{Dir.pwd}/hb.mdb" #conn_str = "driver={SQL Server};database=xxx;server=localhost,1433;uid=sa;pwd=sa" @acs = WIN32OLE.new('ADODB.Connection') @acs.Open(conn_str) end end def close (@acs.Close;@acs=nil) if @acs end def cls self.open sql = "DELETE * from InTable";@acs.Execute(sql) sql = "DELETE * from OutTable";@acs.Execute(sql) end def zip start = Time.now self.close jet = WIN32OLE.new('JRO.JetEngine') path = Dir.pwd+"/hb.mdb" new_path=Dir.pwd+"/hb_ziped.mdb" File.delete(new_path) if File.exist?(new_path) sp = "Provider=Microsoft.Jet.OLEDB.4.0" ss = sp+";Data Source="+path sd = sp+";Data Source="+new_path jet.CompactDatabase(ss,sd) File.delete(path) File.rename(new_path,path) puts "access ziped , take #{Time.now - start} s" end def sync self.cls self.open zb = [64981,57520] i = 0;start = Time.now ret = @oci.exec('select * from DBO.DPXS_ARRIVAL') do |r| next if r[7].unpack("v*") != zb zt = if r[24] == "Arrived" r[23] elsif r[25] r[25] else r[23] end tm = if r[12] r[12] elsif r[11] r[11] else r[10] end @acs.Execute("INSERT INTO InTable VALUES('#{r[0]}','#{tm}','#{r[13]}','#{zt}')");i+=1 end puts "sync #{i} arrival flights , take #{Time.now - start} s" i = 0;start = Time.now ret = @oci.exec('select * from DBO.DPXS_DEPARTURE') do |r| next if r[7].unpack("v*") != zb tm = if r[13] r[13] elsif r[12] r[12] else r[11] end @acs.Execute("INSERT INTO OutTable VALUES('#{r[0]}','#{tm}','#{r[14]}','#{r[27]}')");i+=1 end puts "sync #{i} departure flights , take #{Time.now - start} s" endendINTERVAL_sec = 10hb = Hb.newt = 0loop do sleep(INTERVAL_sec);t+=INTERVAL_sec hb.sync (hb.zip;t=0) if t >= 60 #t=0 if t >= 60end