Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #96883 > unrolled thread

Started to work with SQLite3 in Python3

Started byCecil Westerhof <Cecil@decebal.nl>
First post2015-09-20 17:49 +0200
Last post2015-09-20 21:03 +0200
Articles 5 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Started to work with SQLite3 in Python3 Cecil Westerhof <Cecil@decebal.nl> - 2015-09-20 17:49 +0200
    Re: Started to work with SQLite3 in Python3 Chris Angelico <rosuav@gmail.com> - 2015-09-21 02:44 +1000
      Re: Started to work with SQLite3 in Python3 Cecil Westerhof <Cecil@decebal.nl> - 2015-09-20 20:40 +0200
    Re: Started to work with SQLite3 in Python3 Cecil Westerhof <Cecil@decebal.nl> - 2015-09-20 20:57 +0200
    Re: Started to work with SQLite3 in Python3 Cecil Westerhof <Cecil@decebal.nl> - 2015-09-20 21:03 +0200

#96883 — Started to work with SQLite3 in Python3

FromCecil Westerhof <Cecil@decebal.nl>
Date2015-09-20 17:49 +0200
SubjectStarted to work with SQLite3 in Python3
Message-ID<87fv29rsyn.fsf@Equus.decebal.nl>
I started a little project in Python3 with SQLite3:
    https://github.com/CecilWesterhof/CarApplication

I do not mind to get some feedback on it.

I was wondering about two things:
- Would it be better to split the code into several parts. (For
  example the SQL statements.)
- I understood that with
    for fuel in fuel_cursor:
  a fetchall will be executed.
  At the moment I do not see this as a problem, but if the table would
  become very big it could. Would it be better to rewrite it with a
  fetchone?
  But that is then needed inside and before the loop. What would be a
  little ugly.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [next] | [standalone]


#96886

FromChris Angelico <rosuav@gmail.com>
Date2015-09-21 02:44 +1000
Message-ID<mailman.43.1442767480.21674.python-list@python.org>
In reply to#96883
On Mon, Sep 21, 2015 at 1:49 AM, Cecil Westerhof <Cecil@decebal.nl> wrote:
> - I understood that with
>     for fuel in fuel_cursor:
>   a fetchall will be executed.
>   At the moment I do not see this as a problem, but if the table would
>   become very big it could. Would it be better to rewrite it with a
>   fetchone?
>   But that is then needed inside and before the loop. What would be a
>   little ugly.

It iterates over the query, but it doesn't fetchall() into a list. So
it's as good as using fetchone().

ChrisA

[toc] | [prev] | [next] | [standalone]


#96890

FromCecil Westerhof <Cecil@decebal.nl>
Date2015-09-20 20:40 +0200
Message-ID<874miprl2q.fsf@Equus.decebal.nl>
In reply to#96886
On Sunday 20 Sep 2015 18:44 CEST, Chris Angelico wrote:

> On Mon, Sep 21, 2015 at 1:49 AM, Cecil Westerhof <Cecil@decebal.nl> wrote:
>> - I understood that with for fuel in fuel_cursor: a fetchall will
>> be executed. At the moment I do not see this as a problem, but if
>> the table would become very big it could. Would it be better to
>> rewrite it with a fetchone? But that is then needed inside and
>> before the loop. What would be a little ugly.
>
> It iterates over the query, but it doesn't fetchall() into a list.
> So it's as good as using fetchone().

You are right. I found this:
    http://pythoncentral.io/introduction-to-sqlite-in-python/
where at:
    Retrieving Data (SELECT) with SQLite
it says:
    The cursor object works as an iterator, invoking fetchall()
    automatically:
but all other places (I did a more extended search now) say the same
as you. So this problem is solved. :-)

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [next] | [standalone]


#96891

FromCecil Westerhof <Cecil@decebal.nl>
Date2015-09-20 20:57 +0200
Message-ID<87zj0grk95.fsf@Equus.decebal.nl>
In reply to#96883
On Sunday 20 Sep 2015 17:49 CEST, Cecil Westerhof wrote:

> I started a little project in Python3 with SQLite3:
> https://github.com/CecilWesterhof/CarApplication
>
> I do not mind to get some feedback on it.

I think I found a bug. In init I should put a:
    conn.commit()
after:
    fill_tables()

At the moment it is not a problem, but if the program gets some
functionality and would crash after a long run, the changes would be
lost.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [next] | [standalone]


#96893

FromCecil Westerhof <Cecil@decebal.nl>
Date2015-09-20 21:03 +0200
Message-ID<87vbb4rjzp.fsf@Equus.decebal.nl>
In reply to#96883
On Sunday 20 Sep 2015 17:49 CEST, Cecil Westerhof wrote:

> I started a little project in Python3 with SQLite3:
> https://github.com/CecilWesterhof/CarApplication
>
> I do not mind to get some feedback on it.
>
> I was wondering about two things:
> - Would it be better to split the code into several parts. (For
> example the SQL statements.)

I changed this part. I put the initialisation of the variables with
SQL statements into sqlStatements.py and use in the program:
    from sqlStatements import *

Is this the correct way of doing this?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web