0

I have been creating a very basic database system using SQLite3 in python, and I am attempting to tabulate the data. The problem is I'm not entirely sure how I would go about importing the data and then tabulating said imported data.

At the moment, my file contains the following values, written in the sql code:

db_name = "Clients.db"
sql = """Create table Clients
           (ClientID integer,
           Forename text,
           Surname text,
           Company text,
           Currency text,
           eMail text,
           Phone integer,
           Date_Added text,
           primary key(ClientID))"""
create_table(db_name,"Clients",sql)

This has successfully saved as a .db file which I can access and have successfully edited with other functions within my program. I can export the data into the .db file, however I have no idea how tabulate it once I run it back through the program. Any advice on getting this to work would be greatly appreciated.

B. Anderson
  • 81
  • 1
  • 6
  • 1
    Are you asking how to query a database? – Daniel Roseman Jan 23 '15 at 15:12
  • I suppose so. I need to know how to import data from a database using sql, like this `def get_all_data(data): with sqlite3.connect("Clients.db") as db: cursor = db.cursor() sql = "select * from Clients where ClientID = ?" data = cursor.fetchall() cursor.execute(sql, data) db.commit() return(data)` but use the data it returns and format it into a table. – B. Anderson Jan 23 '15 at 15:17
  • 1
    So you know how to query the database, you've got the data, surely all you need to do is loop through it? – Daniel Roseman Jan 23 '15 at 15:18
  • It's more the fact that I am unsure of how to loop it through, removing the individual data strings, and formatting them into a table. Sort of new to tabulating so I'm not sure how I would go about doing it. – B. Anderson Jan 23 '15 at 15:21
  • Thanks by the way, you kinda informed me that I worded my question badly. – B. Anderson Jan 23 '15 at 15:24
  • 1
    If your problem is the tabular output from Python, this is a duplicate of [Python: Printing Lists as Tabular Data](http://stackoverflow.com/questions/9535954/python-printing-lists-as-tabular-data) – Serge Ballesta Jan 23 '15 at 15:35

0 Answers0