if (CompanyfileObject == failure):
    File.Logerror(ErrorfileObject, module, Errormessage, error)

CompanyfileData = File.Readline(CompanyfileObject, empty)
Errormessage = 'No data in ' + Companyfilename
if (CompanyfileData == empty):
    File.Logerror(ErrorfileObject, module, Errormessage, error)

# Progress update
Errormessage = 'Loading data from file %s' % Companyfilename
File.Logerror(ErrorfileObject, module, Errormessage, info)

DataCount = 0
DataInserted = 0
while (CompanyfileData != empty):
    SQLcommand = Db.Geninsert(Companytable, Companyfields, CompanyfileData)
    SQLresponse = (Db.SQLload(DbObject, DbCursor, SQLcommand, failure))
    Errormessage = 'SQLresponse error for SQL command ' + '\"' + SQLcommand + '\"'
    if ((SQLresponse) == failure):
        File.Logerror(ErrorfileObject, module, Errormessage, warning)
    else:
        DataInserted += 1

    CompanyfileData = File.Readline(CompanyfileObject, empty)

    # Increment counter and display progress message.
    DataCount += 1
    if (DataCount % 100 == 0): print('%d lines processed' % DataCount)

# Progress update
Errormessage = 'Populated \'company\' table with %i of a possible %i entries' % (
File.Logerror(ErrorfileObject, module,
              'Verified that all required tables have been defined', info)

# Load company data from 'companies.data' file
CompanyfileObject = File.Open(Companyfilename, read, failure)
Errormessage = 'Could not open ' + Companyfilename
if (CompanyfileObject == failure):
    File.Logerror(ErrorfileObject, module, Errormessage, error)

CompanyfileData = File.Readline(CompanyfileObject, empty)
Errormessage = 'No data in ' + Companyfilename
if (CompanyfileData == empty):
    File.Logerror(ErrorfileObject, module, Errormessage, error)

while (CompanyfileData != empty):
    SQLcommand = Db.Geninsert('company', Companyfields, CompanyfileData)
    SQLresponse = (Db.SQLload(DbObject, DbCursor, SQLcommand, failure))
    Errormessage = 'SQLresponse error for SQL command ' + '\"' + SQLcommand + '\"'
    if ((SQLresponse) == failure):
        File.Logerror(ErrorfileObject, module, Errormessage, warning)
    CompanyfileData = File.Readline(CompanyfileObject, empty)

# Progress update
File.Logerror(ErrorfileObject, module, 'Populated \'company\' table ', info)

Errormessage = 'Could not close ' + Companyfilename
if (File.Close(CompanyfileObject, failure) == failure):
    File.Logerror(ErrorfileObject, module, Errormessage, warning)

# Load engine data from 'engines.data' file
EnginefileObject = File.Open(Enginefilename, read, failure)