Class: Query

Inherits:
Object
  • Object
show all
Defined in:
lib/pqa.rb

Direct Known Subclasses

ErrorQuery

Constant Summary collapse

DEBUG =
false
REMOVE_TEXT =
Regexp.new("'[^']*'")
REMOVE_NUMBERS =
Regexp.new('([^a-zA-Z_\$])([0-9]{1,10})')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text = "", ignored = false) ⇒ Query

Returns a new instance of Query.



692
693
694
695
696
697
698
699
700
# File 'lib/pqa.rb', line 692

def initialize(text="", ignored=false)
  $stderr.puts "NIL txt for Query" if text.nil? && DEBUG
  @text = text
  @duration = nil
  @subqueries = []
  @parsing_subs = false
  @ignored = ignored
  @normalized = false
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



689
690
691
# File 'lib/pqa.rb', line 689

def db
  @db
end

#durationObject

Returns the value of attribute duration.



690
691
692
# File 'lib/pqa.rb', line 690

def duration
  @duration
end

#ignoredObject

Returns the value of attribute ignored.



690
691
692
# File 'lib/pqa.rb', line 690

def ignored
  @ignored
end

#q_idObject

Returns the value of attribute q_id.



690
691
692
# File 'lib/pqa.rb', line 690

def q_id
  @q_id
end

#textObject (readonly)

Returns the value of attribute text.



689
690
691
# File 'lib/pqa.rb', line 689

def text
  @text
end

#userObject (readonly)

Returns the value of attribute user.



689
690
691
# File 'lib/pqa.rb', line 689

def user
  @user
end

Instance Method Details

#accumulate_to(accumulator) ⇒ Object



737
738
739
# File 'lib/pqa.rb', line 737

def accumulate_to(accumulator)
  accumulator.append_query(self)
end

#append(txt) ⇒ Object



702
703
704
705
706
707
708
709
# File 'lib/pqa.rb', line 702

def append(txt)  
  $stderr.puts "NIL txt for append" if txt.nil? && DEBUG
  if @parsing_subs
    @subqueries.last << " " << txt
  else
    @text << " " << txt
  end
end

#check(regexp) ⇒ Object



773
774
775
# File 'lib/pqa.rb', line 773

def check(regexp)
  regexp.match(@text.strip) != nil
end

#is_deleteObject



761
762
763
# File 'lib/pqa.rb', line 761

def is_delete
  check(/^DELETE/i)
end

#is_insertObject



765
766
767
# File 'lib/pqa.rb', line 765

def is_insert
  check(/^INSERT/i)
end

#is_selectObject



757
758
759
# File 'lib/pqa.rb', line 757

def is_select
  check(/^SELECT/i)
end

#is_updateObject



769
770
771
# File 'lib/pqa.rb', line 769

def is_update
  check(/^UPDATE/i)
end

#normalizeObject



725
726
727
728
729
730
731
732
733
734
735
# File 'lib/pqa.rb', line 725

def normalize
  if @text
    @text.gsub!(/\\'/, '')
    @text.gsub!(REMOVE_TEXT, "{ }")
    @text.gsub!(REMOVE_NUMBERS, '\1{ }')
    @text.squeeze!(" ")  
    @text.strip!
  end
  @normalized = true
  @text
end

#set_db(db) ⇒ Object



717
718
719
# File 'lib/pqa.rb', line 717

def set_db(db)
  @db = db
end

#set_subquery(text) ⇒ Object



711
712
713
714
715
# File 'lib/pqa.rb', line 711

def set_subquery(text)
  $stderr.puts "NIL txt for sub_q" if text.nil? && DEBUG
  @parsing_subs = true
  @subqueries << text
end

#set_user(user) ⇒ Object



721
722
723
# File 'lib/pqa.rb', line 721

def set_user(user)
  @user = user
end

#to_sObject

end



753
754
755
# File 'lib/pqa.rb', line 753

def to_s
  @text
end