# HG changeset patch # User James Bergstra # Date 1232835941 18000 # Node ID ac6e7ce28f7061eeaa966b5d3c3b35db5d31b770 # Parent af14b1f32882ba0a0f6635812145ab741a9e7b21# Parent b79c4e1bbd7d7ad595b68815bebecdae0dc1d9c3 merge diff -r af14b1f32882 -r ac6e7ce28f70 pylearn/dbdict/api0.py --- a/pylearn/dbdict/api0.py Sat Jan 24 17:24:55 2009 -0500 +++ b/pylearn/dbdict/api0.py Sat Jan 24 17:25:41 2009 -0500 @@ -472,6 +472,7 @@ # generate raw sql command string viewsql = crazy_sql_command(view.name, cols, \ + h_self._dict_table.name, \ h_self._pair_table.name, \ h_self._link_table.name); diff -r af14b1f32882 -r ac6e7ce28f70 pylearn/dbdict/sql.py --- a/pylearn/dbdict/sql.py Sat Jan 24 17:24:55 2009 -0500 +++ b/pylearn/dbdict/sql.py Sat Jan 24 17:25:41 2009 -0500 @@ -25,6 +25,7 @@ START = 0 RUNNING = 1 DONE = 2 +FUCKED_UP = 666 _TEST_CONCURRENCY = False @@ -227,7 +228,7 @@ else: s = session - do_insert = force_dup or (None is s.query(db._Dict).filter(db._Dict.hash==jobhash).first()) + do_insert = force_dup or (None is s.query(db._Dict).filter(db._Dict.hash==jobhash).filter(db._Dict.status!=FUCKED_UP).first()) rval = None if do_insert: diff -r af14b1f32882 -r ac6e7ce28f70 pylearn/dbdict/sql_commands.py --- a/pylearn/dbdict/sql_commands.py Sat Jan 24 17:24:55 2009 -0500 +++ b/pylearn/dbdict/sql_commands.py Sat Jan 24 17:25:41 2009 -0500 @@ -1,5 +1,5 @@ -def crazy_sql_command(viewname, cols, keytab, linktab, id_col='id', dict_id='dict_id', pair_id='pair_id'): +def crazy_sql_command(viewname, cols, dicttab, keytab, linktab, id_col='id', dict_id='dict_id', pair_id='pair_id'): #create or replace view expview as select * from (select id as v1_id, value as nhid from #test0 where name='nhid') nhid LEFT OUTER JOIN (select id as v2_id, value as lrate from @@ -8,22 +8,30 @@ col_queries = [] colname0 = None for i, (colname, table_col) in enumerate(cols): + safe_col = colname.replace('__','') + safe_col = safe_col.replace('.','__') + + cols[i][0] = safe_col + if i == 0: - q = """(select %(dict_id)s as v%(i)s_id, %(table_col)s as %(colname)s - from \"%(keytab)s\", \"%(linktab)s\" + q = """(select %(dict_id)s as v%(i)s_id, %(table_col)s as %(safe_col)s + from \"%(dicttab)s\", \"%(keytab)s\", \"%(linktab)s\" where name='%(colname)s' - and \"%(keytab)s\".%(id_col)s = \"%(linktab)s\".%(pair_id)s) - %(colname)s """ % locals() - colname0 = colname + and \"%(keytab)s\".%(id_col)s = \"%(linktab)s\".%(pair_id)s + and \"%(dicttab)s\".%(id_col)s = \"%(linktab)s\".%(dict_id)s) + %(safe_col)s """ % locals() + colname0 = safe_col else: - q = """ LEFT OUTER JOIN (select %(dict_id)s as v%(i)s_id, %(table_col)s as %(colname)s - from \"%(keytab)s\", \"%(linktab)s\" + q = """ LEFT OUTER JOIN (select %(dict_id)s as v%(i)s_id, %(table_col)s as %(safe_col)s + from \"%(dicttab)s\", \"%(keytab)s\", \"%(linktab)s\" where name='%(colname)s' - and \"%(keytab)s\".%(id_col)s = \"%(linktab)s\".%(pair_id)s) - %(colname)s - on %(colname0)s.v0_id = %(colname)s.v%(i)s_id""" % locals() + and \"%(keytab)s\".%(id_col)s = \"%(linktab)s\".%(pair_id)s + and \"%(dicttab)s\".%(id_col)s = \"%(linktab)s\".%(dict_id)s) + %(safe_col)s + on %(colname0)s.v0_id = %(safe_col)s.v%(i)s_id""" % locals() + col_queries.append(q) - + header = " create or replace view %s as select %s.v0_id as id, %s from " \ % (viewname, colname0, (", ".join([c[0] for c in cols])))