Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mutliple SQL statements in a single HTTP Request - metamug

Tags:

rest

metamug

In the following resource file, I'm trying to perform 2 insert operations for the same request.(form submit)

But getting 500 error from the API.

<?xml version="1.0" encoding="UTF-8" ?>
<Resource xmlns="http://xml.metamug.net/resource/1.0" v="1.0">
    <Request method="POST">
        <Desc> CRICKET INFO </Desc>
        <Update>
          insert into CRICKET (NAME,DOB,BATTING_STYLE,BOWLING_STYLE,TEAM)
          values($xname,$birthdate,$batstyle,$bowlstyle,$st); 
          insert into DETAILS (FORMAT,RUNS,WICKETS,AVERAGE)
          values($sf,$rns,$wkts,$avg);
        </Update>
    </Request>
</Resource>

1 Answers

You'll have to use <Sql> tag twice to achieve this, you can't write more than one query inside a single <Sql>.
So your resource file should be like this

<?xml version="1.0" encoding="UTF-8" ?>
<Resource xmlns="http://xml.metamug.net/resource/1.0" v="1.0">
    <Request method="POST">
        <Desc> CRICKET INFO </Desc>
        <Sql id="first">
          insert into CRICKET (NAME,DOB,BATTING_STYLE,BOWLING_STYLE,TEAM)
          values($xname,$birthdate,$batstyle,$bowlstyle,$st); 
        </Sql>
        <Sql id="second">
          insert into DETAILS (FORMAT,RUNS,WICKETS,AVERAGE)
          values($sf,$rns,$wkts,$avg);
        </Sql>
    </Request>
</Resource>
like image 182
Kainix Avatar answered Mar 21 '26 12:03

Kainix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!