Skip to content

Commit

Permalink
Various minor changes. #20
Browse files Browse the repository at this point in the history
  • Loading branch information
bero committed Dec 6, 2024
1 parent c8ef5b6 commit 6889b1b
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 168 deletions.
126 changes: 64 additions & 62 deletions Source/BoldDbValidator.pas
Original file line number Diff line number Diff line change
Expand Up @@ -122,83 +122,85 @@ procedure TBoldDbValidator.CheckTypeTableConsistency(SystemSQLMapper: TBoldSyste
begin
query := SystemSQLMapper.GetQuery;
ExecQuery := SystemSQLMapper.GetExecQuery;
query.AssignSQLText(format('SELECT * FROM %s', [TypeTableName]));
try
query.AssignSQLText(format('SELECT * FROM %s', [TypeTableName]));

HighestBoldDbType := -1;
HighestBoldDbType := -1;

Query.Open;
BoldDBTypeField := Query.FieldByName('BOLD_TYPE');
ClassNameField := Query.FieldByName('CLASSNAME');
while not query.eof do
begin
BoldDbType := BoldDBTypeField.AsInteger;
if BoldDbType > HighestBoldDbType then
HighestBoldDbType := BoldDbType;
Query.Open;
BoldDBTypeField := Query.FieldByName('BOLD_TYPE');
ClassNameField := Query.FieldByName('CLASSNAME');
while not query.eof do
begin
BoldDbType := BoldDBTypeField.AsInteger;
if BoldDbType > HighestBoldDbType then
HighestBoldDbType := BoldDbType;

Name := ClassNameField.AsString;
Name := ClassNameField.AsString;

Found := false;
for i := 0 to SystemSQLMapper.ObjectPersistenceMappers.count - 1 do
begin
if assigned(SystemSQLMapper.ObjectPersistenceMappers[i]) and
(CompareText(SystemSQLMapper.ObjectPersistenceMappers[i].ExpressionName, Name) = 0) then
Found := false;
for i := 0 to SystemSQLMapper.ObjectPersistenceMappers.count - 1 do
begin
ObjectPMapper := SystemSQLMapper.ObjectPersistenceMappers[i] as TBoldObjectSQLMapper;
ObjectPMapper.BoldDbType := BoldDbType;
Found := true;
Break;
if assigned(SystemSQLMapper.ObjectPersistenceMappers[i]) and
(CompareText(SystemSQLMapper.ObjectPersistenceMappers[i].ExpressionName, Name) = 0) then
begin
ObjectPMapper := SystemSQLMapper.ObjectPersistenceMappers[i] as TBoldObjectSQLMapper;
ObjectPMapper.BoldDbType := BoldDbType;
Found := true;
Break;
end;
end;
if not found then
BoldLog.LogFmt(sClassInDBNotInModel, [Name, BoldDbType]);
Query.Next;
end;
if not found then
BoldLog.LogFmt(sClassInDBNotInModel, [Name, BoldDbType]);
Query.Next;
end;
Query.Close;

MissingClasses := false;
for i := 0 to SystemSQLMapper.ObjectPersistenceMappers.count - 1 do
begin
ObjectPMapper := SystemSQLMapper.ObjectPersistenceMappers[i] as TBoldObjectSQLMapper;
if assigned(ObjectPMapper) and (ObjectPMapper.BoldDbType = -1) then
begin
if not MissingClasses then
BoldLog.Separator;
BoldLog.LogFmt(sClassWithMissingID, [ObjectPMapper.ExpressionName]);
MissingClasses := true;
end;
end;
Query.Close;

if MissingClasses and (MessageDlg(sCorrectClassWithNoID, mtConfirmation, [mbYes, mbNo], 0) = mrYes) then
begin
BoldLog.Separator;
Execquery.AssignSQLText(
format('INSERT INTO %s (%s, %s) VALUES (:%s, :%s)', [
TypeTablename,
TYPECOLUMN_NAME,
CLASSNAMECOLUMN_NAME,
TYPECOLUMN_NAME,
CLASSNAMECOLUMN_NAME]));

ExecQuery.ParamCheck := true;
TypeParam := ExecQuery.ParamByName(TYPECOLUMN_NAME);
ClassParam := ExecQuery.ParamByName(CLASSNAMECOLUMN_NAME);
MissingClasses := false;
for i := 0 to SystemSQLMapper.ObjectPersistenceMappers.count - 1 do
begin
ObjectPMapper := SystemSQLMapper.ObjectPersistenceMappers[i] as TBoldObjectSQLMapper;
if assigned(ObjectPMapper) and (ObjectPMapper.BoldDbType = -1) then
begin
Inc(HighestBoldDbType);
ObjectPMapper.BoldDbType := HighestBoldDbType;
BoldLog.LogFmt(sAddBoldDBTType, [ObjectPMapper.BoldDbType, ObjectPMapper.expressionName]);
TypeParam.AsInteger := HighestBoldDbType;
ClassParam.AsString := ObjectPMapper.ExpressionName;
ExecQuery.ExecSQL;
if not MissingClasses then
BoldLog.Separator;
BoldLog.LogFmt(sClassWithMissingID, [ObjectPMapper.ExpressionName]);
MissingClasses := true;
end;
end;
end;

SystemSQLMapper.ReleaseQuery(Query);
SystemSQLMapper.ReleaseExecQuery(ExecQuery);
if MissingClasses and (MessageDlg(sCorrectClassWithNoID, mtConfirmation, [mbYes, mbNo], 0) = mrYes) then
begin
BoldLog.Separator;
Execquery.AssignSQLText(
format('INSERT INTO %s (%s, %s) VALUES (:%s, :%s)', [
TypeTablename,
TYPECOLUMN_NAME,
CLASSNAMECOLUMN_NAME,
TYPECOLUMN_NAME,
CLASSNAMECOLUMN_NAME]));

ExecQuery.ParamCheck := true;
TypeParam := ExecQuery.ParamByName(TYPECOLUMN_NAME);
ClassParam := ExecQuery.ParamByName(CLASSNAMECOLUMN_NAME);
for i := 0 to SystemSQLMapper.ObjectPersistenceMappers.count - 1 do
begin
ObjectPMapper := SystemSQLMapper.ObjectPersistenceMappers[i] as TBoldObjectSQLMapper;
if assigned(ObjectPMapper) and (ObjectPMapper.BoldDbType = -1) then
begin
Inc(HighestBoldDbType);
ObjectPMapper.BoldDbType := HighestBoldDbType;
BoldLog.LogFmt(sAddBoldDBTType, [ObjectPMapper.BoldDbType, ObjectPMapper.expressionName]);
TypeParam.AsInteger := HighestBoldDbType;
ClassParam.AsString := ObjectPMapper.ExpressionName;
ExecQuery.ExecSQL;
end;
end;
end;
finally
SystemSQLMapper.ReleaseQuery(Query);
SystemSQLMapper.ReleaseExecQuery(ExecQuery);
end;
end;

procedure TBoldDbValidator.Activate;
Expand Down Expand Up @@ -265,4 +267,4 @@ function TBoldDbValidator.TypeTableName: String;
result := BoldExpandPrefix(TYPETABLE_NAME, '', PersistenceHandle.SQLDataBaseConfig.SystemTablePrefix, SystemSQLMapper.SQLDatabaseConfig.MaxDBIdentifierLength, SystemSQLMapper.NationalCharConversion);
end;

end.
end.
16 changes: 12 additions & 4 deletions Source/BoldFireDACInterfaces.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,8 @@ procedure TBoldFireDACConnection.Reconnect;
end;
end;

type TCollectionAccess = class(TCollection);

procedure TBoldFireDACConnection.ReleaseQuery(var Query: IBoldQuery);
var
lBoldFireDACQuery: TBoldFireDACQuery;
Expand All @@ -1140,6 +1142,10 @@ procedure TBoldFireDACConnection.ReleaseQuery(var Query: IBoldQuery);
begin
lBoldFireDACQuery := Query.Implementor as TBoldFireDACQuery;
lBoldFireDACQuery.clear;
while lBoldFireDACQuery.SQLStrings.Updating do
lBoldFireDACQuery.SQLStrings.EndUpdate;
while TCollectionAccess(lBoldFireDACQuery.Params).UpdateCount > 0 do
lBoldFireDACQuery.Params.EndUpdate;
Query := nil;
if not Assigned(fCachedQuery1) then
fCachedQuery1 := lBoldFireDACQuery
Expand All @@ -1159,13 +1165,15 @@ procedure TBoldFireDACConnection.ReleaseExecQuery(var Query: IBoldExecQuery);
if (Query.Implementor is TBoldFireDACQuery) then
begin
lBoldFireDACQuery := Query.Implementor as TBoldFireDACQuery;
if lBoldFireDACQuery.GetSQLStrings.Count <> 0 then
if lBoldFireDACQuery.SQLStrings.Count <> 0 then
begin
lBoldFireDACQuery.GetSQLStrings.BeginUpdate;
lBoldFireDACQuery.SQLStrings.BeginUpdate;
lBoldFireDACQuery.clear;
end;
while TStringsAccess(lBoldFireDACQuery.GetSQLStrings).UpdateCount > 0 do
lBoldFireDACQuery.GetSQLStrings.EndUpdate;
while lBoldFireDACQuery.SQLStrings.Updating do
lBoldFireDACQuery.SQLStrings.EndUpdate;
while TCollectionAccess(lBoldFireDACQuery.Params).UpdateCount > 0 do
lBoldFireDACQuery.Params.EndUpdate;
Query := nil;
if not Assigned(fCachedExecQuery1) then
fCachedExecQuery1 := lBoldFireDACQuery
Expand Down
9 changes: 6 additions & 3 deletions Source/BoldPMappers.pas
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,11 @@ procedure TBoldSystemPersistenceMapper.PMUpdate(ObjectIDList: TBoldObjectIdList;
Exit;
Guard := TBoldGuard.Create(ModifiedObjectIDList, NewObjectIDList, DeletedObjectIDList);
DeletedObjectIDList := TBoldObjectIdList.Create;
DeletedObjectIDList.OwnsEntries := false;
NewObjectIDList := TBoldObjectIdList.Create;
NewObjectIDList.OwnsEntries := false;
ModifiedObjectIDList := TBoldObjectIdList.Create;
ModifiedObjectIDList.OwnsEntries := false;

// downto order is important here - Daniel
for i := ObjectIDList.Count - 1 downto 0 do
Expand All @@ -540,11 +543,11 @@ procedure TBoldSystemPersistenceMapper.PMUpdate(ObjectIDList: TBoldObjectIdList;
if ObjectContents.BoldPersistenceState = bvpsModified then
begin
if ObjectContents.BoldExistenceState = besDeleted then
DeletedObjectIDList.Add(ObjectIDList[i])
DeletedObjectIDList.AddAndAdopt(ObjectIDList[i])
else
NewObjectIDList.Add(ObjectIDList[i]);
NewObjectIDList.AddAndAdopt(ObjectIDList[i]);
end else
ModifiedObjectIDList.Add(ObjectIDList[i]);
ModifiedObjectIDList.AddAndAdopt(ObjectIDList[i]);
end;

ReserveNewIds(ValueSpace, ObjectIdList, TranslationList);
Expand Down
18 changes: 17 additions & 1 deletion Source/BoldPMappersAttributeDefault.pas
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ TBoldPMString = class(TBoldSingleColumnMember)
{TBoldPMAnsiString}
TBoldPMAnsiString = class(TBoldPMString)
protected
function GetColumnTypeAsSQL(ColumnIndex: Integer): string; override;
function CompareField(const ObjectContent: IBoldObjectContents; const Field: IBoldField;
ColumnIndex: integer; const ValueSpace: IBoldValueSpace; TranslationList:
TBoldIdTranslationList): Boolean; override;
function GetColumnBDEFieldType(ColumnIndex: Integer): TFieldType; override;
public
procedure ValueFromField(OwningObjectId: TBoldObjectId; const ObjectContent:
IBoldObjectContents; const ValueSpace: IBoldValueSpace; TranslationList:
Expand Down Expand Up @@ -343,7 +345,10 @@ class function TBoldPMString.CanStore(const ContentName: string): Boolean;

function TBoldPMString.GetColumnBDEFieldType(ColumnIndex: Integer): TFieldType;
begin
Result := ftMemo; // Changed from ftString to ftMemo as MSSQL truncates string params to 8000
if SystemPersistenceMapper.SQLDataBaseConfig.TreatStringFieldAsUnicode then
result := ftWideString
else
Result := ftString;
end;

function TBoldPMString.GetColumnSize(ColumnIndex: Integer): Integer;
Expand Down Expand Up @@ -1267,6 +1272,17 @@ function TBoldPMAnsiString.CompareField(const ObjectContent: IBoldObjectContents
end;
end;

function TBoldPMAnsiString.GetColumnBDEFieldType(
ColumnIndex: Integer): TFieldType;
begin
Result := ftString;
end;

function TBoldPMAnsiString.GetColumnTypeAsSQL(ColumnIndex: Integer): string;
begin
Result := SystemPersistenceMapper.SQLDataBaseConfig.GetColumnTypeForAnsiString(GetColumnSize(ColumnIndex));
end;

procedure TBoldPMAnsiString.ValueFromField(OwningObjectId: TBoldObjectId;
const ObjectContent: IBoldObjectContents; const ValueSpace: IBoldValueSpace;
TranslationList: TBoldIdTranslationList; const Field: IBoldField; ColumnIndex:
Expand Down
5 changes: 3 additions & 2 deletions Source/BoldPMappersDefault.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ procedure TBoldObjectDefaultMapper.PMCreate(ObjectIDList: TBoldObjectIdList; con
TickCounter := 0;
end;
inc(Row);
if UseParams or (i = ObjectIDList.Count-1) or (Row = Limit) or (aQuery.ParamCount + aQuery.BatchQueryParamCount >= SystemPersistenceMapper.SQLDataBaseConfig.MaxBatchQueryParams) then
if UseParams or (i = ObjectIDList.Count-1) or (Row = Limit) or (aQuery.Params.Count + aQuery.BatchQueryParamCount >= SystemPersistenceMapper.SQLDataBaseConfig.MaxBatchQueryParams) then
begin
if not UseParams then
SB.Append(')');
Expand Down Expand Up @@ -1593,7 +1593,8 @@ procedure TBoldObjectDefaultMapper.PMUpdate(ObjectIDList: TBoldObjectIdList; con
finally
aQuery.SQLStrings.Clear;
aQuery.ClearParams;
aQuery.SQLStrings.EndUpdate;
if aQuery.SQLStrings.Updating then
aQuery.SQLStrings.EndUpdate;
SystemPersistenceMapper.ReleaseExecQuery(aQuery);
end;

Expand Down
Loading

0 comments on commit 6889b1b

Please sign in to comment.