-
Notifications
You must be signed in to change notification settings - Fork 0
/
ASGSQLite3Dsg.pas
594 lines (502 loc) · 18.3 KB
/
ASGSQLite3Dsg.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
unit ASGSQLite3Dsg;
{*_* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Author: Albert Drent
Description: SQLite Design time component class
For a description of changes, bugfixes, enhancements etc.,
look into the ASGSQLite3.pas file.
Creation: November 2003
Version: 2005.02.A
EMail: [email protected] (sqlite.aducom.com)
Support: [email protected] (sqlite.aducom.com)
for questions, remarks etc. please register on the forum on
www.aducom.com/sqlite
Legal issues: Copyright (C) 2003..2006 by Aducom Software
Aducom Software
Eckhartstr 61
9746 BN Groningen
Netherlands
Open Source licence (BSD: http://www.opensource.org/licenses/bsd-license.php)
Copyright (c) 2006, Aducom Software
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
Neither the name of Aducom Software nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Acknowledgement
These components were written for our own needs. Since SQLite is
a freeware component we like to donate this one to the community
too. Parts of the code is adapted from several sources, but mainly
from the sample of Borland itself. And, of course, we did a lot
and still are...
To Do
A lot...
We are very busy, but will develop on our needs. If anyone can
contribute, please feel welcome. Alter the source with lots of comment
and mail it to me. If it works right I will add it to the official
source and add your credit here below. Before you start, please
put a request on the forum. It would be a shame if you develop something
which already is...
*_* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * }
interface
uses
{$I asqlite_def.inc}
{$IFDEF ASQLITE_D6PLUS}
DesignIntf, DesignEditors,
{$ELSE}
DsgnIntf,
{$ENDIF}
FileCtrl,Classes, Controls, AMDSqlite3;
type
TASQLiteEditor = Class( TComponentEditor )
Function GetVerbCount: integer; Override;
Function GetVerb( Index: integer ): String; Override;
Procedure ExecuteVerb( Index: integer ); Override;
End;
TDatabasePropertyEditor = class(TPropertyEditor)
public
function GetAttributes : TPropertyAttributes; override;
function GetValue : string; override;
procedure GetValues(Proc: TGetStrProc); override;
procedure SetValue(const Value: string); override;
end;
{ Property editor for TASQLiteTable }
TASQLite3DatabaseProperty = class(TDatabasePropertyEditor)
// procedure GetValueList(Values: TStringList);
end;
TTablePropertyEditor = class(TPropertyEditor)
public
function GetAttributes : TPropertyAttributes; override;
function GetValue : string; override;
procedure GetValues(Proc: TGetStrProc); override;
procedure SetValue(const Value: string); override;
end;
{ Property editor for TASQLiteTableNames }
TASQLite3TableNameProperty = class(TTablePropertyEditor)
// procedure GetValueList(Values: TStringList);
end;
TMasterDetailPropertyEditor = class(TPropertyEditor)
public
function GetAttributes : TPropertyAttributes; override;
function GetValue : string; override;
procedure GetValues(Proc: TGetStrProc); override;
procedure SetValue(const Value: string); override;
end;
{ Property editor for TASQLiteMasterDetail fields }
TASQLite3MasterDetailProperty = class(TMasterDetailPropertyEditor)
// procedure GetValueList(Values: TStringList);
end;
TStoragePropertyEditor = class(TPropertyEditor)
public
function GetAttributes : TPropertyAttributes; override;
function GetValue : string; override;
procedure GetValues(Proc: TGetStrProc); override;
procedure SetValue(const Value: string); override;
end;
{ Property editor for TASQLiteStorage fields }
TASQLite3StorageProperty = class(TStoragePropertyEditor)
// procedure GetValueList(Values: TStringList);
end;
TSyncPropertyEditor = class(TPropertyEditor)
public
function GetAttributes : TPropertyAttributes; override;
function GetValue : string; override;
procedure GetValues(Proc: TGetStrProc); override;
procedure SetValue(const Value: string); override;
end;
{ Property editor for TASQLiteStorage fields }
TASQLite3SyncProperty = class(TSyncPropertyEditor)
// procedure GetValueList(Values: TStringList);
end;
TDirPropertyEditor = class(TPropertyEditor)
public
function GetAttributes : TPropertyAttributes; override;
function GetValue : string; override;
procedure GetValues(Proc: TGetStrProc); override;
procedure SetValue(const Value: string); override;
end;
{ Property editor for TASQLiteStorage fields }
TASQLite3DirProperty = class(TDirPropertyEditor)
// procedure GetValueList(Values: TStringList);
end;
TDLLDirPropertyEditor = class(TPropertyEditor)
public
function GetAttributes : TPropertyAttributes; override;
function GetValue : string; override;
procedure GetValues(Proc: TGetStrProc); override;
procedure SetValue(const Value: string); override;
end;
{ Property editor for DLL directory}
TASQLite3DLLDirProperty = class(TDLLDirPropertyEditor)
// procedure GetValueList(Values: TStringList);
end;
TFileTypePropertyEditor = class(TPropertyEditor)
public
function GetAttributes : TPropertyAttributes; override;
function GetValue : string; override;
procedure GetValues(Proc: TGetStrProc); override;
procedure SetValue(const Value: string); override;
end;
{ Property editor for TASQLiteOutputtype fields }
TASQLite3FileTypeProperty = class(TFileTypePropertyEditor)
// procedure GetValueList(Values: TStringList);
end;
TTransactionPropertyEditor = class(TPropertyEditor)
public
function GetAttributes : TPropertyAttributes; override;
function GetValue : string; override;
procedure GetValues(Proc: TGetStrProc); override;
procedure SetValue(const Value: string); override;
end;
{ Property editor for TASQLiteOutputtype fields }
TASQLite3TransactionProperty = class(TTransactionPropertyEditor)
// procedure GetValueList(Values: TStringList);
end;
TCharEncPropertyEditor = class(TPropertyEditor)
public
function GetAttributes : TPropertyAttributes; override;
function GetValue : string; override;
procedure GetValues(Proc: TGetStrProc); override;
procedure SetValue(const Value: string); override;
end;
{ Property editor for TASQLiteOutputtype fields }
TASQLite3CharEncProperty = class(TCharEncPropertyEditor)
// procedure GetValueList(Values: TStringList);
end;
procedure Register;
implementation
uses ASGSQLite3, SysUtils, Forms, Dialogs;
// *************************************************************************************
// ** GetVerbCount
// *************************************************************************************
Function TASQLiteEditor.GetVerbCount: integer;
Begin
Result := 1;
End;
// *************************************************************************************
// ** GetVerb
// *************************************************************************************
Function TASQLiteEditor.GetVerb( Index: integer ): String;
Begin
Case Index Of
0: Result := 'Aducom Software';
End;
End;
// *************************************************************************************
// ** ExecuteVerb
// *************************************************************************************
Procedure TASQLiteEditor.ExecuteVerb( Index: integer );
Begin
Case Index Of
0: ;//ShowAboutBox( 'Max''s WebUpdate Component' );
End;
End;
function TDatabasePropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result := [paMultiSelect, paDialog, paValueList, paRevertable];
end;
procedure TDatabasePropertyEditor.GetValues(Proc: TGetStrProc);
var
sr: TSearchRec;
begin
with GetComponent(0) as TASQLite3DB do begin
if DefaultExt = '' then DefaultExt := '.sqb';
if DefaultExt[1]<> '.' then DefaultExt := '.'+DefaultExt;
if DefaultDir <> '' then
if DefaultDir[Length(DefaultDir)]<>'\' then
DefaultDir := DefaultDir + '\';
if FindFirst(DefaultDir+'*'+DefaultExt,faAnyFile, sr) = 0 then begin
repeat
Proc(sr.Name);
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;
Proc(':memory:');
end;
function TDatabasePropertyEditor.GetValue: string;
begin
Result := GetStrValue;
end;
procedure TDatabasePropertyEditor.SetValue(const Value: string);
begin
SetStrValue(Value);
end;
//procedure TASQLiteTableNameProperty.GetValueList(Values: TStringList);
//begin
//end;
function TTablePropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result := [paMultiSelect, paDialog, paValueList, paRevertable];
end;
procedure TTablePropertyEditor.GetValues(Proc: TGetStrProc);
var MyList : TStringList;
i : integer;
begin
with GetComponent(0) as TASQLite3Table do begin
if Connection = nil then begin // check to see if a valid database
raise AsgError.Create('no database connection'); // object is linked
exit;
end;
MyList := TStringList.Create;
Connection.GetTableNames(MyList, true);
if MyList.Count > 0 then // marc 20040222
for i := 0 to MyList.Count - 1 do Proc(MyList[i]);
MyList.Free;
end;
end;
function TTablePropertyEditor.GetValue: string;
begin
Result := GetStrValue;
end;
procedure TTablePropertyEditor.SetValue(const Value: string);
begin
SetStrValue(Value);
end;
function TMasterDetailPropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result := [paDialog, paRevertable];
end;
procedure TMasterDetailPropertyEditor.GetValues(Proc: TGetStrProc);
var
i,p : integer;
r : string;
oldr : string;
begin
with GetComponent(0) as TASQLite3BaseQuery do begin
if not Assigned(MasterSource) then begin
Proc('');
exit;
end;
if not Assigned(MasterSource.Dataset) then begin
Proc('');
exit;
end;
FMD := TFMD.Create(Application);
if not Active then open;
if not Active then exit;
for i := 0 to FieldDefs.Count - 1 do
FMD.LBDetail.Items.Add(FieldDefs.Items[i].Name);
if not Mastersource.Dataset.Active then Mastersource.DataSet.Open;
if not Mastersource.Dataset.Active then exit;
for i := 0 to MasterSource.DataSet.FieldDefs.Count - 1 do
FMD.LBMaster.Items.Add(MasterSource.DataSet.FieldDefs.Items[i].Name);
r := MasterFields;
Oldr := r;
while r <> '' do begin
p := pos(';', r);
if p = 0 then begin
if Trim(r) <> '' then FMD.LBLinked.Items.Add(Trim(r));
r := '';
end else begin
FMD.LBLinked.Items.Add(Trim(Copy(r, 1, p-1)));
System.Delete(r, 1, p);
end;
end;
if FMD.ShowModal = mrOk then begin
for i := 0 to FMD.LBLinked.Items.Count - 1 do begin
r := r + FMD.LBLinked.Items[i]+';';
end;
end else r := oldr;
FMD.Free;
end;
Proc(r);
end;
function TMasterDetailPropertyEditor.GetValue: string;
begin
Result := GetStrValue;
end;
procedure TMasterDetailPropertyEditor.SetValue(const Value: string);
begin
SetStrValue(Value);
end;
function TStoragePropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result := [paValueList, paRevertable];
end;
procedure TStoragePropertyEditor.GetValues(Proc: TGetStrProc);
begin
Proc('DEFAULT');
Proc('MEMORY');
Proc('FILE');
end;
function TStoragePropertyEditor.GetValue: string;
begin
Result := GetStrValue;
end;
procedure TStoragePropertyEditor.SetValue(const Value: string);
begin
SetStrValue(Value);
end;
function TSyncPropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result := [paValueList, paRevertable];
end;
procedure TSyncPropertyEditor.GetValues(Proc: TGetStrProc);
begin
Proc('FULL');
Proc('NORMAL');
Proc('OFF');
end;
function TSyncPropertyEditor.GetValue: string;
begin
Result := GetStrValue;
end;
procedure TSyncPropertyEditor.SetValue(const Value: string);
begin
SetStrValue(Value);
end;
function TDirPropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result := [paDialog, paRevertable];
end;
procedure TDirPropertyEditor.GetValues(Proc: TGetStrProc);
var Dir : string;
begin
Dir := 'C:\';
SelectDirectory(Dir, [sdAllowCreate, sdPerformCreate, sdPrompt],0);
Proc(Dir);
end;
function TDirPropertyEditor.GetValue: string;
begin
Result := GetStrValue;
end;
procedure TDirPropertyEditor.SetValue(const Value: string);
begin
SetStrValue(Value);
end;
function TDLLDirPropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result := [paDialog, paRevertable];
end;
procedure TDLLDirPropertyEditor.GetValues(Proc: TGetStrProc);
var Dir : string;
// Drv : string;
begin
Dir := 'C:\';
SelectDirectory(Dir, [sdAllowCreate, sdPerformCreate, sdPrompt],0);
// ExtractFileDrive(Dir);
// if Drv=''
if Dir[Length(Dir)]<>'\' then Dir := Dir +'\';
Proc(Dir+'sqlite3.dll');
end;
function TDLLDirPropertyEditor.GetValue: string;
begin
Result := GetStrValue;
end;
procedure TDLLDirPropertyEditor.SetValue(const Value: string);
begin
SetStrValue(Value);
end;
function TFileTypePropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result := [paValueList, paRevertable];
end;
procedure TFileTypePropertyEditor.GetValues(Proc: TGetStrProc);
begin
Proc('htmlfile');
Proc('xmlfile');
Proc('textfile');
end;
function TFileTypePropertyEditor.GetValue: string;
begin
Result := GetStrValue;
end;
procedure TFileTypePropertyEditor.SetValue(const Value: string);
begin
SetStrValue(Value);
end;
function TTransactionPropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result := [paValueList, paRevertable];
end;
procedure TTransactionPropertyEditor.GetValues(Proc: TGetStrProc);
begin
Proc('DEFAULT');
Proc('DEFERRED');
Proc('IMMEDIATE');
Proc('EXCLUSIVE');
end;
function TTransactionPropertyEditor.GetValue: string;
begin
Result := GetStrValue;
end;
procedure TTransactionPropertyEditor.SetValue(const Value: string);
begin
SetStrValue(Value);
end;
function TCharEncPropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result := [paValueList, paRevertable];
end;
procedure TCharEncPropertyEditor.GetValues(Proc: TGetStrProc);
begin
Proc('STANDARD');
Proc('UTF8');
// Proc('OFF');
end;
function TCharEncPropertyEditor.GetValue: string;
begin
Result := GetStrValue;
end;
procedure TCharEncPropertyEditor.SetValue(const Value: string);
begin
SetStrValue(Value);
end;
{ This procedure is used to register this component on the component palette }
procedure Register;
begin
RegisterPropertyEditor(TypeInfo(string), TASQLite3DB, 'Database',
TASQLite3DatabaseProperty);
RegisterPropertyEditor(TypeInfo(string), TASQLite3DB, 'DefaultDir',
TASQLite3DirProperty);
RegisterPropertyEditor(TypeInfo(string), TASQLite3DB, 'DriverDLL',
TASQLite3DLLDirProperty);
RegisterPropertyEditor(TypeInfo(string), TASQLite3Table, 'TableName',
TASQLite3TableNameProperty);
RegisterPropertyEditor(TypeInfo(string), TASQLite3BaseQuery, 'MasterFields',
TASQLite3MasterDetailProperty);
RegisterPropertyEditor(TypeInfo(string), TASQLite3Pragma, 'TempStore',
TASQLite3StorageProperty);
RegisterPropertyEditor(TypeInfo(string), TASQLite3Pragma, 'DefaultTempStore',
TASQLite3StorageProperty);
RegisterPropertyEditor(TypeInfo(string), TASQLite3Pragma, 'Synchronous',
TASQLite3SyncProperty);
RegisterPropertyEditor(TypeInfo(string), TASQLite3Pragma, 'DefaultSynchronous',
TASQLite3SyncProperty);
RegisterPropertyEditor(TypeInfo(string), TASQLite3Output, 'OutputType',
TASQLite3FileTypeProperty);
RegisterPropertyEditor(TypeInfo(string), TASQLite3BaseQuery, 'TransactionType',
TASQLite3TransactionProperty);
RegisterPropertyEditor(TypeInfo(string), TASQLite3DB, 'TransactionType',
TASQLite3TransactionProperty);
RegisterPropertyEditor(TypeInfo(string), TASQLite3DB, 'CharacterEncoding',
TASQLite3CharEncProperty);
RegisterComponents('Aducom SQLite3', [TASQLite3DB]);
RegisterComponents('Aducom SQLite3', [TASQLite3Query]);
RegisterComponents('Aducom SQLite3', [TASQLite3Table]);
RegisterComponents('Aducom SQLite3', [TASQLite3UpdateSQL]);
RegisterComponents('Aducom SQLite3', [TASQLite3Pragma]);
RegisterComponents('Aducom SQLite3', [TASQLite3Log]);
RegisterComponents('Aducom SQLite3', [TASQLite3InlineSQL]);
RegisterComponents('Aducom SQLite3', [TASQLite3Output]);
RegisterComponentEditor(TASQLite3DB, TASQLiteEditor);
end;
end.