<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">2014-11-14 11:43 GMT-03:00 Michael Van Canneyt <span dir="ltr"><<a href="mailto:michael@freepascal.org" target="_blank">michael@freepascal.org</a>></span>:<br><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="">
On Fri, 14 Nov 2014, Marcos Douglas wrote:<br>
<br></span><span class=""></span><br><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
This RETURNING clause works for all DBMS?<br>
</blockquote>
<br></span>
AFAIK Only sqlite does not (maybe it does today). But that is not a DBMS :-)<span class=""><br></span></blockquote><div><br></div><div>MySQL also does not implement it<br><br></div><div>This is the workaround i use today:<br><br>var<br> Info: TSQLStatementInfo; <br> ActualConnection: TSQLConnection;<br> InsertQuery: TSQLQuery;<br>begin<br> Result := '';<br> if (FConnection is TSQLConnector) then <br> ActualConnection := TSQLConnectorAccess(FConnection).Proxy<br> else<br> ActualConnection := FConnection;<br><br> Info := TSQLConnectionAccess(ActualConnection).GetStatementInfo(Query.SQL.Text, True, stNoSchema);<br> InsertQuery := CreateInsertQuery(Query, Info.TableName, ActualConnection.FieldNameQuoteChars);<br> try<br> if (ActualConnection is TPQConnection) or (ActualConnection is TIBConnection) then<br> begin<br> InsertQuery.SQL.Add(Format('Returning %s', [FPrimaryKey]));<br> InsertQuery.Open;<br> if InsertQuery.RecordCount > 0 then<br> Result := InsertQuery.Fields[0].AsString;<br> ActualConnection.Transaction.CommitRetaining;<br> end<br> else<br> begin<br> InsertQuery.ExecSQL;<br> ActualConnection.Transaction.CommitRetaining;<br> if (ActualConnection is TSQLite3Connection) then<br> Result := IntToStr(TSQLite3Connection(ActualConnection).GetInsertID)<br> else if (ActualConnection is TConnectionName{MySql}) then<br> Result := IntToStr(TConnectionName(ActualConnection).GetInsertID);<br> end;<br> finally<br> InsertQuery.Destroy;<br> end;<br>end;<br><br></div><div>Luiz<br></div><br></div></div></div>