mORMot and Open Source friends
Check-in [e52f4f90fd]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:fixed several issues with previous commit
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e52f4f90fd350ca98fdc99d5474037b7d00dbd40
User & Date: G018869 2011-08-26 15:38:02
Context
2011-08-29
10:05
fixed potential A/V error in function UTF8DecodeToString check-in: 21888ecc70 user: G018869 tags: trunk
2011-08-26
15:38
fixed several issues with previous commit check-in: e52f4f90fd user: G018869 tags: trunk
15:31
TSQLDatabase, TSQLRestClientDB and TSQLRestServerDB constructors now accept an optional Password parameter, associated to the supplied file name, in order to use encryption at the database level - still experimental check-in: b4e0ee9a01 user: G018869 tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to SynSQLite3.pas.

3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
....
3440
3441
3442
3443
3444
3445
3446
3447
3448


3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
....
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
var result: integer;
begin
  {$ifdef WITHLOG}
  fLog := SynSQLite3Log.Family.SynLog; // leave fLog=nil if no Logging wanted
  {$endif}
  InitializeCriticalSection(fLock);
  fFileName := aFileName;
  if (aPassword<>'') and (aFileName<>':memory') and (aFileName<>'') then begin
    SetLength(fCypherBlock,SQLEncryptTableSize);
    CreateSQLEncryptTableBytes(aPassword,pointer(fCypherBlock));
  end;
  fSQLFunctions := TObjectList.Create;
  result := DBOpen;
  if result<>SQLITE_OK then
    raise ESQLException.Create(fDB,result);
................................................................................

procedure TSQLDataBase.DBClose;
var i: integer;
begin
  if (self=nil) or (fDB=0) then
    exit;
  fLog.Enter;
  if Cyphers<>nil then begin
    i := Cypher.Find(PSQLDBStruct(fDB)^.DB0^.Btree^.pBt^.pPager^.fd^.h);


    if i>=0 then begin
      Cypher.Delete(i);
      fLog.Log(sllDB,'end of encryption');
    end;
  end;
  sqlite3_close(fDB);
  fDB := 0;
end;

function TSQLDataBase.DBOpen: integer;
var utf8: RawUTF8;
    i: integer;
    Cyph: TSQLCypher;
................................................................................
    fLog.Log(sllError,'open("%") failed',utf8,self);
    sqlite3_close(fDB); // should always be closed, even on failure
    fDB := 0;
    exit;
  end;
  Cyph.Handle := PSQLDBStruct(fDB)^.DB0^.Btree^.pBt^.pPager^.fd^.h;
  fLog.Log(sllDB,'open("%") with handle=%',[utf8,Cyph.Handle],self);
  if pointer(fCypherBlock)<>nil then begin
    if Cyphers=nil then
      Cypher.Init(TypeInfo(TSQLCypherDynArray),Cyphers,@CypherCount);
    i := Cypher.Find(Cyph.Handle);
    if i>=0 then
      fLog.Log(sllError,'DBClose missing: handle reused for ',utf8) else begin
      Cyph.CypherBuf := fCypherBlock;
      Cypher.Add(Cyph);






|







 







|
|
>
>
|
|
|
|
<
<







 







|







3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
....
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454


3455
3456
3457
3458
3459
3460
3461
....
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
var result: integer;
begin
  {$ifdef WITHLOG}
  fLog := SynSQLite3Log.Family.SynLog; // leave fLog=nil if no Logging wanted
  {$endif}
  InitializeCriticalSection(fLock);
  fFileName := aFileName;
  if (aPassword<>'') and (aFileName<>':memory:') and (aFileName<>'') then begin
    SetLength(fCypherBlock,SQLEncryptTableSize);
    CreateSQLEncryptTableBytes(aPassword,pointer(fCypherBlock));
  end;
  fSQLFunctions := TObjectList.Create;
  result := DBOpen;
  if result<>SQLITE_OK then
    raise ESQLException.Create(fDB,result);
................................................................................

procedure TSQLDataBase.DBClose;
var i: integer;
begin
  if (self=nil) or (fDB=0) then
    exit;
  fLog.Enter;
  if Cyphers<>nil then
    i := Cypher.Find(PSQLDBStruct(fDB)^.DB0^.Btree^.pBt^.pPager^.fd^.h) else
    i := -1;
  sqlite3_close(fDB);
  if i>=0 then begin
    Cypher.Delete(i); // do it after file closing
    fLog.Log(sllDB,'end of encryption');
  end;


  fDB := 0;
end;

function TSQLDataBase.DBOpen: integer;
var utf8: RawUTF8;
    i: integer;
    Cyph: TSQLCypher;
................................................................................
    fLog.Log(sllError,'open("%") failed',utf8,self);
    sqlite3_close(fDB); // should always be closed, even on failure
    fDB := 0;
    exit;
  end;
  Cyph.Handle := PSQLDBStruct(fDB)^.DB0^.Btree^.pBt^.pPager^.fd^.h;
  fLog.Log(sllDB,'open("%") with handle=%',[utf8,Cyph.Handle],self);
  if fCypherBlock<>'' then begin
    if Cyphers=nil then
      Cypher.Init(TypeInfo(TSQLCypherDynArray),Cyphers,@CypherCount);
    i := Cypher.Find(Cyph.Handle);
    if i>=0 then
      fLog.Log(sllError,'DBClose missing: handle reused for ',utf8) else begin
      Cyph.CypherBuf := fCypherBlock;
      Cypher.Add(Cyph);