Have you got auto_increment on the id field? http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html
Seems last_insert_id() looks at the previously-run SQL statement that performed an INSERT. If you're running this query in a separate program, or have done other SQL operations since the INSERT on the editprojects table, you may well get 0 back. Why not try select max(id) from editprojects? Guess it depends what you really want... the id of the last-inserted record, or the maximum id used until now so you can assign the 'next' id... of course if you use auto_increment, you may not need the last id as it'll all happen automatically... Kind regards, Caveat On 17/07/12 13:14, Bill-Lancaster wrote: > I have a table (editprojects) with "id" as primary key, serial, integer. > There is only one record at the moment (id = 1) > hResult = hConn.Exec("SELECT last_insert_id() as id FROM editprojects") > print hResult!id > produces 0 not 1 > > Obviously my sql query is at fault but where? > > I wonder if anyone can help. ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user