def test_save_changes_to_csv(self): test_tile = self.csv_file + '_test.csv' copyfile(self.csv_file, test_tile) db = CSVDB(test_tile) db.print_sql("update personnes_csv_test set id = 0") db.print_sql("commit") time.sleep(0.5) db = CSVDB(test_tile) result = db.execute_sql("select distinct id from personnes_csv_test") self.assertEqual(result, [['id'], (0, )])
def main(root_dir=None): db = CSVDB(root_dir) populate_table_list(db) session = PromptSession(lexer=PygmentsLexer(SqlLexer), completer=WordCompleter(sql_csv_keywords, ignore_case=True), style=style, history=FileHistory('history.txt'), auto_suggest=AutoSuggestFromHistory()) while True: messages = [] try: cmd = session.prompt("SQLCSV> ") except KeyboardInterrupt: continue # Control-C pressed. Try again. except EOFError: break # Control-D pressed. try: messages = execute_command(cmd, db) # add potential new table to the auto complete for table in db.table_list: if table.name not in sql_csv_keywords: sql_csv_keywords.append(table.name) except Exception as e: print(repr(e)) finally: for message in messages: print(message)
def execute_script(root_dir, sql_script): db = CSVDB(root_dir) populate_table_list(db) script_file = open(sql_script, 'r') command = '' for line in script_file.readlines(): command += line if line.strip().endswith(';'): print("Executing: " + command) execute_command(command, db) command = '' script_file.close() execute_command('exit', db)
def setUp(self): self.csv_file = 'data/rh/personnes.csv' self.root_dir = 'data' self.db = CSVDB(self.root_dir)
def test_execute_sql(self): db = CSVDB(self.root_dir) result = db.execute_sql("select 1") self.assertEqual(result, [['1'], (1, )])
def test_get_table_name_list(self): db = CSVDB(self.root_dir) table_list = db.get_table_name_list() self.assertTrue('rh_personnes' in table_list)
def test_desc(self): db = CSVDB(self.root_dir) result = db.desc('rh_personnes') self.assertEqual(result, '')
def test_print_sql(self): db = CSVDB(self.root_dir) result = db.print_sql("select * from rh_personnes") self.assertEqual(result, '')
def test_load(self): db = CSVDB(self.root_dir)
def test_load_file(self): db = CSVDB(self.csv_file) type = get_file_type(self.csv_file) db.load_file(type, self.csv_file, self.root_dir)