Revision 2513
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql_gen.py | ||
---|---|---|
12 | 12 |
return quote + name.replace(quote, quote+quote) + quote |
13 | 13 |
# doubling an embedded quote escapes it in both PostgreSQL and MySQL |
14 | 14 |
|
15 |
def clean_name(name): return name.replace('"', '').replace('`', '') |
|
16 |
|
|
15 | 17 |
##### SQL code objects |
16 | 18 |
|
17 | 19 |
class MockDb: |
lib/sql.py | ||
---|---|---|
100 | 100 |
|
101 | 101 |
##### Input validation |
102 | 102 |
|
103 |
def clean_name(name): return name.replace('"', '').replace('`', '') |
|
104 |
|
|
105 | 103 |
def check_name(name): |
106 | 104 |
if re.search(r'\W', name) != None: raise NameException('Name "'+name |
107 | 105 |
+'" may contain only alphanumeric characters and _') |
... | ... | |
560 | 558 |
assert returning != None |
561 | 559 |
|
562 | 560 |
# Create function |
563 |
function_name = clean_name(first_line) |
|
561 |
function_name = sql_gen.clean_name(first_line)
|
|
564 | 562 |
return_type = 'SETOF '+returning.to_str(db)+'%TYPE' |
565 | 563 |
while True: |
566 | 564 |
try: |
... | ... | |
687 | 685 |
preserve = set(preserve) |
688 | 686 |
for col in cols: |
689 | 687 |
if col not in preserve: |
690 |
items.append((col, sql_gen.Col(clean_name(str(col)), into))) |
|
688 |
items.append((col, sql_gen.Col(sql_gen.clean_name(str(col)), into)))
|
|
691 | 689 |
|
692 | 690 |
if not as_items: items = dict(items) |
693 | 691 |
return items |
... | ... | |
788 | 786 |
assert sql_gen.is_table_col(col) |
789 | 787 |
|
790 | 788 |
table = col.table |
791 |
index = sql_gen.as_Table(clean_name(str(col))) |
|
789 |
index = sql_gen.as_Table(sql_gen.clean_name(str(col)))
|
|
792 | 790 |
col = sql_gen.to_name_only_col(col) |
793 | 791 |
try: run_query(db, 'CREATE INDEX '+index.to_str(db)+' ON '+table.to_str(db) |
794 | 792 |
+' ('+col.to_str(db)+')', recover=True, cacheable=True, log_level=3) |
lib/db_xml.py | ||
---|---|---|
136 | 136 |
try: in_col = row[out_col] |
137 | 137 |
except KeyError: pass |
138 | 138 |
else: # has a rank column, so hierarchical |
139 |
col_name = sql.clean_name(str(sql_gen.remove_col_rename(in_col))) |
|
139 |
col_name = sql_gen.clean_name(str( |
|
140 |
sql_gen.remove_col_rename(in_col))) |
|
140 | 141 |
into = out_table+'['+out_col+'='+col_name+']' |
141 | 142 |
else: # has a value column, so function-like |
142 |
col_name = sql.clean_name(str(sql_gen.remove_col_rename(in_col))) |
|
143 |
col_name = sql_gen.clean_name(str(sql_gen.remove_col_rename(in_col)))
|
|
143 | 144 |
into = out_table+'('+col_name+')' |
144 | 145 |
return into |
145 | 146 |
|
Also available in: Unified diff
Moved clean_name() from sql.py to sql_gen.py because it's DB-general and so that it can be used by sql_gen.py without circular dependencies