2019-02-21 20:17:11 +01:00
|
|
|
// *************************************************************************** }
|
|
|
|
//
|
|
|
|
// Delphi MVC Framework
|
|
|
|
//
|
2020-01-06 16:49:18 +01:00
|
|
|
// Copyright (c) 2010-2020 Daniele Teti and the DMVCFramework Team
|
2019-02-21 20:17:11 +01:00
|
|
|
//
|
|
|
|
// https://github.com/danieleteti/delphimvcframework
|
|
|
|
//
|
|
|
|
// ***************************************************************************
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
// ***************************************************************************
|
|
|
|
|
|
|
|
unit MVCFramework.SQLGenerators.Interbase;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
System.Rtti,
|
|
|
|
System.Generics.Collections,
|
|
|
|
FireDAC.Phys.IB,
|
|
|
|
FireDAC.Phys.IBDef,
|
|
|
|
MVCFramework.ActiveRecord,
|
|
|
|
MVCFramework.Commons,
|
|
|
|
MVCFramework.SQLGenerators.Firebird,
|
|
|
|
MVCFramework.RQL.Parser;
|
|
|
|
|
|
|
|
type
|
|
|
|
TMVCSQLGeneratorInterbase = class(TMVCSQLGeneratorFirebird)
|
2020-01-08 15:30:10 +01:00
|
|
|
public
|
|
|
|
function CreateInsertSQL(const TableName: string;
|
2020-03-25 11:35:25 +01:00
|
|
|
const Map: TFieldsMap;
|
2020-01-08 15:30:10 +01:00
|
|
|
const PKFieldName: string;
|
|
|
|
const PKOptions: TMVCActiveRecordFieldOptions): string; override;
|
|
|
|
function HasReturning: Boolean; override;
|
2019-02-21 20:17:11 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2020-01-08 15:30:10 +01:00
|
|
|
uses
|
|
|
|
System.SysUtils;
|
|
|
|
|
|
|
|
{ TMVCSQLGeneratorInterbase }
|
|
|
|
|
|
|
|
function TMVCSQLGeneratorInterbase.CreateInsertSQL(const TableName: string;
|
2020-03-25 11:35:25 +01:00
|
|
|
const Map: TFieldsMap;
|
2020-01-08 15:30:10 +01:00
|
|
|
const PKFieldName: string;
|
|
|
|
const PKOptions: TMVCActiveRecordFieldOptions): string;
|
|
|
|
var
|
2020-03-25 11:35:25 +01:00
|
|
|
lKeyValue: TPair<TRttiField, TFieldInfo>;
|
2020-01-08 15:30:10 +01:00
|
|
|
lSB: TStringBuilder;
|
2020-06-19 19:31:34 +02:00
|
|
|
lPKInInsert: Boolean;
|
2020-01-08 15:30:10 +01:00
|
|
|
begin
|
2020-06-24 23:51:06 +02:00
|
|
|
lPKInInsert := (not PKFieldName.IsEmpty); // and (not(TMVCActiveRecordFieldOption.foAutoGenerated in PKOptions));
|
2020-08-11 00:54:42 +02:00
|
|
|
lPKInInsert := lPKInInsert and (not(TMVCActiveRecordFieldOption.foReadOnly in PKOptions));
|
2020-01-08 15:30:10 +01:00
|
|
|
lSB := TStringBuilder.Create;
|
|
|
|
try
|
|
|
|
lSB.Append('INSERT INTO ' + TableName + '(');
|
2020-06-19 19:31:34 +02:00
|
|
|
if lPKInInsert then
|
2020-03-27 00:37:28 +01:00
|
|
|
begin
|
|
|
|
lSB.Append(PKFieldName + ',');
|
|
|
|
end;
|
2020-01-08 15:30:10 +01:00
|
|
|
for lKeyValue in Map do
|
2020-03-25 11:35:25 +01:00
|
|
|
begin
|
|
|
|
if lKeyValue.Value.Writeable then
|
|
|
|
begin
|
2020-06-24 23:51:06 +02:00
|
|
|
lSB.Append(lKeyValue.Value.FieldName + ',');
|
2020-03-25 11:35:25 +01:00
|
|
|
end;
|
|
|
|
end;
|
2020-01-08 15:30:10 +01:00
|
|
|
|
|
|
|
lSB.Remove(lSB.Length - 1, 1);
|
|
|
|
lSB.Append(') values (');
|
2020-06-19 19:31:34 +02:00
|
|
|
if lPKInInsert then
|
2020-01-08 15:30:10 +01:00
|
|
|
begin
|
2020-03-27 00:37:28 +01:00
|
|
|
lSB.Append(':' + PKFieldName + ',');
|
2020-01-08 15:30:10 +01:00
|
|
|
end;
|
2020-03-27 00:37:28 +01:00
|
|
|
for lKeyValue in Map do
|
2020-01-08 15:30:10 +01:00
|
|
|
begin
|
2020-06-24 23:51:06 +02:00
|
|
|
if lKeyValue.Value.Writeable then
|
|
|
|
begin
|
|
|
|
lSB.Append(':' + lKeyValue.Value.FieldName + ',');
|
|
|
|
end;
|
2020-01-08 15:30:10 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
lSB.Remove(lSB.Length - 1, 1);
|
|
|
|
lSB.Append(')');
|
|
|
|
Result := lSB.ToString;
|
|
|
|
finally
|
|
|
|
lSB.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TMVCSQLGeneratorInterbase.HasReturning: Boolean;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
end;
|
|
|
|
|
2019-02-21 20:17:11 +01:00
|
|
|
initialization
|
|
|
|
|
|
|
|
TMVCSQLGeneratorRegistry.Instance.RegisterSQLGenerator('interbase',
|
|
|
|
TMVCSQLGeneratorInterbase);
|
|
|
|
|
|
|
|
finalization
|
|
|
|
|
|
|
|
TMVCSQLGeneratorRegistry.Instance.UnRegisterSQLGenerator('interbase');
|
|
|
|
|
|
|
|
end.
|