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" smile :
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;
...

Re: TSqlitePassDatabase.DataTypeOptions.LoadFromDatabase Error

Many thanks for your contribution and smart remarks.

Leander007 wrote:

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?

Both...I didn't have time to finish it in 0.32. Done in 0.33 (Except bugs...). You can also call LoadFromDatabase Directly from the database (MyDb.DatatypeOptions.LoadFromDatabase)

Leander007 wrote:

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;

I have already done some other changes to the 'LoadFromDatabase' code but I will add your correction (below) if loading problems are not solved.

I'll upload version 0.33 by the end of this week.

Luc