Topic: TSqlitePassDatabase.DataTypeOptions.LoadFromDatabase Error
I'm not really very experienced delphi programmer, but I encounter some problems on openning and closing the database.
I must mention that compiling is done in Turbo Delphi 2006 Pro (some $IFDEFs on uses...) with 0.32 version of sqlitepass.
I tried to fix those bugs (annoying messages or exceptions were gone, about "real" functionality of code related to Loading and Saving to database I don't know if it is all right):
About functionality as I see it:
Only functional part of "LoadFromDatabase" procedure is used in next procedure and as we see here is exploited only
LoadFromDatabase for SoCustomFieldDefs, where are others? Is this bug or yet not finished feature?
SqlitePassDatabaseParts.inc
procedure TSqlitePassTableDefs.Refresh;
...
{ Loads the DatatypeOptions if needed }
If Not (soManual in FDatabase.FDataTypeOptions.LoadOptions)
and (SoCustomFieldDefs in FDatabase.FDataTypeOptions.LoadOptions)
then FDatabase.FDatatypeOptions.LoadFromDatabase([SoCustomFieldDefs]);
BUGS "SOLVED" :
in SqlPassDatabase.inc
procedure TSqlitePassDatabaseDataTypeOptions.LoadFromDatabase(_LoadOptions: TsqlitePassDataTypeStorageOptions = []);
...
BUG CODE: //error --> index is out of bounds
{ Storage Version }
FStorageVersion := StorageInfoStrings[1];
FIXED CODE:
{ Storage Version }
FStorageVersion := StorageInfoStrings[0];
...
procedure TSqlitePassDatabaseDataTypeOptions.SaveToDatabase(_SaveOptions: TsqlitePassDataTypeStorageOptions = []);
...
BUG CODE: //error --> RowId should not be forced to ftMemo
{ Enforces fields fieldTypes to ftMemo whatever Databasetype is used }
For i := 0 to Pred(DbSettingTableDef.FieldDefs.Count)
do DbSettingTableDef.FieldDefs[i].DataType := ftMemo;
This bug lead us to Access violation in next procedure:
procedure TSqlitePassMemRecord.ClearAndFree(FieldDefs: TFieldDefs = nil);
...
if (FieldDefs[Idx].DataType in SqlitePassBlobFieldTypes)
and (FieldsValues[Idx] <> '') then
begin
BlobStream := TMemoryStream(StrToInt(FieldsValues[Idx])); //HERE THE BUG ESCALATES TO ACCESS VIOLATION
BlobStream.Free;
end;
end; { Assigned }
FIXED CODE:
{ Enforces fields fieldTypes to ftMemo whatever Databasetype is used }
For i := 0 to Pred(DbSettingTableDef.FieldDefs.Count)
do begin
if DbSettingTableDef.FieldDefs[i].FieldName = 'Rowid' then Continue;
DbSettingTableDef.FieldDefs[i].DataType := ftMemo;
end;
...