In: |
lib/rq-3.0.0/querier.rb
|
Parent: | MainHelper |
# File lib/rq-3.0.0/querier.rb, line 18 18: def query 19: #--{{{ 20: set_q 21: 22: @q.qdb.transaction_retries = 1 23: 24: where_clause = @argv.join ' ' 25: 26: if where_clause.empty? and stdin? 27: debug{ "reading where_clause from stdin" } 28: while((buf = stdin.gets)) 29: buf.strip! 30: buf.gsub! %/#.*$/o, '' 31: next if buf.empty? 32: where_clause << "#{ buf } " 33: end 34: end 35: 36: @q.query(where_clause, &dumping_yaml_tuples) 37: #--}}} 38: end
# File lib/rq-3.0.0/querier.rb, line 39 39: def query 40: #--{{{ 41: set_q 42: 43: @q.qdb.transaction_retries = 1 44: 45: simple_pat = %/^\s*([^=\s!~]+)(=~|!~|!=|==|=)([^=\s]+)\s*$/ox 46: simple_query = @argv.select{|arg| arg !~ simple_pat }.empty? 47: 48: where_clause = 49: if simple_query 50: wc = [] 51: 52: @argv.each do |arg| 53: m = simple_pat.match(arg).to_a[1..-1] 54: field, op, value = m[0], m[1], m[2..-1].join 55: op = 56: case op 57: when '=', '==' 58: '=' 59: when '!=' 60: '!=' 61: when '=~' 62: 'like' 63: when '!~' 64: 'not like' 65: end 66: 67: quoted = (value =~ %/^\s*'.*'\s*$/o) 68: numeric = begin; Float(value); true; rescue; false; end 69: 70: value = "'#{ value }'" unless quoted or numeric 71: 72: wc << "(#{ field } #{ op } #{ value })" 73: end 74: 75: wc.join ' and ' 76: else 77: @argv.join ' ' 78: end 79: 80: if where_clause.strip.empty? and stdin? 81: debug{ "reading where_clause from stdin" } 82: while((buf = stdin.gets)) 83: buf.strip! 84: buf.gsub! %/#.*$/o, '' 85: next if buf.empty? 86: where_clause << "#{ buf } " 87: end 88: end 89: 90: @q.query(where_clause, &dumping_yaml_tuples) 91: #--}}} 92: end