WIP: problem inserting a row into database, troubleshooting

This commit is contained in:
JohnE 2015-12-10 12:48:13 -08:00
parent 8653b56e86
commit 7736404c30
2 changed files with 21 additions and 21 deletions

View File

@ -149,18 +149,17 @@ class FingerprintDB:
dbmd5 = jsonData['db-metadata-md5'] dbmd5 = jsonData['db-metadata-md5']
all_tables = tb.keys() all_tables = tb.keys()
for table_name in all_tables: for table_name in all_tables:
print "[[ Table <" + table_name + "> imported ]]" #logging.info("[[ Table <" + table_name + "> imported ]]")
newTable = TableSchema() newTable = TableSchema()
newTable.importTable(table_name, tb[table_name], dbmt[table_name], dbht[table_name]) newTable.importTable(table_name, tb[table_name], dbmt[table_name], dbht[table_name])
tables[table_name] = newTable tables[table_name] = newTable
except Exception, e: self.tables_json = tables
self.db_hash = dbmd5
self.table_hashes = dbht
except Exception as e:
logging.error("ERROR: problem loading json file: " + file_json + e) logging.error("ERROR: problem loading json file: " + file_json + e)
self.tables_json = tables
self.db_hash = dbmd5
self.table_hashes = dbht
# #
def __DBMD5Compare(self): def __DBMD5Compare(self):
pass pass

View File

@ -52,20 +52,19 @@ class FingerprintIndex:
md5_list TEXT, md5_list TEXT,
file_name TEXT); file_name TEXT);
''') ''')
logging.info("Successfully created index table") logging.info("Successfully created index table")
self.__populateIndex(fp_dir)
logging.info("Successfully populated the index")
except: except:
raise FingerprintIndexWrite("Error creating an index file") raise FingerprintIndexWrite("Error creating an index file")
finally: finally:
if self.db_conn: if self.db_conn:
self.db_conn.close() self.db_conn.close()
self.db_conn = None self.db_conn = None
self.__populateIndex(fp_dir) #
def __populateIndex(self, fp_dir): def __populateIndex(self, fp_dir):
# """ read each file, pull md5, add row to database """
# read each file, pull md5, add row to database
failCount = 0 failCount = 0
finCount = 0 finCount = 0
try: try:
@ -75,12 +74,13 @@ class FingerprintIndex:
for file in files: for file in files:
try: try:
fq_file = fp_dir + os.path.sep + file fq_file = fp_dir + os.path.sep + file
print ("importJson file=={}".format(fq_file)) # print ("importJson file=={}".format(fq_file))
db.importJson(fq_file) db.importJson(fq_file)
print("db_hash=={}".format(db.db_hash)) self.__insertRecord(db.db_hash, db.table_hashes.values(), file)
print("table_hashes={}".format(db.table_hashes)) # print("db_hash=={}".format(db.db_hash))
# print("table_hashes={}".format(db.table_hashes))
#md5_all = __createMD5Index(dbht) #md5_all = __createMD5Index(dbht)
return
finCount = finCount+1 finCount = finCount+1
except: except:
failCount = failCount+1 failCount = failCount+1
@ -88,17 +88,18 @@ class FingerprintIndex:
pass pass
logging.info("Completed populating the index. Completed: {} Failed: {} ".format(str(finCount), str(failCount))) logging.info("Completed populating the index. Completed: {} Failed: {} ".format(str(finCount), str(failCount)))
# #
def __insertRecord(self, md5_all, md5_list, filename): def __insertRecord(self, md5_all, md5_list, filename):
try: try:
logging.info("INSERT INTO md5_index VALUES(?, ?, ?): {}; {}; {}".format(md5_all, md5_list, filename))
self.db_conn.execute( self.db_conn.execute(
''' '''
INSERT INTO md5_index VALUES(?, ?, ?) INSERT INTO md5_index VALUES(?, ?, ?)
''', md5_all, md5_list, filename) ''', md5_all, md5_list, filename)
except: except Exception as e:
pass print e
logging.error("Error inserting a row")
raise FingerprintIndexWrite("Error inserting a row")
# #
def __checkIntegrity(self): def __checkIntegrity(self):