Sqlite application

Asked by Shiney

Hi all

Just trying to get my head around python and quickly. Anybody got any tips on writing a small sqlite based app in quickly - any templates etc that might help? Or tutorials?

Regards
Martyn

Question information

Language:
English Edit question
Status:
Answered
For:
Quickly Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Didier Roche-Tolomelli (didrocks) said :
#1

Hey,

I don't know any of sqlite application template in Quickly that some contributors have done. The ubuntu-application template uses couchdb, (with desktopcouch binding) which is very cool for storing easily data and get them synced between computers (you will find some tutorials with "$ quicky tutorial ubuntu-application".

Revision history for this message
John C Barstow (jbowtie) said :
#2

Support for SQLite is built into the Python standard library since v2.5. It has a very simple API.

http://docs.python.org/library/sqlite3.htm

I don't know that there is anything specific that Quickly can or should provide in this regard.

Revision history for this message
Shiney (martyn-chessels) said :
#3

Didier/John

Thanks for your quick responses.

I was thinking of Glade specifically, I guess. I've used Delphi and some other RAD desktop tools where they have data bound controls and was wondering if anybody had done any work binding the Glade/GTK+ widgets to sqlite tables and columns.

Martyn

Revision history for this message
Rick Spencer (rick-rickspencer3) said :
#4

Martyn,

In Quickly Widgets, there is a widget that binds to a Python Dictionary, and one that Binds to a record type in DesktopCouch. I'd like to create one that binds to a sqlite table as well, but I don't know that I'll have time to get to this for Maverick. Also, Quickly Widgets are not integrated with Glade quite yet, but might be for Maverick.

However, it's easy to do what you want with a quickly.widgets.DictionaryGrid. I know it's not the GUI way you are looking for yet, but that will come in later version.

Here's a quick example
from quickly.widgets.dictionary_grid import DictionaryGrid

#create a list for storing the dictionaries
work_items = []

#get stuff from the database
sql = """SELECT description, status, spec, assignee
                     FROM work_items
                     where date = '%s'
                     AND milestone = '%s'""" % (d , "maverick-alpha-2")
cursor.execute(sql )

#build the list of dictionaries from the data
for r in cursor:
    wi = {"Item":r[0].strip(),
              "Status":r[1].strip(),
              "Spec":r[2].strip()}
    work_items.append(wi)

#build your grid and add it to the window
grid = DictionaryGrid(dictionaries = work_items)
grid.show()
self.builder.get_object("vbox1").pack_start(grid)

I you want to make it editable, pass in "editable=True" when you create it, and connect to the cell-edited signal, and update the database from the signal handler.

HTH

Revision history for this message
Shiney (martyn-chessels) said :
#5

Rick

OK - Thanks for that - this is just what I wanted. I've just used a version of this code against one my db tables and it works a treat.

I guess if I use an object-mapper like sqlalchemy then its even easier.

Thanks again

Martyn

Can you help with this problem?

Provide an answer of your own, or ask Shiney for more information if necessary.

To post a message you must log in.