source: subversion/tile.openstreetmap.org/insert_tile.rb @ 2176

Last change on this file since 2176 was 2029, checked in by steve, 14 years ago

add hack tile stuff

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