[Tutor] Data conversion

Alan Gauld alan.gauld at btinternet.com
Thu May 19 20:05:07 CEST 2011


"Joe Aquilina" <joe at chem.com.au> wrote

> I have a (single table) database file (SQLite3). It has one table, 
> call it literature, with an integer, autoincrement primary key 
> field. I have created a data entry form in Python that I want to use 
> to enter new rows into this database file. On the data entry form I 
> will enter the values for a new table row - all except the primary 
> key field.
>
> What I want to be able to do is to have my data entry form 
> autoincrement this primary key field for me, with no ability to 
> change the contents on the data entry form, and save this 
> incremented value as the value of the num field when I save the new 
> row.

Can I ask you why you are trying to do this yourself?
Its normal to let the database generate the key - thats why
you define it as autoincrement. If you try to double guess
the value and the database is doing something in the
background you could get in an awful mess!

Either define the ID field as a normal int and you do the
autoincrement (by fetching the highest value and adding one)
or leave it as autoincrement and let the database do
its job.

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list