186 msg = ' Entity with eid %s exists in the system table but in no source' |
186 msg = ' Entity with eid %s exists in the system table but in no source' |
187 print >> sys.stderr, msg % eid, |
187 print >> sys.stderr, msg % eid, |
188 if fix: |
188 if fix: |
189 session.system_sql('DELETE FROM entities WHERE eid=%s;' % eid) |
189 session.system_sql('DELETE FROM entities WHERE eid=%s;' % eid) |
190 notify_fixed(fix) |
190 notify_fixed(fix) |
|
191 session.system_sql('INSERT INTO cw_source_relation (eid_from, eid_to) ' |
|
192 'SELECT e.eid, s.cw_eid FROM entities as e, cw_CWSource as s ' |
|
193 'WHERE s.cw_name=e.asource AND NOT EXISTS(SELECT 1 FROM cw_source_relation as cs ' |
|
194 ' WHERE cs.eid_from=e.eid AND cs.eid_to=s.cw_eid)') |
|
195 session.system_sql('INSERT INTO is_relation (eid_from, eid_to) ' |
|
196 'SELECT e.eid, s.cw_eid FROM entities as e, cw_CWEType as s ' |
|
197 'WHERE s.cw_name=e.type AND NOT EXISTS(SELECT 1 FROM is_relation as cs ' |
|
198 ' WHERE cs.eid_from=e.eid AND cs.eid_to=s.cw_eid)') |
|
199 session.system_sql('INSERT INTO is_instance_of_relation (eid_from, eid_to) ' |
|
200 'SELECT e.eid, s.cw_eid FROM entities as e, cw_CWEType as s ' |
|
201 'WHERE s.cw_name=e.type AND NOT EXISTS(SELECT 1 FROM is_instance_of_relation as cs ' |
|
202 ' WHERE cs.eid_from=e.eid AND cs.eid_to=s.cw_eid)') |
191 print 'Checking entities tables' |
203 print 'Checking entities tables' |
192 for eschema in schema.entities(): |
204 for eschema in schema.entities(): |
193 if eschema.final: |
205 if eschema.final: |
194 continue |
206 continue |
195 table = SQL_PREFIX + eschema.type |
207 table = SQL_PREFIX + eschema.type |