Last active
February 2, 2021 00:01
-
-
Save ratozumbi/2b7b7fb9f23f6bb797c46469a904b20e to your computer and use it in GitHub Desktop.
How to use variables in SQLite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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