-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathdbases_sqlite.pas
executable file
·2779 lines (2586 loc) · 119 KB
/
dbases_sqlite.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit dbases_sqlite; // New to v3.0.0 of QuickHash
// Copyright (C) 2011-2023 Ted Smith www.quickhash-gui.org
// Rule of thumb - For INSERT, UPDATE, DELETE, use SQLQuery.ExecSQL, for SELECT use SQLQuery.Open:
{$mode objfpc}{$H+} // {$H+} ensures all strings are of unlimited size, and set as ansistring
interface
uses
{$ifdef Linux}
dl,
{$endif}
{$ifdef Darwin}
dl,
{$endif}
Classes, SysUtils, db, sqldb, sqldblib, fpcsvexport, sqlite3conn, FileUtil,
LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, DBGrids,
sqlite3dyn, clipbrd, DbCtrls, LazUTF8, LazUTF8Classes;
type
{ TfrmSQLiteDBases }
TfrmSQLiteDBases = class(TForm)
CSVExporter1 : TCSVExporter; // We use this for users who want to clipboard the results. Works fine if not too many values.
DataSource1 : TDataSource;
DataSource2 : TDataSource;
DataSource3 : TDataSource;
SQLDBLibraryLoaderLinux : TSQLDBLibraryLoader;
SQLDBLibraryLoaderOSX : TSQLDBLibraryLoader;
SQLDBLibraryLoaderWindows : TSQLDBLibraryLoader;
SQLite3Connection1 : TSQLite3Connection;
sqlFILES : TSQLQuery;
sqlCOPY : TSQLQuery;
sqlCOMPARETWOFOLDERS : TSQLQuery;
SQLTransaction1 : TSQLTransaction;
lblConnectionStatus : TLabel;
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure CreateDatabase(DBaseName : string);
procedure WriteFILESValuesToDatabase(Filename, Filepath, HashValue, FileSize : string; KnownHash : boolean);
procedure WriteCOPYValuesToDatabase(Col1, Col2, Col3, Col4, Col5 : string);
procedure PrepareData_COMPARE_TWO_FOLDERS;
procedure Write_COMPARE_TWO_FOLDERS(FilePath, FilePathName, FileHash : string);
procedure EmptyDBTable(TableName : string; DBGrid : TDBGrid);
procedure EmptyDBTableCOPY(TableName : string; DBGrid : TDBGrid);
procedure EmptyDBTableC2F(TableName : string; DBGrid : TDBGrid);
procedure UpdateGridFILES(Sender: TObject);
procedure UpdateGridCOPYTAB(Sender: TObject);
procedure UpdateGridCOMPARETWOFOLDERSTAB(Sender: TObject);
procedure SaveFILESDBToCSV(DBGrid : TDBGrid; Filename : string);
procedure SaveCopyDBToCSV(DBGrid : TDBGrid; Filename : string);
procedure SaveC2FDBToCSV(DBGrid : TDBGrid; Filename : string);
procedure SaveFILESTabToHTML(DBGrid : TDBGrid; Filename : string);
procedure SaveCOPYWindowToHTML(DBGrid : TDBGrid; Filename : string);
procedure SaveC2FWindowToHTML(DBGrid : TDBGrid; Filename : string);
procedure DatasetToClipBoard(DBGrid : TDBGrid);
procedure DatasetToClipBoardFILES(DBGrid : TDBGrid);
procedure DatasetToClipBoardCOPYTAB(DBGrid : TDBGrid);
procedure ShowDuplicates(DBGrid : TDBGrid);
procedure DeleteDuplicates(DBGrid : TDBGrid);
procedure SortByID(DBGrid : TDBGrid);
procedure SortByFileName(DBGrid : TDBGrid);
procedure SortByFilePath(DBGrid : TDBGrid);
procedure SortByHash(DBGrid : TDBGrid);
procedure SortByHashList(DBGrid : TDBGrid);
procedure FilterOutHashListNO(DBGrid : TDBGrid);
procedure FilterOutHashListYES(DBGrid : TDBGrid);
procedure ShowAll(DBGrid : TDBGrid);
procedure ShowAllCOPYGRID(DBGrid : TDBGrid);
procedure ShowAllC2FGRID(DBGrid : TDBGrid);
procedure CopyFileNameOfSelectedCell(DBGrid : TDBGrid);
procedure CopyFilePathOfSelectedCell(DBGrid : TDBGrid);
procedure CopyHashOfSelectedCell(DBGrid : TDBGrid);
procedure CopyAllHashesFILESTAB(DBGrid : TDBGrid; UseFileFlag : Boolean);
procedure CopySelectedRowFILESTAB(DBGrid : TDBGrid);
procedure CopySelectedRowCOPYTAB(DBGrid : TDBGrid);
procedure CopySelectedRowC2FTAB(DBGrid : TDBGrid);
procedure CopySelectedRowsC2FTAB(DBGrid : TDBGrid);
procedure SortBySourceFilename(DBGrid : TDBGrid);
procedure SortByDestinationFilename(DBGrid : TDBGrid);
procedure SortBySourceHash(DBGrid : TDBGrid);
procedure SortByDestinationHash(DBGrid : TDBGrid);
procedure ShowMismatchesC2F(DBGrid : TDBGrid);
procedure ShowDuplicatesC2FTAB(DBGrid : TDBGrid);
procedure Copy_C2F_DuplicatesList(DBGrid : TDBGrid);
procedure ShowDiffHashes(DBGrid : TDBGrid);
procedure ShowMatchingHashes(DBGrid : TDBGrid);
procedure ShowMissingFilesFolderA(DBGrid : TDBGrid);
procedure ShowMissingFilesFolderB(DBGrid : TDBGrid);
procedure ShowMissingFromFolderAAndFolderB(DBGrid : TDBGrid);
function DBVersionLookup() : string;
function CountGridRows(AGrid: TDBGrid; ATableName: string): Integer;
private
{ private declarations }
public
DBName : string; // New to v3.3.0. Used by PreserveDB button to enable the user to save the DB.
ChosenDelimiter : string; // New to v3.3.0 to enable use of preferred delim char
FFilePathA : String; // new to v3.3.0 for Compare Two Folders tab
FFilePathB : String; // new to v3.3.0 for Compare Two Folders tab
FC2Fquery : Boolean;// New to v3.3.0 to enable and control results of "Show Duplicates" right click option
{ public declarations }
const
// More information on the use of these values is below.
// They need not be set as constants and can be any valid value
application_id = 1189021115; // must be a 32-bit Unsigned Integer (Longword 0 .. 4294967295) https://www.sqlite.org/pragma.html#pragma_application_id
user_version = 23400001; // must be a 32-bit Signed Integer (LongInt -2147483648 .. 2147483647) https://www.sqlite.org/pragma.html#pragma_user_version
end;
var
frmSQLiteDBases: TfrmSQLiteDBases;
implementation
{$R *.lfm}
{ TfrmSQLiteDBases }
uses
Unit2, uDisplayGrid, udisplaygrid3;
// On creation we check for SQLite capability and load as we find it.
// If it cant be found, QH will run with some tabs, but not those that need SQLIte backend
procedure TfrmSQLiteDBases.FormCreate(Sender: TObject);
const
{$ifdef CPU32}
LIB_FOLDER : ansistring = 'libs\x86';
{$else ifdef CPU64}
LIB_FOLDER : ansistring = 'libs\x64';
{$endif}
// LIB_FOLDER : ansistring = 'libs';
var
guid : TGuid;
SQLiteLibraryPath : string = Default(string);
strFileNameRandomiser : string = Default(string);
SafePlaceForDB : string = Default(string);
{$ifdef Linux}
LibHandle : Pointer;
Pdlinfo : Pdl_info;
PtrSQLiteLibraryPath : PChar;
{$endif}
{$ifdef darwin}
LibHandle : THandle = Default(THandle);
{$endif}
begin
// Set the delimiter to comma by default.
ChosenDelimiter := ',';
// Initiate calls to SQLite libraries for WINDOWS
{$ifdef windows}
SQLDBLibraryLoaderWindows.ConnectionType := 'SQLite3';
// Load the right DLL for the architecture of Windows in use
{$ifdef CPU32}
SQLiteLibraryPath := ExtractFilePath(Application.ExeName)+IncludeTrailingPathDelimiter(LIB_FOLDER)+'sqlite3-win32.dll';
{$else ifdef CPU64}
SQLiteLibraryPath := ExtractFilePath(Application.ExeName)+IncludeTrailingPathDelimiter(LIB_FOLDER)+'sqlite3-win64.dll';
{$endif}
// Check the DLL exists and load it
if FileExists(SQLiteLibraryPath) then
begin
SQLDBLibraryLoaderWindows.LibraryName := SQLiteLibraryPath;
SQLDBLibraryLoaderWindows.Enabled := true;
SQLDBLibraryLoaderWindows.LoadLibrary; // We dont need to use LoadLibraryEx here as SQLDBLibraryLoader seems to load the supplied SQlite.dll as intended
if CreateGUID(guid) = 0 then
begin
strFileNameRandomiser := GUIDToString(guid);
end
else
begin
strFileNameRandomiser := FormatDateTime('YYYY-MM-DD_HH-MM-SS.ZZZ', Now);
end;
// write the SQLite database file to system temp
SafePlaceForDB := GetTempDir;
if ForceDirectories(SafePlaceForDB) then
begin
SQLite3Connection1.DatabaseName := SafePlaceForDB + 'QuickHashDB_' + strFileNameRandomiser + '.sqlite';
// Create the database
CreateDatabase(SQLite3Connection1.DatabaseName);
if SQLIte3Connection1.Connected then
begin
lblConnectionStatus.Caption:= 'SQLite3 Database connection active';
DBName := SQLite3Connection1.DatabaseName; // We call DBName from Unit2, that is why it is declared here
end;
end
else
begin
Showmessage('Could not create folder ' + SafePlaceForDB + ' for ' + SQLite3Connection1.DatabaseName);
end;
end
else
begin
ShowMessage('Cannot create SQLite database. Probably SQLite libraries are not on your system.');
MainForm.TabSheet3.Enabled := false; // disable FileS tab, because it needs SQLite
MainForm.TabSheet4.Enabled := false; // disable Copy tab, because it needs SQLite
end;
{$endif} // End of Windows compiler directive
// Initiate calls to standard built in SQLite libraries for LINUX
{$ifdef linux}
SQLDBLibraryLoaderLinux.ConnectionType := 'SQLite3';
SQLiteLibraryPath := '';
LibHandle := dlopen('libsqlite3.so.0', RTLD_LAZY);
if LibHandle <> nil then
begin
Pdlinfo := LibHandle;
PtrSQLiteLibraryPath := Pdlinfo^.dli_fbase;
SQLiteLibraryPath := String(PtrSQLiteLibraryPath);
PtrSQLiteLibraryPath := nil;
dlclose(LibHandle);
end;
if FileExists(SQLiteLibraryPath) then
begin
SQLDBLibraryLoaderLinux.LibraryName := SQLiteLibraryPath;
SQLDBLibraryLoaderLinux.Enabled := true;
SQLDBLibraryLoaderLinux.LoadLibrary;
if CreateGUID(guid) = 0 then
begin
strFileNameRandomiser := GUIDToString(guid);
end
else
begin
strFileNameRandomiser := FormatDateTime('YYYY-MM-DD_HH-MM-SS.ZZZ', Now);
end;
// write the SQLite database file to system temp
SafePlaceForDB := GetTempDir;
if ForceDirectories(SafePlaceForDB) then
begin
SQLite3Connection1.DatabaseName := SafePlaceForDB + 'QuickHashDB_' + strFileNameRandomiser + '.sqlite';
// Create the database
CreateDatabase(SQLite3Connection1.DatabaseName);
if SQLIte3Connection1.Connected then
begin
lblConnectionStatus.Caption:= 'SQLite3 Database connection active';
DBName := SQLite3Connection1.DatabaseName; // We call DBName from Unit2, that is why it is declared here
end;
end
else
begin
Showmessage('Could not create folder ' + SafePlaceForDB + ' for ' + SQLite3Connection1.DatabaseName);
end;
end
else
begin
ShowMessage('Cannot create SQLite database. Probably SQLite libraries are not on your system.');
MainForm.TabSheet3.Enabled := false; // disable FileS tab, because it needs SQLite
MainForm.TabSheet4.Enabled := false; // disable Copy tab, because it needs SQLite
end;
{$endif} // End of Linux compiler directive
// Initiate calls to standard built in SQLite libraries for APPLE OSX
{$ifdef darwin}
// Thanks to OSX being a total and utter pain, moving goal posts with every release of OSX,
// and since BigSur has removed libraries, more Skullduggery is required for
// that platform. Thanks Apple, from me.
SQLDBLibraryLoaderOSX.ConnectionType := 'SQLite3';
SQLiteLibraryPath := '';
// First check the SQLite lib can be loaded by calling the new dynamic cache of Big Sur
LibHandle := loadLibrary(PChar('libsqlite3.dylib'));
// check whether loading was possible and successful but then just unload it
// to allow the TSQLDBLibraryLoader to load it, later
if LibHandle <> 0 then
begin
// Nothing is needed here anymore
end
else ShowMessage('Cannot load SQLite libraries for backend use.' + SysErrorMessage(GetLastOSError));
// unload library and pass control to TSQLDBLibraryLoader
if LibHandle <> NilHandle then
begin
unloadLibrary(LibHandle);
SQLDBLibraryLoaderOSX.LibraryName := 'libsqlite3.dylib';
SQLDBLibraryLoaderOSX.Enabled := true;
SQLDBLibraryLoaderOSX.LoadLibrary;
// Generate a unique name for the DB
if CreateGUID(guid) = 0 then
begin
strFileNameRandomiser := GUIDToString(guid);
end
else
begin
strFileNameRandomiser := FormatDateTime('YYYY-MM-DD_HH-MM-SS.ZZZ', Now);
end;
// write the SQLite database file to system temp
SafePlaceForDB := GetTempDir;
if ForceDirectories(SafePlaceForDB) then
begin
SQLite3Connection1.DatabaseName := SafePlaceForDB + 'QuickHashDB_' + strFileNameRandomiser + '.sqlite';
// Create the database
CreateDatabase(SQLite3Connection1.DatabaseName);
if SQLIte3Connection1.Connected then
begin
lblConnectionStatus.Caption:= 'SQLite3 Database connection active';
DBName := SQLite3Connection1.DatabaseName; // We call DBName from Unit2, that is why it is declared here
end;
end
end;
LibHandle := NilHandle;
// Method used prior to v3.3.0, for info
{ SQLDBLibraryLoaderOSX.ConnectionType := 'SQLite3';
SQLiteLibraryPath := '';
LibHandle := dlopen('libsqlite3.dylib', RTLD_LAZY);
if LibHandle <> nil then
begin
Pdlinfo := LibHandle;
PtrSQLiteLibraryPath := Pdlinfo^.dli_fbase;
SQLiteLibraryPath := String(PtrSQLiteLibraryPath);
PtrSQLiteLibraryPath := nil;
dlclose(LibHandle);
end;}
{$endif} // End of Apple OSX compiler directive
end;
// Create a fresh SQLite database for each instance of the program
procedure TfrmSQLiteDBases.CreateDatabase(DBaseName : string);
begin
SQLite3Connection1.Close; // Ensure the connection is closed when we start
try
// Since we're making this database for the first time,
// check whether the file already exists and remove it if it does
if FileExists(SQLite3Connection1.DatabaseName) then
begin
DeleteFile(SQLite3Connection1.DatabaseName);
end;
// Make a new, clean, database and add the tables
try
SQLite3Connection1.Open;
SQLTransaction1.Active := true;
// Periodically sort the database out to ensure it stays in tip top shape
// during heavy usage
SQLite3Connection1.ExecuteDirect('PRAGMA auto_vacuum = FULL;');
// Per the SQLite Documentation (edited for clarity):
// The pragma user_version is used to set or get the value of the user-version.
// The user-version is a big-endian 32-bit signed integer stored in the database header at offset 60.
// The user-version is not used internally by SQLite. It may be used by applications for any purpose.
// http://www.sqlite.org/pragma.html#pragma_schema_version
SQLite3Connection1.ExecuteDirect('PRAGMA user_version = ' + IntToStr(user_version) + ';');
// Per the SQLite Documentation:
// The application_id PRAGMA is used to query or set the 32-bit unsigned big-endian
// "Application ID" integer located at offset 68 into the database header.
// Applications that use SQLite as their application file-format should set the
// Application ID integer to a unique integer so that utilities such as file(1) can
// determine the specific file type rather than just reporting "SQLite3 Database".
// A list of assigned application IDs can be seen by consulting the magic.txt file
// in the SQLite source repository.
// http://www.sqlite.org/pragma.html#pragma_application_id
SQLite3Connection1.ExecuteDirect('PRAGMA application_id = ' + IntToStr(application_id) + ';');
// Here we're setting up a table named "TBL_FILES" in the new database for FileS tab
// Note AUTOINCREMENT is NOT used! If it is, it causes problems with RowIDs etc after multiple selections
// Besides, SQLite advice is not to use it unless entirely necessary (http://sqlite.org/autoinc.html)
// VARCHAR is set as 32767 to ensure max length of NFTS based filename and paths can be utilised
SQLite3Connection1.ExecuteDirect('CREATE TABLE "TBL_FILES"(' +
' "No" Integer NOT NULL PRIMARY KEY,' +
' "FileName" VARCHAR(4096) NOT NULL,' +
' "FilePath" VARCHAR(4096) NOT NULL,' +
' "HashValue" VARCHAR NOT NULL,' +
' "FileSize" VARCHAR NULL,' +
' "KnownHashFlag" VARCHAR NULL);');
// Creating an index based upon id in the TBL_FILES Table
SQLite3Connection1.ExecuteDirect('CREATE UNIQUE INDEX "FILES_id_idx" ON "TBL_FILES"( "No" );');
// Here we're setting up a table named "TBL_COPY" in the new database for Copy tab
// VARCHAR is set as 32767 to ensure max length of NFTS based filename and paths can be utilised
SQLite3Connection1.ExecuteDirect('CREATE TABLE "TBL_COPY"(' +
' "No" Integer NOT NULL PRIMARY KEY,' +
' "SourceFilename" VARCHAR(4096) NOT NULL,' +
' "SourceHash" VARCHAR NULL,' +
' "DestinationFilename" VARCHAR(4096) NOT NULL,'+
' "DestinationHash" VARCHAR NULL,' +
' "DateAttributes" VARCHAR NULL);');
// Creating an index based upon id in the TBL_COPY Table
SQLite3Connection1.ExecuteDirect('CREATE UNIQUE INDEX "COPIED_FILES_id_idx" ON "TBL_COPY"( "No" );');
// New to v3.2.0 to enable a display grid for the comparison of two folders
// Here we're setting up a table named "TBL_COMPARE_TWO_FOLDERS" in the new database for Comapre Two Folders tab
// VARCHAR is set as 4096 to ensure max length of NFTS based filename and paths can be utilised
SQLite3Connection1.ExecuteDirect('CREATE TABLE "TBL_COMPARE_TWO_FOLDERS"('+
' "No" Integer NOT NULL PRIMARY KEY,'+
' "FilePath" VARCHAR(4096) NULL,' +
' "FileName" VARCHAR(4096) NULL,' +
' "FileHash" VARCHAR NULL);');
// Creating an index based upon id in the TBL_COMPARE_TWO_FOLDERS Table
// Pre v3.3.0 was : SQLite3Connection1.ExecuteDirect('CREATE UNIQUE INDEX "COMPARE_TWO_FOLDERS_id_idx" ON "TBL_COMPARE_TWO_FOLDERS"( "No" );'); //DS (original) - no need because it is primary key
// The following is new to v3.3.0 following extensive improvement with community help:
SQLite3Connection1.ExecuteDirect('CREATE INDEX COMPARE_TWO_FOLDERS_path_name_hash_idx '+
' ON TBL_COMPARE_TWO_FOLDERS (FilePath, FileName, FileHash)');
SQLite3Connection1.ExecuteDirect('CREATE INDEX COMPARE_TWO_FOLDERS_path_hash_name_idx '+
' ON TBL_COMPARE_TWO_FOLDERS (FilePath, FileHash, FileName)');
SQLite3Connection1.ExecuteDirect('CREATE TABLE TBL_COMPARE_TWO_FOLDERS_MATCH ( '+
'No Integer NOT NULL PRIMARY KEY, '+
'FileName VARCHAR NULL, '+
'FilePathA VARCHAR NULL, '+
'FileHashA VARCHAR NULL, '+
'FilePathB VARCHAR NULL, '+
'FileHashB VARCHAR NULL) ');
SQLite3Connection1.ExecuteDirect('CREATE TABLE TBL_COMPARE_TWO_FOLDERS_DUPLICATES ( '+
'No Integer NOT NULL PRIMARY KEY, '+
'FilePath VARCHAR NULL, '+
'FileName VARCHAR NULL, '+
'FileHash VARCHAR NULL) ');
// Now write to the new database
SQLTransaction1.CommitRetaining;
except
ShowMessage('SQLite detected but unable to create a new SQLite Database');
end;
except
ShowMessage('SQLite detected but could not check if a database file exists');
end;
end;
// Shows the user what version of SQLite is in use. Useful for bug reporting etc
function TfrmSQLiteDBases.DBVersionLookup() : string;
var
DynamicSQLQuery: TSQLQuery;
begin
result := '';
DynamicSQLQuery := TSQLQuery.Create(nil);
try
try
DynamicSQLQuery.DataBase := SQLTransaction1.DataBase;
DynamicSQLQuery.SQL.Add('SELECT sqlite_version()');
DynamicSQLQuery.Open;
result := ('SQLite version : ' + DynamicSQLQuery.FieldByName('sqlite_version()').AsString);
except
on E: EDatabaseError do
begin
MessageDlg('Error','A database error has occurred. Technical error message: ' + E.Message,mtError,[mbOK],0);
end;
end;
finally
DynamicSQLQuery.Free;
end;
end;
// Copy selected row to clipboard from FILES grid
procedure TfrmSQLiteDBases.CopySelectedRowFILESTAB(DBGrid : TDBGrid);
var
FileNameCell : string = Default(string);
FilePathCell : string = Default(string);
FileHashCell : string = Default(string);
AllRowCells : string = Default(string);
begin
ChosenDelimiter := MainForm.ChosenDelimiter;
FileNameCell := DBGrid.DataSource.DataSet.Fields[1].AsString;
FilePathCell := DBGrid.DataSource.DataSet.Fields[2].AsString;
FileHashCell := DBGrid.DataSource.DataSet.Fields[3].AsString;
AllRowCells := FileNameCell+ChosenDelimiter+FilePathCell+ChosenDelimiter+FileHashCell;
Clipboard.AsText:= AllRowCells;
end;
// Copy selected row to clipboard from COPY grid
procedure TfrmSQLiteDBases.CopySelectedRowCOPYTAB(DBGrid : TDBGrid);
var
AllRowCells : string = Default(string);
SourceFileNameCell : string = Default(string);
SourceHash : string = Default(string);
DestinationFilenameCell : string = Default(string);
DestinationHash : string = Default(string);
DateAttr : string = Default(string);
begin
ChosenDelimiter := MainForm.ChosenDelimiter;
SourceFileNameCell := DBGrid.DataSource.DataSet.Fields[1].AsString;
SourceHash := DBGrid.DataSource.DataSet.Fields[2].AsString;
DestinationFilenameCell := DBGrid.DataSource.DataSet.Fields[3].AsString;
DestinationHash := DBGrid.DataSource.DataSet.Fields[4].AsString;
DateAttr := DBGrid.DataSource.DataSet.Fields[5].AsString;
// and just add them all together :-)
AllRowCells := SourceFileNameCell+ChosenDelimiter+SourceHash +ChosenDelimiter+DestinationFilenameCell+ChosenDelimiter+DestinationHash+ChosenDelimiter+DateAttr;
Clipboard.AsText := AllRowCells;
end;
// Copy selected row to clipboard from COMPARE TWO FOLDERS grid
procedure TfrmSQLiteDBases.CopySelectedRowC2FTAB(DBGrid : TDBGrid);
var
AllRowCells : string = Default(string);
strID : string = Default(string);
FileNameCell: string = Default(string);
FolderPathA : string = Default(string);
FileHashA : string = Default(string);
FolderPathB : string = Default(string);
FileHashB : string = Default(string);
// For filtered view
FolderPath : string = Default(string);
FileName : string = Default(string);
FileHash : string = Default(string);
begin
ChosenDelimiter := MainForm.ChosenDelimiter;
// If user has enabled "Show Duplicates" filter, copy the adjusted layout
If FC2Fquery = false then
begin
strID := DBGrid.DataSource.DataSet.Fields[0].AsString;
FolderPath := DBGrid.DataSource.DataSet.Fields[1].AsString;
FileName := DBGrid.DataSource.DataSet.Fields[2].AsString;
FileHash := DBGrid.DataSource.DataSet.Fields[3].AsString;
AllRowCells := strID +ChosenDelimiter+
FolderPath +ChosenDelimiter+
FileName +ChosenDelimiter+
FileHash +ChosenDelimiter;
Clipboard.AsText := AllRowCells;
end
else // If user has not enabled "Show Duplicates" filter, copy the standard layout
begin
strID := DBGrid.DataSource.DataSet.Fields[0].AsString;
FileNameCell := DBGrid.DataSource.DataSet.Fields[1].AsString;
FolderPathA := DBGrid.DataSource.DataSet.Fields[2].AsString;
FileHashA := DBGrid.DataSource.DataSet.Fields[3].AsString;
FolderPathB := DBGrid.DataSource.DataSet.Fields[4].AsString;
FileHashB := DBGrid.DataSource.DataSet.Fields[5].AsString;
AllRowCells := strID +ChosenDelimiter+
FileNameCell +ChosenDelimiter+
FolderPathA +ChosenDelimiter+
FileHashA +ChosenDelimiter+
FolderPathB +ChosenDelimiter+
FileHashB;
Clipboard.AsText := AllRowCells;
end;
end;
// Copies multiple selected rows (plural) to clipboard of the "Compare Two Folders" results grid
// For some odd reason it copies it in the reverse order to shown in grid. Not sure why yet.
// New to v3.3.0
procedure TfrmSQLiteDBases.CopySelectedRowsC2FTAB(DBGrid : TDBGrid);
var
AllRowCells : string = Default(string);
strID : string = Default(string);
FileNameCell : string = Default(string);
FolderPathA : string = Default(string);
FileHashA : string = Default(string);
FolderPathB : string = Default(string);
FileHashB : string = Default(string);
i : Integer;
FolderPath : string = Default(string);
FileName : string = Default(string);
FileHash : string = Default(string);
begin
ChosenDelimiter := MainForm.ChosenDelimiter;
for i := 0 to DBGrid.SelectedRows.Count -1 do
with DBGrid.DataSource.DataSet do
begin
// If user has enabled "Show Duplicates" filter, copy the adjusted layout
If FC2Fquery = false then
begin
GotoBookmark(Pointer(DBGrid.SelectedRows.Items[i]));
strID := DBGrid.DataSource.DataSet.Fields[0].AsString;
FolderPath := DBGrid.DataSource.DataSet.Fields[1].AsString;
FileName := DBGrid.DataSource.DataSet.Fields[2].AsString;
FileHash := DBGrid.DataSource.DataSet.Fields[3].AsString;
AllRowCells := AllRowCells + strID +ChosenDelimiter+
FolderPath +ChosenDelimiter+
FileName +ChosenDelimiter+
FileHash +LineEnding;
Clipboard.AsText := AllRowCells;
end
else // If user has not enabled "Show Duplicates" filter, copy the standard layout
begin
GotoBookmark(Pointer(DBGrid.SelectedRows.Items[i]));
strID := DBGrid.DataSource.DataSet.Fields[0].AsString;
FileNameCell := DBGrid.DataSource.DataSet.Fields[1].AsString;
FolderPathA := DBGrid.DataSource.DataSet.Fields[2].AsString;
FileHashA := DBGrid.DataSource.DataSet.Fields[3].AsString;
FolderPathB := DBGrid.DataSource.DataSet.Fields[4].AsString;
FileHashB := DBGrid.DataSource.DataSet.Fields[5].AsString;
AllRowCells := AllRowCells + strID +ChosenDelimiter+
FileNameCell +ChosenDelimiter+
FolderPathA +ChosenDelimiter+
FileHashA +ChosenDelimiter+
FolderPathB +ChosenDelimiter+
FileHashB +LineEnding;
end;
Clipboard.AsText := AllRowCells; // Clipboard.AsText:=sCSV;
end;
end;
// Counts rows of the calling display tab using dedicated SQLQuery instead of
// DBGrid.DataSet.RecordCount, which only gives the count shown on screen.
// Returns positive integer if successfull
function TfrmSQLiteDBases.CountGridRows(AGrid: TDBGrid; ATableName: string): Integer;
begin
result := -1;
with TSQLQuery.Create(nil) do
try
Database := TSQLQuery(AGrid.DataSource.DataSet).Database;
SQL.Text := ('SELECT COUNT(*) FROM '+ATableName);
Open;
Result := Fields[0].AsInteger;
Close;
finally
Free;
end;
{pre v3.3.0 method
result := -1;
DBGrid.DataSource.Dataset.DisableControls;
DBGrid.DataSource.DataSet.First;
while not DBGrid.DataSource.DataSet.EOF do
begin
inc(NoOfRows, 1);
DBGrid.DataSource.DataSet.Next;
end;
DBGrid.DataSource.Dataset.EnableControls;
// Go to top of grid.
DBGrid.DataSource.DataSet.First;
// Return count
If NoOfRows > -1 then result := NoOfRows; }
end;
// Saves the grid in FILES tab to HTML. If small volume of records, uses a stringlist.
// If big volume, uses file stream.
procedure TfrmSQLiteDBases.SaveFILESTabToHTML(DBGrid : TDBGrid; Filename : string);
var
strTitle : string = Default(string);
FileIDCell : string = Default(string);
FileNameCell : string = Default(string);
FilePathCell : string = Default(string);
FileHashCell : string = Default(string);
FileSizeCell : string = Default(string);
KnownHashCell : string = Default(string);
NoOfRowsInGrid : integer = Default(integer);
sl : TStringList;
fs : TFileStreamUTF8;
ExportSQLQuery : TSQLQuery;
const
strHTMLHeader = '<HTML>' ;
strTITLEHeader = '<TITLE>QuickHash HTML Output' ;
strBODYHeader = '<BODY>' ;
strTABLEHeader = '<TABLE>' ;
strTABLEROWStart = '<TR>' ;
strTABLEDATAStart = '<TD>' ;
strTABLEDataEnd = '</TD>' ;
strTABLEROWEnd = '</TR>' ;
strTableRow1 = strTABLEROWStart+'<TD><B>NO</B></TD><TD><B>Filename</B></TD><TD><B>Filepath</B></TD><TD><B>Filehash</B></TD><TD><B>Filesize</B></TD>';
strTABLEFooter = '</TABLE>';
strBODYFooter = '</BODY>' ;
strTITLEFooter = '</TITLE>';
strHTMLFooter = '</HTML>' ;
begin
// If database volume not too big, use memory and stringlists. Otherwise, use file writes
if DBGrid.Name = 'DBGrid_FILES' then
begin
NoOfRowsInGrid := CountGridRows(DBGrid, 'TBL_FILES');// Count the rows first. If not too many, use memory. Otherwise, use filestreams
if (NoOfRowsInGrid < 20000) and (NoOfRowsInGrid > -1) then
try
MainForm.StatusBar2.Caption:= ' Saving grid to ' + Filename + '...please wait';
Application.ProcessMessages;
// Write the grid to a stringlist
sl := TStringList.Create;
sl.add('<HTML>');
sl.add('<TITLE>QuickHash HTML Output</TITLE>');
sl.add('<BODY>');
sl.add('<p>HTML Output generated ' + FormatDateTime('YYYY/MM/DD HH:MM:SS', Now) + ' using ' + MainForm.Caption + '</p>');
sl.add('<TABLE>');
if MainForm.cbLoadHashList.Checked then
begin
sl.add(strTableRow1 + '<TD>Known Hash Flag</TD>' + strTABLEROWEnd)
end else sl.add(strTableRow1 + strTABLEROWEnd);
try
DBGrid.DataSource.DataSet.DisableControls;
DBGrid.DataSource.DataSet.First;
while not DBGrid.DataSource.DataSet.EOF do
begin
sl.add('<tr>');
// Get the data from the ID cell
FileIDCell := DBGrid.DataSource.DataSet.Fields[0].AsString;
sl.add('<td>'+FileIDCell+'</td>');
// Get the data from the filename cell
FileNameCell := DBGrid.DataSource.DataSet.Fields[1].AsString;
sl.add('<td>'+FileNameCell+'</td>');
// Get the data from the filepath cell
FilePathCell := DBGrid.DataSource.DataSet.Fields[2].AsString;
sl.add('<td>'+FilePathCell+'</td>');
// Get the data from the filehash cell
FileHashCell := DBGrid.DataSource.DataSet.Fields[3].AsString;
sl.add('<td>'+FileHashCell+'</td>');
// Get the data from the filesize cell
FileSizeCell := DBGrid.DataSource.DataSet.Fields[4].AsString;
sl.add('<td>'+FileSizeCell+'</td>');
// Get the data from the Known Hash Cell, if required
if MainForm.cbLoadHashList.Checked then
begin
KnownHashCell := DBGrid.DataSource.DataSet.Fields[5].AsString;
sl.add('<td>'+KnownHashCell+'</td>');
end;
sl.add('</tr>');
DBGrid.DataSource.DataSet.Next;
end;
sl.add('</TABLE>');
sl.add('</BODY> ');
sl.add('</HTML> ');
finally
DBGrid.DataSource.DataSet.EnableControls;
end;
finally
sl.SaveToFile(Filename);
sl.free;
MainForm.StatusBar2.Caption:= ' Data saved to HTML file ' + Filename + '...OK';
ShowMessage(MainForm.StatusBar2.Caption);
Application.ProcessMessages;
end
else // Use filestream method because there's more than 10K rows. Too many to add HTML tags and store in memory
try
if not FileExists(filename) then
begin
fs := TFileStreamUTF8.Create(Filename, fmCreate);
end
else fs := TFileStreamUTF8.Create(Filename, fmOpenReadWrite);
MainForm.StatusBar2.Caption:= ' Saving grid to ' + Filename + '...please wait';
strTitle := '<p>HTML Output generated ' + FormatDateTime('YYYY/MM/DD HH:MM:SS', Now) + ' using ' + MainForm.Caption + '</p>';
Application.ProcessMessages;
fs.Write(strHTMLHeader[1], Length(strHTMLHeader));
fs.Write(#13#10, 2);
fs.Write(strTITLEHeader[1], Length(strTITLEHeader));
fs.Write(strTITLEFooter[1], Length(strTITLEFooter));
fs.Write(#13#10, 2);
fs.Write(strBODYHeader[1], Length(strBODYHeader));
fs.Write(strTitle[1], Length(strTitle));
fs.Write(#13#10, 2);
fs.Write(strTABLEHeader[1], Length(strTABLEHeader));
fs.Write(strTableRow1[1], Length(strTableRow1));
{ strTABLEROWStart = '<TR>' = 4 bytes
strTABLEDATAStart = '<TD>' = 4 bytes
strTABLEDataEnd = '</TD>' = 5 bytes
strTABLEROWEnd = '</TR>' = 5 bytes
strTABLEFooter = '</TABLE>' = 8 bytes
strBODYFooter = '</BODY>' = 7 bytes
strTITLEFooter = '</TITLE>' = 8 bytes
strHTMLFooter = '</HTML>' = 7 bytes}
// v3.3.0 highlighted that the exporting of large volumes of data in the
// DBGrid, even as a filestream, was causing QH to crash dueo the DBGrid controls.
// So for v3.3.1 onwards, we create temporary dedicated pure SQLQueries to handle this instead.
try
ExportSQLQuery := TSQLQuery.Create(nil);
try
ExportSQLQuery.SQL.Text := 'SELECT * FROM TBL_FILES'; // Get all the data from Files tab table
ExportSQLQuery.Database := SQLite3Connection1;
ExportSQLQuery.UniDirectional := True; //<- this is the important part for memory handling reasons but cant be used in an active DBGrid - only for SQLQueries
ExportSQLQuery.Open;
ExportSQLQuery.First;
while not ExportSQLQuery.EOF do
begin
fs.Write(strTABLEROWStart[1], 4);
// Get the data from the ID cell
FileIDCell := ExportSQLQuery.FieldByName('No').AsString;
// Write filename to new row
fs.Write(strTABLEDATAStart[1], 4);
fs.Write(FileIDCell[1], Length(FileIDCell));
fs.Write(strTABLEDataEnd[1], 5);
// Get the data from the filename cell
FileNameCell := ExportSQLQuery.FieldByName('FileName').AsString;
// Write filename to new row
fs.Write(strTABLEDATAStart[1], 4);
fs.Write(FileNameCell[1], Length(FileNameCell));
fs.Write(strTABLEDataEnd[1], 5);
// Get the data from the filepath cell
FilePathCell := ExportSQLQuery.FieldByName('FilePath').AsString;
// Write filepath to new row
fs.Write(strTABLEDATAStart[1], 4);
fs.Write(FilePathCell[1], Length(FilePathCell));
fs.Write(strTABLEDATAEnd[1], 5);
// Get the data from the filehash cell
FileHashCell := ExportSQLQuery.FieldByName('HashValue').AsString;
// Write hash to new row
fs.Write(strTABLEDATAStart[1], 4) ;
fs.Write(FileHashCell[1], Length(Trim(FileHashCell)));
fs.Write(strTABLEDATAEnd[1], 5);
// Get the data from the filesize cell
FileSizeCell := ExportSQLQuery.FieldByName('FileSize').AsString;
// Write hash to new row
fs.Write(strTABLEDATAStart[1], 4) ;
fs.Write(FileSizeCell[1], Length(Trim(FileSizeCell)));
fs.Write(strTABLEDATAEnd[1], 5);
//Get the data from the KnownHashFlag cell, if it has been selected for use by the user
if MainForm.cbLoadHashList.Checked then
begin
KnownHashCell := ExportSQLQuery.FieldByName('KnownHashFlag').AsString;
// Write hash to new row
fs.Write(strTABLEDATAStart[1], 4) ;
fs.Write(KnownHashCell[1], Length(Trim(KnownHashCell)));
fs.Write(strTABLEDATAEnd[1], 5);
end;
// End the row
fs.Write(strTABLEROWEnd[1], 5);
fs.Write(#13#10, 2);
// Repeat for the next row
ExportSQLQuery.next;
end;
finally
// Nothing to free here
end;
fs.Write(strTABLEFooter, 8);
fs.Write(#13#10, 2);
fs.writeansistring(IntToStr(NoOfRowsInGrid) + ' grid entries saved.');
fs.Write(strBODYFooter, 7);
fs.Write(#13#10, 2);
fs.Write(strHTMLFooter, 7);
fs.Write(#13#10, 2);
finally
ExportSQLQuery.free; // Free the temp SQL Query
end;
finally
fs.free; // Free the filestream
MainForm.StatusBar2.Caption:= ' Data saved to HTML file ' + Filename + '...OK';
Application.ProcessMessages;
ShowMessage(MainForm.StatusBar2.Caption);
end;
end
else
if DBGrid.Name = 'frmDisplayGrid1' then
begin
// See SaveCOPYWindowToHTML
end;
end;
// Deletes a DB table from the SQLite DB
procedure TfrmSQLiteDBases.EmptyDBTable(TableName : string; DBGrid : TDBGrid);
var
DynamicSQLQuery: TSQLQuery;
begin
DynamicSQLQuery := TSQLQuery.Create(nil);
try
try
DynamicSQLQuery.DataBase := sqlFILES.Database;
DynamicSQLQuery.Transaction := sqlFILES.Transaction;
DynamicSQLQuery.SQL.Text := 'DELETE FROM ' + TableName;
if SQLite3Connection1.Connected then
begin
SQLTransaction1.Active := True;
DynamicSQLQuery.ExecSQL;
SQLTransaction1.CommitRetaining; // Retain transaction is important here
end;
except
on E: EDatabaseError do
begin
MessageDlg('Error','A database error has occurred. Technical error message: ' + E.Message,mtError,[mbOK],0);
end;
end;
finally
DynamicSQLQuery.Free;
end;
end;
// Deletes a DB table from the COPY DB
procedure TfrmSQLiteDBases.EmptyDBTableCOPY(TableName : string; DBGrid : TDBGrid);
var
DynamicSQLQuery: TSQLQuery;
begin
DynamicSQLQuery := TSQLQuery.Create(nil);
try
try
DynamicSQLQuery.DataBase := sqlCOPY.Database;
DynamicSQLQuery.Transaction := sqlCOPY.Transaction;
DynamicSQLQuery.SQL.Text := 'DELETE FROM ' + TableName;
if SQLite3Connection1.Connected then
begin
SQLTransaction1.Active := True;
DynamicSQLQuery.ExecSQL;
SQLTransaction1.CommitRetaining; // Retain transaction is important here
end;
except
on E: EDatabaseError do
begin
MessageDlg('Error','A database error has occurred. Technical error message: ' + E.Message,mtError,[mbOK],0);
end;
end;
finally
DynamicSQLQuery.Free;
end;
end;
// Empties table of Compare Two Folders
procedure TfrmSQLiteDBases.EmptyDBTableC2F(TableName : string; DBGrid : TDBGrid);
var
DynamicSQLQuery: TSQLQuery;
begin
DynamicSQLQuery := TSQLQuery.Create(nil);
try
try
DynamicSQLQuery.DataBase := sqlCOMPARETWOFOLDERS.Database;
DynamicSQLQuery.Transaction := sqlCOMPARETWOFOLDERS.Transaction;
DynamicSQLQuery.SQL.Text := 'DELETE FROM ' + TableName;
if SQLite3Connection1.Connected then
begin
SQLTransaction1.Active := True;
DynamicSQLQuery.ExecSQL;
SQLTransaction1.CommitRetaining; // Retain transaction is important here
end;
except
on E: EDatabaseError do
begin
MessageDlg('Error','A database error has occurred. Technical error message: ' + E.Message,mtError,[mbOK],0);
end;
end;
finally
DynamicSQLQuery.Free;
end;
end;
// SaveDBToCSV exports the DBGrid (DBGridName) to a CSV file (filename) for the user
// using a filestream and dedicated TSQLQuery due to DBGrid poor perfomance for large data.
// Note if the user has filtered the display, such as show all duplicates, the whole
// tabel of data will still be dumped to text for sorting etc in Excel or similar.
procedure TfrmSQLiteDBases.SaveFILESDBToCSV(DBGrid : TDBGrid; Filename : string);
var
linetowrite : ansistring = Default(ansistring);
FileIDCell : string = Default(string);
FileNameCell : string = Default(string);
FilePathCell : string = Default(string);
FileHashCell : string = Default(string);
FileSizeCell : string = Default(string);
KnownHashCell : string = Default(string);
CSVFileToWrite: TFilestreamUTF8;
ExportSQLQuery: TSQLQuery;
n : integer = Default(integer);
KnownHashFlagIsSet : boolean = Default(boolean);
begin
Mainform.StatusBar2.SimpleText := 'Writing data to file...please wait';
Application.ProcessMessages;
ChosenDelimiter := MainForm.ChosenDelimiter;
try
// Create a filestream for the output CSV.
CSVFileToWrite := TFileStreamUTF8.Create(Filename, fmCreate);
if CSVFileToWrite.Handle > 0 then
begin
linetowrite := ('No' + ChosenDelimiter +
'Filename' + ChosenDelimiter +
'FilePath' + ChosenDelimiter +
'HashValue' + ChosenDelimiter +
'FileSize' + ChosenDelimiter +
'KnownHashFlag' + LineEnding);
n := Length(LineToWrite);
CSVFileToWrite.Write(linetowrite[1], n);
// Write all columns, but dont try to include the Known Hash result if not computed to start with
// This boolean check should be quicker instead of checking for every row whether the field is empty or not
if MainForm.cbLoadHashList.checked then KnownHashFlagIsSet := true
else KnownHashFlagIsSet := false;
try
ExportSQLQuery := TSQLQuery.Create(nil);
try
ExportSQLQuery.SQL.Text := 'SELECT * FROM TBL_FILES'; // Get all the data from Files tab table
ExportSQLQuery.Database := SQLite3Connection1;
ExportSQLQuery.UniDirectional := True; //<- this is the important part for memory handling reasons but cant be used in an active DBGrid - only for SQLQueries
ExportSQLQuery.Open;
ExportSQLQuery.First;
while not ExportSQLQuery.EOF do
begin
// Include all columns, inc hash flag, but exclude the row count (not needed for a CSV output).
// Get the data from the ID cell
FileIDCell := ExportSQLQuery.FieldByName('No').AsString;
// Get the data from the filename cell
FileNameCell := ExportSQLQuery.FieldByName('FileName').AsString;
// Get the data from the filepath cell
FilePathCell := ExportSQLQuery.FieldByName('FilePath').AsString;
// Get the data from the filehash cell
FileHashCell := ExportSQLQuery.FieldByName('HashValue').AsString;
// Get the data from the filesize cell
FileSizeCell := ExportSQLQuery.FieldByName('FileSize').AsString;