Skip to content

Instantly share code, notes, and snippets.

@ratozumbi
Last active February 2, 2021 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ratozumbi/2b7b7fb9f23f6bb797c46469a904b20e to your computer and use it in GitHub Desktop.
Save ratozumbi/2b7b7fb9f23f6bb797c46469a904b20e to your computer and use it in GitHub Desktop.
How to use variables in SQLite
PRAGMA temp_store = 2;
CREATE TEMP TABLE _Variables(Name TEXT PRIMARY KEY, RealValue REAL, IntegerValue INTEGER, BlobValue BLOB, TextValue TEXT);
/*pergunta 1 linha 3*/
insert into main.pergunta (descricao, dificuldade, cod_quiz, cod_especialidade) values ('Podemos utilizar o cateter Power PICC® para infusão de contraste?', 1, 1, 7);
/* Declaring a variable */
INSERT INTO _Variables (Name, IntegerValue) VALUES ('pergunta_id',(SELECT last_insert_rowid()) );
-- UPDATE _Variables SET IntegerValue = (SELECT last_insert_rowid()) WHERE Name = 'pergunta_id';
insert into main.resposta (id_pergunta, descricao,certa) values ((SELECT IntegerValue FROM _Variables WHERE Name = 'pergunta_id' LIMIT 1), 'Sim', 1);
insert into main.resposta (id_pergunta, descricao,certa) values ((SELECT IntegerValue FROM _Variables WHERE Name = 'pergunta_id' LIMIT 1), 'Não', 0);
-- reference: https://stackoverflow.com/questions/7739444/declare-variable-in-sqlite-and-use-it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment