From ec1025014859cbd8e0e20311d90aecc576cf9170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 11 Jul 2011 18:31:16 +0200 Subject: [PATCH] onedb: use sequel interface to sanitize sql strings --- src/onedb/1.rb | 54 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/src/onedb/1.rb b/src/onedb/1.rb index 43260e22b3..98db3116c3 100644 --- a/src/onedb/1.rb +++ b/src/onedb/1.rb @@ -57,7 +57,10 @@ module Migrator body = "#{oid}#{gid}#{groupname}#{name}#{row[:password]}#{row[:enabled]}" - @db.run "INSERT INTO user_pool VALUES(#{oid},'#{name}','#{body}');" + @db[:user_pool].insert( + :oid => oid, + :name => name, + :body => body) end # Delete old user_pool @@ -100,7 +103,12 @@ module Migrator body = "#{oid}#{name}#{state}#{row[:im_mad]}#{row[:vm_mad]}#{row[:tm_mad]}#{last_mon_time}#{host_share}#{ template_doc.to_s }" - @db.run "INSERT INTO host_pool VALUES(#{oid},'#{name}','#{body}', #{state}, #{last_mon_time});" + @db[:host_pool].insert( + :oid => oid, + :name => name, + :body => body, + :state => state, + :last_mon_time => last_mon_time) end # Delete old table @@ -140,7 +148,13 @@ module Migrator # from 0 to 5, but the meaning is the same for states 0 to 3 body = "#{oid}#{row[:uid]}#{gid}#{get_username(row[:uid])}#{group}#{name}#{row[:type]}#{public}#{row[:persistent]}#{row[:regtime]}#{row[:source]}#{row[:state]}#{row[:running_vms]}#{row[:template]}" - @db.run "INSERT INTO image_pool VALUES(#{oid},'#{name}','#{body}', #{uid}, #{gid}, #{public});" + @db[:image_pool].insert( + :oid => oid, + :name => name, + :body => body, + :uid => uid, + :gid => gid, + :public => public) end # Delete old table @@ -170,7 +184,10 @@ module Migrator body = "#{seq}#{row[:host_name]}#{row[:vm_dir]}#{row[:hid]}#{row[:stime]}#{row[:etime]}#{row[:vm_mad]}#{row[:tm_mad]}#{row[:pstime]}#{row[:petime]}#{row[:rstime]}#{row[:retime]}#{row[:estime]}#{row[:eetime]}#{row[:reason]}" - @db.run "INSERT INTO history VALUES(#{vid},'#{seq}','#{body}');" + @db[:history].insert( + :vid => vid, + :seq => seq, + :body => body) end @@ -198,14 +215,14 @@ module Migrator body = "#{oid}#{uid}#{gid}#{get_username(uid)}#{group}#{name}#{last_poll}#{state}#{lcm_state}#{row[:stime]}#{row[:etime]}#{row[:deploy_id]}#{row[:memory]}#{row[:cpu]}#{row[:net_tx]}#{row[:net_rx]}#{row[:template]}#{history}" @db[:vm_pool].insert( - :oid => oid, - :name => name, - :body => body, - :uid => uid, - :gid => gid, - :last_poll => last_poll, - :state => state, - :lcm_state => lcm_state) + :oid => oid, + :name => name, + :body => body, + :uid => uid, + :gid => gid, + :last_poll => last_poll, + :state => state, + :lcm_state => lcm_state) end @@ -244,7 +261,13 @@ module Migrator # network is listed. So setting it to 0 is safe body = "#{oid}#{uid}#{gid}#{get_username(uid)}#{group}#{name}#{row[:type]}#{row[:bridge]}#{public}0#{row[:template]}" - @db.run "INSERT INTO network_pool VALUES(#{oid},'#{name}','#{body}', #{uid}, #{gid}, #{public});" + @db[:network_pool].insert( + :oid => oid, + :name => name, + :body => body, + :uid => uid, + :gid => gid, + :public => public) end # Read each entry in the old table, and insert into new table @@ -254,7 +277,10 @@ module Migrator body = "#{ip}#{row[:mac_prefix]}#{row[:mac_suffix]}#{row[:used]}#{row[:vid]}" - @db.run "INSERT INTO leases VALUES(#{oid}, #{ip}, '#{body}');" + @db[:leases].insert( + :oid => oid, + :ip => ip, + :body => body) end # Delete old tables