Topic: some more fix...

function TSqlitePassDatabaseOptions.GetFPageSize: TSqlitePassPageSize;
begin
  Result := FDatabase.GetIntPragma('page_size');
  // Range Check Error
  if Result>High(TSqlitePassPageSize) then
    Result := High(TSqlitePassPageSize);
  if Result<Low(TSqlitePassPageSize) then
    Result := Low(TSqlitePassPageSize);
end;

But it still raise exception on Designtime.

How about change "TSqlitePassPageSize" to "Word"?


{ Translates a SQLite value to its internal storage value in memory
  Returns the size of the value }
function TSqlitePassRecordset.SqliteValueToBuffer(Const PSqliteData: Pointer; Const ColumnIndex: Integer; Const BufferFieldPos: Integer; Const DataType: TFieldType; Buffer: PChar): Integer;
...
  ftDateTime:
    begin
    Result := SizeOf(Double);
    if SqliteDbv3_column_type(PSqliteData, ColumnIndex) = SQLITE_NULL then Exit;
    Case FDatabase.DatatypeOptions.DateTimeStorage of
         dtsDateTime : DoubleValue := SqliteDbv3_column_double(PSqliteData,ColumnIndex);  // miss variable
...

{ Add a String and Returns the Index of the new string in Fstrings Array }
function TSqlitePassRecordset.AddString(Buffer: PChar; StrValue: String): Integer;
begin
 if FRecycledStrings.Count > 0
    then begin
    Result := Integer(FRecycledStrings[Pred(FRecycledStrings.Count)]); // << changed PInteger()^ to Integer
    FRecycledStrings.Delete(Pred(FRecycledStrings.Count));
...

Last edited by parcel (2009-03-28 10:31:44)

Re: some more fix...

TSqlitePassPageSize = Word;
...

function TSqlitePassDatabaseOptions.GetFPageSize: TSqlitePassPageSize;
begin
  Result := FDatabase.GetIntPragma('page_size') and $FFFF;
end;
...

function TSqlitePassDatabase.CreateDatabase(DbName: String; DbType: TSqlitePassDatabaseType;
                                            Encoding: TSqlitePassEncoding = UTF_8; PageSize: TSqlitePassPageSize = 4096;
                                            AutoVacuum: TSqlitePassAutoVacuumType = 0): Boolean;
var
EncodingStr: string;
begin
Result := False;
if Not FileExists(DbName) then
   With TSqlitePassEngine.Create(Self) do
        begin
        Try
        OpenDatabase(DbName, FSqliteLibrary);

        Case Encoding of
             UTF_8:    EncodingStr:= '"UTF-8"';
             UTF_16:   EncodingStr:= '"UTF-16"';
             UTF_16le: EncodingStr:= '"UTF-16le"';
             UTF_16be: EncodingStr:= '"UTF-16be"';
             end;
        //DW
        if PageSize<512 then
          PageSize := 512;
        if PageSize>32768 then
          PageSize := 32768;
        Case PageSize of
             512         : PageSize := 512;
             513..1024   : PageSize := 1024;
             1025..2048  : PageSize := 2048;
             2049..4096  : PageSize := 4096;
             4097..8192  : PageSize := 8192;
             8193..16384 : PageSize := 16384;
             16385..32768: PageSize := 32768;
             end;
...

It maybe fix Pagesize exception on designtime.

Re: some more fix...

Hi Parcel, thanks for all your work and checks.

I changed :

function TSqlitePassRecordset.SqliteValueToBuffer
...
 dtsDateTime : DoubleValue := SqliteDbv3_column_double(PSqliteData,ColumnIndex);
...

Database Page Size :

The Sqlite documentation says

"PRAGMA page_size;
PRAGMA page_size = bytes;

Query or set the page size of the database. The page size may only be set if the database has not yet been created. The page size must be a power of two greater than or equal to 512 and less than or equal to SQLITE_MAX_PAGE_SIZE. The maximum value for SQLITE_MAX_PAGE_SIZE is 32768.

When a new database is created, SQLite assigned a default page size based on information received from the xSectorSize and xDeviceCharacteristics methods of the sqlite3_io_methods object of the newly created database file. The page_size pragma will only cause an immediate change in the page size if it is issued while the database is still empty, prior to the first CREATE TABLE statement. As of version 3.5.8, if the page_size pragma is used to specify a new page size just prior to running the VACUUM command then VACUUM will change the page size to the new value."

So The pageSize could be verified when the property is set by user or when database is created.

I work on it and keep you informed soon.


The TSqlitePassRecordset.AddString was already changed in 0.42
...
    Result := Integer(FRecycledStrings[Pred(FRecycledStrings.Count)]); // << changed PInteger()^ to Integer
...

Re: some more fix...

Thank you, luckylazarus smile