This code does work, but when you start the program it returns 0.
Only after having inserted a new row into the database you will get the right value.
I used in the SQLiteDB program a column 'Code' as INETEGER PRIMARY KEY and the max() function. So I get the highest rowid which is the last inserted row.
I've already used the method of Klaus as a workaround. But the method of Erel (which works fine) seems to be a little bit saver - enclosing the INSERT and the SELCT in just one transmission. It's just a feeling, it has to be proved yet.