We will start with the SQL
format to CSV
Your function will receives a
connection
(ansqlite3
object from import sqlite3 which will be already connected),table_name
. Your function will transform the content oftable_name
toCSV
format and return it. (Columns separated bycomma
and rows separated by\n
)_
Your function will transform the content to
SQL
format by creating thetable_name
and adding each row._
a) You will use your function to convert the
list of all volcanos
fromCSV
toSQL
.
b) You will use your function to convert the
list of all fault lines
fromSQL
toCSV
. Data are inside the table named: fault_lines.
1# sql_to_csv will receive two strings as parameters and return a string. the database is a filename where sql_to_csv will fetch the information. table_name is the table from the database file to fetch the information. your return value will be a CSV formatted string: "ColA,ColB,ColC\n1,2,3\n4,5,6\n"
2# csv_to_sql will receive three strings as parameters and return nothing. csv_content is a StringIO following the CSV format. the database is a filename where csv_to_sql will push the information. table_name is the table from the database file to insert the data.