[Tutor] SQLite3 DB Field Alphabetizing

David Hutto smokefloat at gmail.com
Wed Oct 13 07:25:55 CEST 2010

On Tue, Oct 12, 2010 at 10:23 AM, Alan Gauld <alan.gauld at btinternet.com> wrote:
> "David Hutto" <smokefloat at gmail.com> wrote
>> > Did you include an ORDER BY?
>> See three posts above, line 6.
> Looks like our posts crossed in transit :-)
> So you order by graphname, and you only have a single field of that name?
> But then when you put it into the list you only use part of graphname
> converted
> to a string and stripped:

This is actually an example derived from the code I used it in.
The full code is here:


I forgot to give the names in the link, but the .py files are
seperated, and should be named as follows.

The first module should be named dataplotmain.py
The second should be named dpappfunc.py
The third should be named mainpanel.py
and the dbfile should be in the directory placed on line 58 of mainpanel.py

It's still in rough draft form, but feel free to comment, and not some
will be taken out, and much more placed in.

> str(graphname[0]).lstrip('u'))
> So what did the field look like before you modified it? Since that is what
> determines the way that ORDER BY ordered it? And what is
> graphname[0] before you convert it to a string? (It looks like it
> is already a string?!)

Below is the output before converting:


[(u'.hjvkjgfkj/bdgfkjbg', u''), (u'bbbbbbbbbbbbuuzzzzzzzzz', u'Pie
Chart'), (u'jgkgyckghc', u''), (u'kfhhv ', u''), (u'khfhf', u''),
(u'test', u''), (u'test10', u''), (u'test2', u'Dashed/Dotted'),
(u'test3', u'Pie Chart'), (u'test346w43', u''), (u'test4', u'Scatter
Plot'), (u'test5', u''), (u'test6', u''), (u'test7', u''),
(u'test7uyuy', u''), (u'test8', u''), (u'test9', u''), (u'testgraph',
u''), (u'u;s;juf;sfkh', u''), (u'zzrerhshhjrs', u'')]

> BTW.
> Its unusual to have to extract sub fields from a SQL result since to
> maximise the power of SQL its better to store all "subfields" in
> separate fields of the table.

Almost to that part. As you can see from the full script in the link
above, it's still early on, so I just got the insert into db portion
in, and was working on accessing it, before placing in the overall
data structure I want to use.

> One of the complexities of debugging any database program is that
> almost as much depends on the data structures and content as it
> does on the code. Without seeing the data that is beintg operated
> upon its hard to be precise.

The above code should clarify more than my original posting.

> What happens if you execute the SQL at the sqlite interactive
> prompt? Does it give the same result?

haven't used the sqlite prompt yet, Haven't needed to yet.

> PS. You don't need the commit() for a SELECT statement, you aren't
> changing anything.

Consider it removed.

> Alan G.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

More information about the Tutor mailing list