- sql_res = execute("SELECT id FROM struct WHERE name=? AND parent=?", \
- (name, row_id)).fetchone()
- if sql_res is None: # update STRUCT table (MIDDLELEVEL_FIELD)
- execute("INSERT INTO struct values(NULL,?,?)", (name, row_id))
+ child_id = execute("SELECT id FROM struct WHERE name=? AND parent=?", \
+ (name, parent_id)).fetchone()
+ if child_id is None: # update STRUCT table (MIDDLELEVEL_FIELD)
+ execute("INSERT INTO struct values(NULL,?,?)", (name, parent_id))
+ child_id = execute("SELECT last_insert_rowid()").fetchone()[0]
+ else:
+ child_id = child_id[0]
+
+ # update RELATION table
+ execute("INSERT INTO relation values(?,?)", (_id, child_id))