I’m completely new to SQLite and I’m stuck in the RNA Transcription exercise for SQLite. My code won’t pass the last test.
Instructions
Your task is determine the RNA complement of a given DNA sequence.
Both DNA and RNA strands are a sequence of nucleotides.
The four nucleotides found in DNA are adenine (A), cytosine (C), guanine (G) and thymine (T).
The four nucleotides found in RNA are adenine (A), cytosine (C), guanine (G) and uracil (U).
Given a DNA strand, its transcribed RNA strand is formed by replacing each nucleotide with its complement:
G → C
C → G
T → A
A → U
– Schema: CREATE TABLE “rna-transcription” (“dna” TEXT, “result” TEXT);
– Task: update the rna-transcription table and set the result based on the dna field.
Last test result: Result for "ACGTGGTCTTAA" is "", but should be "UGCACCAGAAUU"
I think I need to loop through every letter of the string in order to check each letter, but I can’t find anyting helpful in the documentation nor in other places online. How do I loop through a string in SQLite?
None of the community solutions loop through the string. They take a different approach (hint below in a spoiler if you want it).
Hint
They all manipulate the string, rather than iterating through it it
Someone else can probably explain how you could achieve looping (I guess by splitting the string into a temporary table and iterating over the rows), but until then, this might unblock you
First things first:
The SQLite track uses the general exercise pool from exercism that is shared by all the languages. It is not necessarily a good fit for a SQL-language but it is possible to solve them, but you might need unconventional means. The track is very young and might prove challenging, if you use it to learn SQL, as it is not (yet) fitted to handle real-life database problems.
For looping:
SQLite does not have a traditional looping method. An (hideously complicated) alternative, is a trigger that’s recursively called until your loop condition is reached.
Thank you all for the answers. I’ve managed to solve it without looping. I nested the cases with the help of ChatGPT after giving up on finding a solution on my own. It wasn’t perfect, though. I still had to modify the answer to make it work properly.