def test_delete(self): sql = sqlpuzzle.delete().from_('user').where(id=42) self.assertEqual(str(sql), 'DELETE FROM "user" WHERE "id" = 42')
def test_delete(): sql = sqlpuzzle.delete().from_('user').where(id=42) assert str(sql) == 'DELETE FROM "user" WHERE "id" = 42'
# - - ConfirmDeleteAllException # - InvalidArgumentException # - - InvalidQueryException # try: sqlpuzzle.select(True) except sqlpuzzle.exceptions.InvalidArgumentException, e: print('catched:', e) try: print(sqlpuzzle.select_from('t').on('t2')) except sqlpuzzle.exceptions.InvalidQueryException, e: print('catched:', e) try: print(sqlpuzzle.update('table').set(name='Alan')) except sqlpuzzle.exceptions.ConfirmUpdateAllException, e: print('catched:', e) try: print(sqlpuzzle.delete().from_('table')) except sqlpuzzle.exceptions.ConfirmDeleteAllException, e: print('catched:', e) # All exceptions are inherited from SqlPuzzleException. try: sqlpuzzle.select(1) except sqlpuzzle.exceptions.SqlPuzzleException, e: print('catched:', e)
# - InvalidArgumentException # - - InvalidQueryException # try: sqlpuzzle.select(True) except sqlpuzzle.exceptions.InvalidArgumentException, e: print('catched:', e) try: print(sqlpuzzle.select_from('t').on('t2')) except sqlpuzzle.exceptions.InvalidQueryException, e: print('catched:', e) try: print(sqlpuzzle.update('table').set(name='Alan')) except sqlpuzzle.exceptions.ConfirmUpdateAllException, e: print('catched:', e) try: print(sqlpuzzle.delete().from_('table')) except sqlpuzzle.exceptions.ConfirmDeleteAllException, e: print('catched:', e) # All exceptions are inherited from SqlPuzzleException. try: sqlpuzzle.select(1) except sqlpuzzle.exceptions.SqlPuzzleException, e: print('catched:', e)
#!/usr/bin/env python # -*- coding: utf-8 -*- import sqlpuzzle import sqlpuzzle.exceptions sql = sqlpuzzle.delete().from_('table') try: print(sql) except sqlpuzzle.exceptions.ConfirmDeleteAllException: pass # delete all records is not enabled by default sql.allow_delete_all() print(sql) # output: DELETE FROM `table` try: sql.forbid_delete_all() print(sql) except sqlpuzzle.exceptions.ConfirmDeleteAllException: pass # protected of delete all records can be turned on again sql.where(id=42) print(sql) # output: DELETE FROM `table` WHERE `id` = 42 print(sqlpuzzle.delete_from('table').where(id=42)) # same output as previous command