I'm practicing with Genie + SQLite and I'm blocked when I try to make a query.
uses Sqlite
init
db : Sqlite.Database
Sqlite.Database.open ("agenda.db3", out db)
db.exec ("CREATE TABLE Contactos (pkiD INTEGER PRIMARY KEY, nombre TEXT UNIQUE, phone INTEGER)")
stdout.printf( "Nuevo contacto: " )
contacto_nombre:string = stdin.read_line()
stdout.printf( "Teléfono: " )
contacto_phone:string = stdin.read_line()
enter:string = @"INSERT INTO Contactos (nombre, phone) VALUES ('$contacto_nombre', $contacto_phone)"
// if contacto_nombre exists ????????????
//"SELECT nombre FROM Contactos WHERE nombre = 'contacto_nombre'" ????
//stdout.printf("%s ya está en la Agenda.\n", contacto_nombre)
//else
db.exec (enter)
How can I check if a value already exists? Thank you.
Well, I do not know if this is the best way to do it, but I have found this solution.