Commit f66bdf77 authored by Anze Vavpetic's avatar Anze Vavpetic
Browse files

fixed that treeliker conversion works with in memory orange tables

parent 719887a7
......@@ -149,11 +149,30 @@ class DBContext:
if self.orng_tables:
data = []
for ex in self.orng_tables[table]:
data.append([ex[col] for col in cols])
print cols
print self.orng_tables[table].domain
data.append([ex[str(col)] for col in cols])
return data
else:
return self.fetch(table, cols)
def select_where(self, table, cols, pk_att, pk):
'''
SELECT with WHERE clause.
'''
if self.orng_tables:
data = []
for ex in self.orng_tables[table]:
data.append([ex[str(col)] for col in cols if ex[str(pk_att)] == pk])
return data
else:
con = self.connection.connect()
cursor = con.cursor()
attributes = self.db.fmt_cols(cols)
cursor.execute("SELECT %s FROM %s WHERE `%s`='%s'" % (attributes, table, pk_att, pk))
con.close()
return [cols for cols in cursor]
def fetch_types(self, table, cols):
'''
Returns a dictionary of field types for the given table and columns.
......
......@@ -321,12 +321,13 @@ class TreeLikerConverter(Converter):
# Skip the class attribute
if self.db.target_att in cols:
cols.remove(self.db.target_att)
attributes = self.db.fmt_cols(cols)
#attributes = self.db.fmt_cols(cols)
# All rows matching `pk`
#print "SELECT %s FROM %s WHERE `%s`='%s'" % (attributes, target, pk_att, pk)
self.cursor.execute("SELECT %s FROM %s WHERE `%s`='%s'" % (attributes, target, pk_att, pk))
for row in self.cursor:
#self.cursor.execute("SELECT %s FROM %s WHERE `%s`='%s'" % (attributes, target, pk_att, pk))
#for row in self.cursor:
for row in self.db.select_where(target, cols, pk_att, pk):
# print 'row'
#values = []
row_pk = self._row_pk(target, cols, row)
......@@ -401,10 +402,13 @@ class TreeLikerConverter(Converter):
# Link case 2: this_att is a fk of another table
else:
attributes = self.db.fmt_cols([this_att]+cols)
self.cursor.execute("SELECT %s FROM %s WHERE `%s`='%s'" % (attributes, target, pk_att, pk))
fk_list = []
for row in self.cursor:
# attributes = self.db.fmt_cols([this_att]+cols)
# self.cursor.execute("SELECT %s FROM %s WHERE `%s`='%s'" % (attributes, target, pk_att, pk))
# fk_list = []
# for row in self.cursor:
# row_pk = self._row_pk(target, cols, row[1:])
# fk_list.append((row[0], row_pk))
for row in self.db.select_where(target, [this_att]+cols, pk_att, pk):
row_pk = self._row_pk(target, cols, row[1:])
fk_list.append((row[0], row_pk))
for fk, row_pk in fk_list:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment