On 9/27/2018 3:24 PM, dev.vide...@gmail.com wrote:
Olá, sou iniciante no racket. Gostaria de capturar o valor
*insert-id* que retorna em um uma struct chama simple-result
executo. O retorno é o seguinte:
|(simple-result '((insert-id . 30) (affected-rows . 1))) |
Gostaria de obter o valor *30* por exemplo.
Código da execução da query:
|(define save_pergunta (lambda (tf_pergunta) (define
result_save_pergunta (query conn "INSERT INTO perguntas VALUES (null,
$pergunta)" tf_pergunta)) (print result_save_pergunta) (printf
*simple-result* is a struct - you need to extract what you want from the
association list in the info field.
The function to extract a field from a struct is [usually] the
concatenation of the field name with the struct name: so the *info*
field in *simple-result* would be (*simple-result-info* <the-struct>).
You find an entry in an association list with *assoc* [or *assv* or
*assq* depending on the type of the key]. The entry itself is a cons
pair, so you need to extract the 2nd value in a pair with *cdr*.
So to get the identifier you need to do something like the following:
(result (query conn "insert into questions values
(cdr (assoc 'insert-id (simple-result-info result))))
Note the above is not checking for errors. You should always check that
the result really is a simple-result before trying to extract the info
because query can return other kinds of results (including no results
... query can throw an exception if it fails).
Hope this helps,
You received this message because you are subscribed to the Google Groups "Racket
To unsubscribe from this group and stop receiving emails from it, send an email
For more options, visit https://groups.google.com/d/optout.