# Using the sqllite in memory as saving sessions is not required in my case'''
sqlliteconnection = sqlite3.connect(':memory:')
sqllitecursor = sqlliteconnection.cursor()
def PutCSVDetailsInSQLLite(filename):
'Reads the SQL File and Inserts the records in SQLLite database'
# Open the CSV file in read only mode
csvfile = open(filename, 'rt')
# Create a reader
reader = csv.reader(csvfile)
for row in reader:
#Read each row and insert it in the testautomation table
sqllitecursor.execute('INSERT INTO testautomation VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', row)
# Close CSV file as it is no longer required
csvfile.close()
# Do not forget to commit
sqlliteconnection.commit()
sqlliteconnection = sqlite3.connect(':memory:')
sqllitecursor = sqlliteconnection.cursor()
def PutCSVDetailsInSQLLite(filename):
'Reads the SQL File and Inserts the records in SQLLite database'
# Open the CSV file in read only mode
csvfile = open(filename, 'rt')
# Create a reader
reader = csv.reader(csvfile)
for row in reader:
#Read each row and insert it in the testautomation table
sqllitecursor.execute('INSERT INTO testautomation VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', row)
# Close CSV file as it is no longer required
csvfile.close()
# Do not forget to commit
sqlliteconnection.commit()
def CreateSQLLiteTable():
'''Creates SQL Lite database if it doesnt exist.
For this case it will be recreated as its in memory database'''
sqllitecursor.execute('DROP TABLE IF EXISTS testautomation')
# 23 Columns are being assumed to be present in the CSV file
sqllitecursor.execute('''CREATE TABLE testautomation (TC,UT,ST,RT,PT,
DataSetup,PreExecutionStep,InputFiles,InputDatabase,ExecutionStep,
OutputFiles,OutputDatabase,OutputExitStatus,Cleanup,TestCaseName,
TestCaseDescription,TestCaseNature,TestStepDescription,DataAttributes,
ExpectedResults,InputVal,ActualResults,PassFailDefect)''')
# Save the table by executing the commit statement
sqlliteconnection.commit()
No comments:
Post a Comment
Please write your comments and suggestions