def sqlite_to_csv(<EOL>input_filename,<EOL>table_name,<EOL>output_filename,<EOL>dialect=csv.excel,<EOL>batch_size=<NUM_LIT>,<EOL>encoding="<STR_LIT:utf-8>",<EOL>callback=None,<EOL>query=None,<EOL>):
<EOL>if isinstance(dialect, six.text_type):<EOL><INDENT>dialect = csv.get_dialect(dialect)<EOL><DEDENT>if query is None:<EOL><INDENT>query = "<STR_LIT>".format(table_name)<EOL><DEDENT>connection = sqlite3.Connection(input_filename)<EOL>cursor = connection.cursor()<EOL>result = cursor.execute(query)<EOL>header = [item[<NUM_LIT:0>] for item in cursor.description]<EOL>fobj = open_compressed(output_filename, mode="<STR_LIT:w>", encoding=encoding)<EOL>writer = csv.writer(fobj, dialect=dialect)<EOL>writer.writerow(header)<EOL>total_written = <NUM_LIT:0><EOL>for batch in rows.plugins.utils.ipartition(result, batch_size):<EOL><INDENT>writer.writerows(batch)<EOL>written = len(batch)<EOL>total_written += written<EOL>if callback:<EOL><INDENT>callback(written, total_written)<EOL><DEDENT><DEDENT>fobj.close()<EOL>
Export a table inside a SQLite database to CSV