I am porting some old C++ code over and I saw that using the Sqlite3 from FreePascal/Laz when creating a new db file with only 3 tables which are the same tables that have been created with existing files from the original C++ code, they seem to be at least twice or more in file size ?
The C++ of course used the CPP libraries to work with Sqlite but they are very noticeably smaller, however, when doing some checks the contents seem to be correct.
So I took a simple example from the net using only the Sqlite3 unit and found the size was still 2 or more larger than I think should be.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,Sqlite3,FileUtil;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
Var
DB: PSQLite3;
ErrMsg: PChar;
SQL: String;
rc: Integer;
procedure ExecSQL(constRef Statement: String);
begin
rc := sqlite3_exec(DB, PChar(Statement), nil, nil, @ErrMsg);
if rc <> SQLITE_OK then
begin
Memo1.Lines.Add('SQL error: '+ErrMsg^);
sqlite3_free(ErrMsg);
Exit;
end;
end;
begin
Memo1.Clear;
rc := sqlite3_open('test.db', @DB);
try
// Create first table
SQL := 'CREATE TABLE IF NOT EXISTS users (' +
'id INTEGER PRIMARY KEY AUTOINCREMENT,' +
'name TEXT NOT NULL,' +
'email TEXT UNIQUE NOT NULL);';
ExecSQL(SQL);
// Create second table
SQL := 'CREATE TABLE IF NOT EXISTS orders (' +
'id INTEGER PRIMARY KEY AUTOINCREMENT,' +
'user_id INTEGER NOT NULL,' +
'product TEXT NOT NULL,' +
'FOREIGN KEY(user_id) REFERENCES users(id));';
ExecSQL(SQL);
// Create third table
SQL := 'CREATE TABLE IF NOT EXISTS products (' +
'id INTEGER PRIMARY KEY AUTOINCREMENT,' +
'name TEXT NOT NULL,' +
'price REAL NOT NULL);';
ExecSQL(SQL);
finally
sqlite3_close(DB);
Memo1.Lines.Add('File Size :'+FileSize('test.db').Tostring);
Memo1.Lines.Add('Sqlite File Version :'+Sqlite3.sqlite3_libversion^);
DeleteFile('test.db');
end;
end;
end.
That generates ~ 24k of a file size, ~ the same as I get when using the components in lazarus for SQL functions applying the same Tables on new DBases but they are like I said like 3 times the size of what I think they should be.
is it possible the existing files are in Ansi and the newly created files are using UncodeString ?
Any input on this?
Jamie