function TServerMethods1.ExecuteSql(const sql: String): Boolean;
var
d: TfrmDB;
begin
d := DBPool.Lock;
if Assigned(d) then
begin
try
try
d.qry.Close;
d.qry.sql.Clear;
d.qry.sql.Text := sql;
d.qry.ExecSQL;
Result := true;
except
on e: Exception do
begin
Result := false;
Log.WriteLog(‘TServerMethods1.ExecuteSql ‘ + e.Message);
end;
end;
finally
DBPool.Unlock(d);
end;
end
else
begin
Result := false;
end;
end;
function TServerMethods1.QuerySql(const sql: String): OleVariant;
var
d: TfrmDB;
begin
d := DBPool.Lock;
if Assigned(d) then
begin
try
try
d.qry.Close;
d.qry.sql.Clear;
d.qry.sql.Text := sql;
d.qry.Open;
Result := d.dsp.Data;
except
on e: Exception do
begin
Result := null;
Log.WriteLog(‘TServerMethods1.QuerySql ‘ + e.Message);
end;
end;
finally
DBPool.Unlock(d);
end;
end
else
begin
Result := null;
end;
end;
function TServerMethods1.QuerySql2(const sql: string): TFDJSONDataSets;
var
d: TfrmDB;
begin
d := DBPool.Lock;
if Assigned(d) then
begin
try
try
d.qry.Close;
d.qry.sql.Clear;
d.qry.Open(sql);
Result := TFDJSONDataSets.Create;
TFDJSONDataSetsWriter.ListAdd(Result, d.qry);
except
on e: Exception do
begin
Result := nil;
Log.WriteLog(‘TServerMethods1.QuerySql2 ‘ + e.Message);
end;
end;
finally
DBPool.Unlock(d);
end;
end
else
Result := nil;
end;
function TServerMethods1.SaveData(const tableName: String;
delta: OleVariant): Boolean;
var
d: TfrmDB;
errCnt: Integer;
begin
d := DBPool.Lock;
if Assigned(d) then
begin
try
try
d.qry.Close;
d.qry.sql.Clear;
d.qry.sql.Text := ‘select * from ‘ + tableName + ‘ where 1=2‘;
d.qry.Open;
d.dsp.ApplyUpdates(delta, 0, errCnt);
if errCnt = 0 then
Result := true
else
Result := false;
except
on e: Exception do
begin
Result := false;
Log.WriteLog(‘TServerMethods1.SaveData ‘ + e.Message);
end;
end;
finally
DBPool.Unlock(d);
end;
end
else
begin
Result := false;
end;
end;
function TServerMethods1.SaveData2(const tableName: string;
delta: TFDJSONDeltas): Boolean;
var
d: TfrmDB;
LApply: IFDJSONDeltasApplyUpdates;
begin
d := DBPool.Lock;
if Assigned(d) then
begin
try
try
d.qry.Close;
d.qry.sql.Clear;
d.qry.sql.Text := ‘select * from ‘ + tableName + ‘ where 1=2‘;
d.qry.Open;
LApply := TFDJSONDeltasApplyUpdates.Create(delta);
LApply.ApplyUpdates(tableName, d.qry.Command);
Result := LApply.Errors.Count = 0;
except
on e: Exception do
begin
Result := false;
Log.WriteLog(‘TServerMethods1.SaveData2 ‘ + e.Message);
end;
end;
finally
DBPool.Unlock(d);
end;
end
else
Result := false;
end;