/[eiffelstudio]/branches/eth/eve/Src/framework/semantic_search/database/semq_queryable_query_executor.e
ViewVC logotype

Contents of /branches/eth/eve/Src/framework/semantic_search/database/semq_queryable_query_executor.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 86350 - (show annotations)
Thu Apr 28 11:47:15 2011 UTC (8 years, 5 months ago) by jasonw
File size: 4948 byte(s)
1. Added a walkaround in queryable query executor to break infinite loop (possible due to long query termination).
2. Ehanced AutoTest online statistics to include details of the faults that have been detected so far.

1 note
2 description: "Queryable query executor"
3 author: ""
4 date: "$Date$"
5 revision: "$Revision$"
6
7 class
8 SEMQ_QUERYABLE_QUERY_EXECUTOR
9
10 create
11 make
12
13 feature{NONE} -- Initialization
14
15 make (a_connection: like connection)
16 -- Initialize Current.
17 do
18 connection := a_connection
19 end
20
21 feature -- Access
22
23 connection: MYSQL_CLIENT
24 -- Database connection config
25
26 feature -- Access
27
28 last_results: LINKED_LIST [ARRAY [STRING]]
29 -- Results retrieved from last `execute'
30
31 log_manager: detachable ELOG_LOG_MANAGER
32 -- Log manager
33
34 feature -- Setting
35
36 set_log_manager (a_manager: like log_manager)
37 -- Set `log_manager' with `a_manager'.
38 do
39 log_manager := a_manager
40 ensure
41 log_manager_set: log_manager = a_manager
42 end
43
44 feature -- Basic operations
45
46 execute (a_query: SEMQ_QUERYABLE_QUERY)
47 -- Execute `a_query' and make results available in `last_results'.
48 local
49 l_term_visitor: SEMQ_QUERYABLE_QUERY_TERM_VISITOR
50 l_ast_visitor: SEMQ_QUERYABLE_QUERY_AST_VISITOR
51 l_query_string: STRING
52 l_result_array: ARRAY [STRING]
53 l_column_ith: INTEGER
54 l_retried: BOOLEAN
55 do
56 if not l_retried then
57 -- Visitors
58 create l_ast_visitor.make
59 create l_term_visitor.make (l_ast_visitor)
60 from
61 a_query.terms.start
62 until
63 a_query.terms.off
64 loop
65 a_query.terms.item.process (l_term_visitor)
66 a_query.terms.forth
67 end
68
69 -- Construct query
70 create l_query_string.make_empty
71
72 -- SELECT
73 l_query_string.append (once "SELECT %N")
74 from
75 l_ast_visitor.sql_select_clauses.start
76 until
77 l_ast_visitor.sql_select_clauses.after
78 loop
79 l_query_string.append_character ('%T')
80 l_query_string.append (l_ast_visitor.sql_select_clauses.item)
81 l_ast_visitor.sql_select_clauses.forth
82 if not l_ast_visitor.sql_select_clauses.after then
83 l_query_string.append_character (',')
84 end
85 l_query_string.append_character ('%N')
86 end
87
88 -- FROM
89 l_query_string.append (once "FROM Queryables AS qry")
90 from
91 l_ast_visitor.sql_from_clauses.start
92 until
93 l_ast_visitor.sql_from_clauses.after
94 loop
95 l_query_string.append_character (',')
96 l_query_string.append_character (' ')
97 l_query_string.append (l_ast_visitor.sql_from_clauses.item)
98 l_ast_visitor.sql_from_clauses.forth
99 end
100
101 -- JOIN
102 -- from
103 -- l_ast_visitor.sql_join_statements.start
104 -- until
105 -- l_ast_visitor.sql_join_statements.after
106 -- loop
107 -- l_query_string.append (l_ast_visitor.sql_join_statements.item)
108 -- l_query_string.append_character ('%N')
109 -- l_ast_visitor.sql_join_statements.forth
110 -- end
111
112 -- WHERE
113 l_query_string.append (once "%NWHERE %N")
114 from
115 l_ast_visitor.sql_where_clauses.start
116 until
117 l_ast_visitor.sql_where_clauses.after
118 loop
119 l_query_string.append (l_ast_visitor.sql_where_clauses.item)
120 l_ast_visitor.sql_where_clauses.forth
121 if not l_ast_visitor.sql_where_clauses.after then
122 l_query_string.append_string (once " AND %N")
123 end
124 end
125
126 -- GROUP BY
127 if a_query.is_group_by_feature_and_positions then
128 l_query_string.append (once "%NGROUP BY qry.feature_name")
129 from
130 l_ast_visitor.variable_mapping_table.start
131 until
132 l_ast_visitor.variable_mapping_table.after
133 loop
134 l_query_string.append_string (once ", Prop")
135 l_query_string.append_integer (l_ast_visitor.variable_mapping_table.item_for_iteration.join_number)
136 l_query_string.append_string (once ".`position`")
137 l_ast_visitor.variable_mapping_table.forth
138 end
139 end
140
141 -- Debug
142 -- io.put_string (l_query_string)
143 -- io.put_character ('%N')
144 -- io.put_character ('%N')
145
146 -- Execute query and store results
147 if log_manager /= Void then
148 check attached {STRING} l_query_string.twin as l_temp_str then
149 l_temp_str.replace_substring_all ("%N", " ")
150 log_manager.put_string_with_time ("Start query: " + l_temp_str)
151 end
152 end
153 create last_results.make
154 connection.execute_query (l_query_string)
155 from
156 connection.last_result.start
157 until
158 -- FIXME: The "last_results.count > 100" condition is used
159 -- to get out of an infinite loop, caused by some problems
160 -- when we iterating through `connection.last_result'.
161 connection.last_result.after or last_results.count > 100
162 loop
163 create l_result_array.make_filled (Void, 1, connection.last_result.column_count)
164 from
165 l_column_ith := 1
166 until
167 l_column_ith > connection.last_result.column_count
168 loop
169 l_result_array.put (connection.last_result.at (l_column_ith), l_column_ith)
170 l_column_ith := l_column_ith + 1
171 end
172 last_results.extend (l_result_array)
173 connection.last_result.forth
174 end
175 end
176 rescue
177 if connection.is_connected then
178 connection.close
179 connection.reinitialize
180 end
181 l_retried := True
182 create last_results.make
183 retry
184 end
185
186 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date ID Revision

  ViewVC Help
Powered by ViewVC 1.1.23