MCPcopy Create free account
hub / github.com/ElementsProject/lightning / extract_queries

Function extract_queries

devtools/sql-rewrite.py:192–236  ·  view source on GitHub ↗
(pofile)

Source from the content-addressed store, hash-verified

190
191
192def extract_queries(pofile):
193 # Given a po-file, extract all queries and their associated names, and
194 # return them as a list.
195
196 def chunk(pofile):
197 # Chunk a given file into chunks separated by an empty line
198 with open(pofile, 'r') as f:
199 chunk = []
200 for line in f:
201 line = line.strip()
202 if line.strip() == "":
203 yield chunk
204 chunk = []
205 else:
206 chunk.append(line.strip())
207 if chunk != []:
208 yield chunk
209
210 colhtables = {}
211 queries = []
212 for c in chunk(pofile):
213
214 # Skip other comments
215 i = 1
216 while c[i][0] == '#':
217 i += 1
218
219 # Strip header and surrounding quotes
220 query = c[i][7:][:-1]
221
222 is_select = query.upper().startswith("SELECT")
223 if is_select:
224 colnames = 'col_table{}'.format(len(queries))
225 colhtables[colnames] = colname_htable(query)
226 else:
227 colnames = None
228
229 queries.append({
230 'name': query,
231 'query': query,
232 'placeholders': query.count('?'),
233 'readonly': "true" if is_select else "false",
234 'colnames': colnames,
235 })
236 return colhtables, queries_htable(queries)
237
238
239if __name__ == "__main__":

Callers 1

sql-rewrite.pyFile · 0.85

Calls 3

chunkFunction · 0.85
colname_htableFunction · 0.85
queries_htableFunction · 0.85

Tested by

no test coverage detected