I have some MariaDB code, which I'm fairly new to. I'm a seasoned MSSQL developer, however. I have a script with a variable which I'm setting to what will eventually be the contents of a file. This it is 51k characters long and ends up being a LONGTEXT. I have determined this by putting it into a temp table and checking the resulting datatype. Basically I'm taking the file contents and turning it into lines of data for subsequent processing.
My code looks like this:
SET @FileData = <51k chars of text>;
SET @LineIndex = 1;
SET @FileDataLen = LENGTH(@FileData);
WHILE @FileDataLen > 0 DO
SET @Chunk = LEFT(@FileData, 1000);
SET @Pos = INSTR(@Chunk, "\r\n");
IF (@Pos = 1) THEN
SET @LineData = "";
SET @FileData = SUBSTRING(@FileData, 3); -- skip the CRLF
ELSE
SET @LineData = LEFT(@FileData, @Pos);
SET @FileData = SUBSTRING(@FileData, @Pos+2);
END IF;
INSERT INTO TextFileLine
(TextFileID,
LineIndex,
LineValue)
VALUES (@TextFileID,
@LineIndex,
@LineData);
SET @LineIndex = @LineIndex + 1;
SET @FileDataLen = LENGTH(@FileData);
END WHILE;
I'm getting the error (that stunningly informative error, which appear to be the only one that MariaDB is capable of generating): "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 2".
Query: WHILE @FileDataLen > 0 DO SET @Chunk = LEFT(@FileData, 1000)
Is it to do with my WHILE loop? Is it to do with using LEFT on LONGTEXT? I've tried fiddling around with both statements to no avail.
Thanks for any help provided.