0

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.

Mark Roworth
  • 409
  • 2
  • 15
  • (1) MySQL <> MariaDB !!! (2) DELIMITER seems to be lost. – Akina May 17 '23 at 14:55
  • Thanks @Akina. I'm actually quite confused between MariaDB and MySQL. What's the difference? I assumed that MariaDB was an internal name for MySQL. – Mark Roworth May 17 '23 at 15:00
  • Sorry, should have just googled it. Short answer: "MySQL is the largest open source database community. MariaDB is a fork from MySQL and is 100% compatible with prior versions of MySQL. However, while the charter for MariaDB remains open source and cross-platform, the future is unclear for MySQL." Not sure if this affects the issue above or not. The semi-colon is definitely there in the code being executed. – Mark Roworth May 17 '23 at 15:02
  • You said you're a user of Microsoft SQL Server. Is Microsoft SQL Server the same as Sybase? It isn't, right? But in fact, Microsoft SQL Server started as a fork from code that they licensed from Sybase in 1993. Since then, both Sybase and Microsoft continued making changes to their respective code, and while they were both nearly compatible at first, they gradually became less and less compatible. That's similar to the relationship between MySQL and MariaDB, but their fork occurred in 2010. – Bill Karwin May 17 '23 at 15:10
  • You can run `SELECT VERSION();` to confirm which brand you're currently using. Based on the error message you show, I think it's some release of MariaDB. You should tag your question on Stack Overflow accurately, because an answer someone suggests might not work for you, if their solution uses a feature implemented only in MySQL. That won't help you, and it'll waste the time of the person who went to the effort of posting the answer. – Bill Karwin May 17 '23 at 15:13
  • @Bill Karwin - ok, thanks, I wasn't aware of that distinction, as indicated above. – Mark Roworth May 17 '23 at 15:16
  • It's understandable. The folks at MariaDB are to blame for confusing the market. On the one hand, they talk trash about Oracle and MySQL frequently, but on the other hand, they continue to claim compatibility to try to give their product credibility. As technology, the MariaDB product has merit, but I refuse to use them because of their dishonest marketing. – Bill Karwin May 17 '23 at 15:18

0 Answers0