def table_absent(name, db):
 changes = {'name': name, 'changes': {}, 'result': None, 'comment': ''}
 conn = None
 try:
  conn = sqlite3.connect(db, detect_types=sqlite3.PARSE_DECLTYPES)
  tables = _query(conn, ('SELECT sql FROM sqlite_master ' + " WHERE type='table' AND name=?"), [name])
  if (len(tables) == 1):
   if __opts__['test']:
    changes['result'] = True
    changes['comment'] = (("'" + name) + "' will be dropped")
   else:
    conn.execute(('DROP TABLE ' + name))
    conn.commit()
    changes['changes']['old'] = tables[0][0]
    changes['result'] = True
    changes['comment'] = (("'" + name) + "' was dropped")
  elif (len(tables) == 0):
   changes['result'] = True
   changes['comment'] = (("'" + name) + "' is already absent")
  else:
   changes['result'] = False
   changes['comment'] = (("Multiple tables with the same name='" + name) + "'")
 except Exception as e:
  changes['result'] = False
  changes['comment'] = str(e)
 finally:
  if conn:
   conn.close()
 return changes

def table_absent ( name , db ) : changes = { 'name' : name , 'changes' : { } , 'result' : None , 'comment' : '' } conn = None try : conn = sqlite3 . connect ( db , detect_types = sqlite3 . PARSE_DECLTYPES ) tables = _query ( conn , ( 'SELECT sql FROM sqlite_master ' + " WHERE type='table' AND name=?" ) , [ name ] ) if ( len ( tables ) == 1 ) : if __opts__ [ 'test' ] : changes [ 'result' ] = True changes [ 'comment' ] = ( ( "'" + name ) + "' will be dropped" ) else : conn . execute ( ( 'DROP TABLE ' + name ) ) conn . commit ( ) changes [ 'changes' ] [ 'old' ] = tables [ 0 ] [ 0 ] changes [ 'result' ] = True changes [ 'comment' ] = ( ( "'" + name ) + "' was dropped" ) elif ( len ( tables ) == 0 ) : changes [ 'result' ] = True changes [ 'comment' ] = ( ( "'" + name ) + "' is already absent" ) else : changes [ 'result' ] = False changes [ 'comment' ] = ( ( "Multiple tables with the same name='" + name ) + "'" ) except Exception as e : changes [ 'result' ] = False changes [ 'comment' ] = str ( e ) finally : if conn : conn . close ( ) return changes
make sure the specified table does not exist name the name of the table db the name of the database file .