search

Home  >  Q&A  >  body text

Execute stored procedures containing SQL scripts using Robot Framework

<p>I want to run a sql script that contains database and table creation and stored procedure creation. But when I try to run the sql script in the <strong>database library</strong> using the <strong>execute sql script</strong> keyword, I get the following error: </p> <pre class="brush:php;toolbar:false;">ProgrammingError: (1064, "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 'DELIMITER $$\n CREATE OR REPLACE PROCEDURE `proc_GetCustomerDetails`(\n I...' at line 2")</pre> <p>Before the stored procedure, I have this <strong>delimiter</strong>: </p> <pre class="brush:php;toolbar:false;">DELIMITER $$ CREATE OR REPLACE PROCEDURE `proc_GetCustomerDetails`( IN CustomerNbr LONGTEXT, IN LANG VARCHAR(5) ) DETERMINISTIC BEGIN IF Lang IS NULL THEN SET lang = "fin"; END IF; SELECT * from dbname.customer; END;$$ DELIMITER ;</pre> <p>If I comment out the stored procedure part, the sql file will run without errors along with the rest of the table creation statements. </p> <p>I searched on Google and found no related questions. I see we have keywords that call stored procedures. But I want to put table creation and stored procedure in the same sql file and run it. I am using MariaDB for this task. </p> <p><strong>Libraries used</strong>: </p> <ul> <li>pymysql</li> <li>Robot Framework Database Library</li> </ul> <p>If I run the sql file using HeidiSQL, it runs within the stored procedure and delimiter without any errors. This means there are no sql errors. </p> <p><strong>Can anyone tell me how to fix this? </strong></p>
P粉031492081P粉031492081484 days ago518

reply all(1)I'll reply

  • P粉268284930

    P粉2682849302023-08-29 11:03:12

    DELIMITER is a client-only statement, the server does not support it, hence the error. Solution - delete it.

    Here is a question with a very good answer that explains what DELIMITER is and why it is needed.

    In short - when you are working with a client you need a way to indicate to it "this is not an immediately executed statement, this is still just a line in the stored procedure that you will send to the server" - so You tell (the client) "DELIMITER between statements is $$ temporarily". The server doesn't need/care about this - it knows that everything between CREATE PROCEDURE, BEGIN, END is a connected statement, a block.

    When you connect to the database via API (pymysql), compared to interactive clients (shell, heidisql, etc.) - you send the SP as a chunk and there is no way to run its statements one by one, so DELIMITER is not needed , the server does not support the command and an error will be generated. Delete it.

    reply
    0
  • Cancelreply