def test_03_add_record(self): sql = SQLite(True) file = os.path.isfile(sql.db_file) self.assertFalse(file, msg='Tastcase database detected!') sql.create_connection() sql.create_table(sql.conn, table) row1 = 0 row2 = 0 with sql.conn: detail = ['Sarah Connor', '12 Lambert St', '123 345 567'] row1 = add_name(sql.conn, detail) detail = ['Jesse Pinkman', '23 Lame Road', '323 453 876'] row2 = add_name(sql.conn, detail) self.assertEqual(row1, 1) self.assertEqual(row2, 2) sql.conn.close() os.remove(sql.db_file)
def test_04_delete_record(self): sql = SQLite(True) file = os.path.isfile(sql.db_file) self.assertFalse(file, msg='Tastcase database detected!') sql.create_connection() sql.create_table(sql.conn, table) result = 1 with sql.conn: detail = ['Sarah Connor', '12 Lambert St', '123 345 567'] add_name(sql.conn, detail) detail = ['Jesse Pinkman', '23 Lame Road', '323 453 876'] id = add_name(sql.conn, detail) delete_name(sql.conn, id) cur = sql.conn.cursor() cur.execute( "SELECT * FROM personal_details WHERE {} GLOB '{}'".format( 'name', '*Jesse*')) rows = cur.fetchall() result = len(rows) self.assertEqual(result, 0, msg='Did not remove properly') sql.conn.close() os.remove(sql.db_file)
def test_05_glob_filter(self): sql = SQLite(True) file = os.path.isfile(sql.db_file) self.assertFalse(file, msg='Tastcase database detected!') sql.create_connection() sql.create_table(sql.conn, table) result = 0 with sql.conn: detail = ['Sarah Connor', '12 Lambert St', '123 345 567'] add_name(sql.conn, detail) detail = ['Jesse Pinkman', '23 Lame Road', '323 453 876'] add_name(sql.conn, detail) detail = ['Cole Finklang', '88 Fancy St', '324 666 876'] add_name(sql.conn, detail) rows = select_with_glob(sql.conn, 'name', '*ink*') result = len(rows) self.assertEqual(result, 2, msg='Glob filter failed') sql.conn.close() os.remove(sql.db_file)
def main(makedb, add, remove, display, filter, output): if makedb: # Create connection and object sql = SQLite() sql.create_connection() # Create table sql.create_table(sql.conn, table) # close the connection sql.conn.close() if not add == 0: # Create connection and object sql = SQLite() sql.create_connection() with sql.conn: for i in range(add): print('Create record number {}:'.format(str(i + 1))) detail = command_line_input() add_name(sql.conn, detail) # close the connection sql.conn.close() if not remove == 0: # Create connection and object sql = SQLite() sql.create_connection() with sql.conn: delete_name(sql.conn, remove) # close the connection sql.conn.close() if display: # Create connection and object sql = SQLite() sql.create_connection() with sql.conn: select_all(sql.conn, display=True) # close the connection sql.conn.close() if len(filter) > 0: # Create connection and object sql = SQLite() sql.create_connection() with sql.conn: select_with_glob(sql.conn, 'name', filter) # close the connection sql.conn.close() if not output == 0: if output == 1: output_to_csv('output/output') elif output == 2: output_to_txt('output/output') elif output == 3: output_to_html('output/output') else: pass
from backend.keyboard_input import command_line_input from backend.sqliteStuff import SQLite, add_name from backend.table import sql_create_personal_details_table as table # Create connection and object sql = SQLite() sql.create_connection() # Create table sql.create_table(sql.conn, table) # Add a name # details = ('John Doe', '123 Nuke Street', '098 765 432') with sql.conn: for i in range(5): print('Give name {}'.format(str(i))) detail = command_line_input() name_id = add_name(sql.conn, detail)