source: subversion/sites/tile.openstreetmap.org/insert_tile.rb @ 5364

Last change on this file since 5364 was 3629, checked in by jonb, 13 years ago

insert_tile.rb: handle mysql connect errors.

  • Property svn:executable set to *
File size: 838 bytes
Line 
1#!/usr/bin/ruby
2
3require 'mysql'
4
5def call_local_sql
6  dbh = nil
7  begin
8    dbh = Mysql.real_connect('localhost', 'tile', 'tile', 'tile')
9    sql = yield
10    res = dbh.query(sql)
11    if res.nil? then return true else return res end
12  rescue MysqlError =>ex
13    puts ex
14  ensure
15    dbh.close unless dbh.nil?
16  end
17  nil
18end
19
20
21x = ARGV[0]
22y = ARGV[1]
23z = ARGV[2]
24filename = ARGV[3]
25
26puts "tile #{x},#{y},#{z} size is #{File.size(filename)}"
27
28if File.size(filename) == 0 #158 # its blank
29  call_local_sql { "delete from tiles where x=#{x} and y=#{y} and z=#{z};" }
30else
31  puts 'inserting tile'
32 
33  file = File.new(filename, "r")
34
35  data = Mysql.quote(file.read)
36
37  call_local_sql { "update tiles set data='#{data}', created_at=NOW(), dirty_t='false' where x=#{x} and y=#{y} and z=#{z};" }
38  puts `ls -l #{filename}`
39end
40`rm #{filename}`
41
Note: See TracBrowser for help on using the repository browser.