(query)
| 100 | |
| 101 | |
| 102 | def colname_htable(query): |
| 103 | assert query.upper().startswith("SELECT") |
| 104 | colquery = query[6:query.upper().index(" FROM ")] |
| 105 | colnames = colquery.split(',') |
| 106 | |
| 107 | # If split caused unbalanced brackets, it's complex: assume |
| 108 | # a single field! |
| 109 | if any([colname.count('(') != colname.count(')') for colname in colnames]): |
| 110 | return [('"' + colquery.strip() + '"', 0)] |
| 111 | |
| 112 | # 50% density htable |
| 113 | tablesize = len(colnames) * 2 - 1 |
| 114 | table = [("NULL", -1)] * tablesize |
| 115 | for colnum, colname in enumerate(colnames): |
| 116 | colname = colname.strip() |
| 117 | # SELECT xxx AS yyy -> Y |
| 118 | as_clause = colname.upper().rfind(" AS ") |
| 119 | if as_clause != -1: |
| 120 | colname = colname[as_clause + 4:].strip() |
| 121 | |
| 122 | pos = hash_djb2(colname) % tablesize |
| 123 | while table[pos][0] != "NULL": |
| 124 | pos = (pos + 1) % tablesize |
| 125 | table[pos] = ('"' + colname + '"', colnum) |
| 126 | return table |
| 127 | |
| 128 | |
| 129 | template = Template("""#ifndef LIGHTNINGD_WALLET_GEN_DB_${f.upper()} |
no test coverage detected