Class: Query
- Inherits:
-
Object
- Object
- Query
- Defined in:
- lib/pqa.rb
Direct Known Subclasses
Constant Summary collapse
- DEBUG =
false
- REMOVE_TEXT =
Regexp.new("'[^']*'")
- REMOVE_NUMBERS =
Regexp.new('([^a-zA-Z_\$])([0-9]{1,10})')
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#ignored ⇒ Object
Returns the value of attribute ignored.
-
#q_id ⇒ Object
Returns the value of attribute q_id.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #accumulate_to(accumulator) ⇒ Object
- #append(txt) ⇒ Object
- #check(regexp) ⇒ Object
-
#initialize(text = "", ignored = false) ⇒ Query
constructor
A new instance of Query.
- #is_delete ⇒ Object
- #is_insert ⇒ Object
- #is_select ⇒ Object
- #is_update ⇒ Object
- #normalize ⇒ Object
- #set_db(db) ⇒ Object
- #set_subquery(text) ⇒ Object
- #set_user(user) ⇒ Object
-
#to_s ⇒ Object
end.
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
#db ⇒ Object (readonly)
Returns the value of attribute db.
689 690 691 |
# File 'lib/pqa.rb', line 689 def db @db end |
#duration ⇒ Object
Returns the value of attribute duration.
690 691 692 |
# File 'lib/pqa.rb', line 690 def duration @duration end |
#ignored ⇒ Object
Returns the value of attribute ignored.
690 691 692 |
# File 'lib/pqa.rb', line 690 def ignored @ignored end |
#q_id ⇒ Object
Returns the value of attribute q_id.
690 691 692 |
# File 'lib/pqa.rb', line 690 def q_id @q_id end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
689 690 691 |
# File 'lib/pqa.rb', line 689 def text @text end |
#user ⇒ Object (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_delete ⇒ Object
761 762 763 |
# File 'lib/pqa.rb', line 761 def is_delete check(/^DELETE/i) end |
#is_insert ⇒ Object
765 766 767 |
# File 'lib/pqa.rb', line 765 def is_insert check(/^INSERT/i) end |
#is_select ⇒ Object
757 758 759 |
# File 'lib/pqa.rb', line 757 def is_select check(/^SELECT/i) end |
#is_update ⇒ Object
769 770 771 |
# File 'lib/pqa.rb', line 769 def is_update check(/^UPDATE/i) end |
#normalize ⇒ Object
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_s ⇒ Object
end
753 754 755 |
# File 'lib/pqa.rb', line 753 def to_s @text end |