Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for string fields as Id column, #43

Merged
merged 8 commits into from
Jun 22, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
New functioon TSession.LoadSQL
  • Loading branch information
dforstner committed Jun 22, 2017
commit 91d7f2865e26bbfb2e685fd5d7dd95673d81dbdc
4 changes: 0 additions & 4 deletions source/dorm.Filters.pas
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ function NewCriteria(const Attribute: string; CompareOperator: TdormCompareOpera

implementation

uses
dorm.Commons,
dorm.Utils;

function NewCriteria(Criteria: ICriteria): ICriteria;
begin
Result := TdormCriteria.NewCriteria(Criteria);
Expand Down
6 changes: 0 additions & 6 deletions source/dorm.adapter.FireDac.BaseAdapter.pas
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,11 @@ function TFireDACBaseAdapter.Update(ARttiType: TRttiType; AObject: TObject; AMap
pk_field: string;
isTransient: boolean;
isNullable: boolean;
pk_mapping_index: Integer;
PKMappingIndexes: TIntegerDynArray;
begin
sql_fields_names := GetSqlFieldsForUpdate(AMappingTable, AObject);
// pk_field aufblasen f�r where
PKMappingIndexes := GetPKMappingIndexes(AMappingTable.Fields);
if Length(PKMappingIndexes) > 0 then begin
pk_mapping_index := PKMappingIndexes[0];
end else begin
pk_mapping_index := -1;
end;
pk_field := AMappingTable.Fields[PKMappingIndexes[0]].FieldName;
SQL := Format('UPDATE %S SET %S WHERE [%S] = :' + pk_field, [AMappingTable.TableName, sql_fields_names, pk_field]);
for I := 1 to Length(PKMappingIndexes) - 1 do begin
Expand Down
19 changes: 18 additions & 1 deletion source/dorm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ TSession = class(TdormInterfacedObject, IdormSession)
: boolean; overload;
{ Load 0 or 1 object by Criteria. The Session will create and returned object of type <T> }
function Load<T: class>(ACriteria: ICriteria): T; overload;
{ Load 0 or 1 object by SQL-Whereclause. The Session will create and returned object of type <T> }
function LoadSQL<T: class>(const _WhereClause : string; _WithNoLock : boolean = false): T;
{ Load all the objects that satisfy the Criteria. The Session will fill the list (ducktype) passed on 2nd parameter with objects of type <T> }
procedure LoadList<T: class>(Criteria: ICriteria;
AObject: TObject); overload;
Expand Down Expand Up @@ -316,7 +318,7 @@ implementation

uses
dorm.Adapters,
dorm.Utils;
dorm.Utils, System.StrUtils;
{ TSession }

procedure TSession.AddAsLoadedObject(AObject: TObject;
Expand Down Expand Up @@ -2344,4 +2346,19 @@ function TSession.Load(APTypeInfo: PTypeInfo; ASQLable: ISQLable): TObject;
GetLogger.ExitLevel('Load(SQL)');
end;

function TSession.LoadSQL<T>(const _WhereClause : string; _WithNoLock : boolean = false): T;
var
Table: TMappingTable;
rt: TRttiType;
CustomCrit: ICustomCriteria;
ItemTypeInfo: PTypeInfo;
begin
ItemTypeInfo := T.ClassInfo;
rt := FCTX.GetType(ItemTypeInfo);
Table := FMappingStrategy.GetMapping(rt);
CustomCrit := TSQLCustomCriteria.Create('select top 1 * from ' + Table.TableName +
IfThen(_WithNoLock, ' with(nolock)','') + ' where ' + _WhereClause); //TODO: Nolock nur f�r MSSQL!
Result := Load<T>(CustomCrit);
end;

end.