forked from synopse/mORMot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SynOleDB.pas
3230 lines (3006 loc) · 123 KB
/
SynOleDB.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
/// fast OleDB direct access classes
// - this unit is a part of the freeware Synopse framework,
// licensed under a MPL/GPL/LGPL tri-license; version 1.18
unit SynOleDB;
{
This file is part of Synopse framework.
Synopse framework. Copyright (C) 2017 Arnaud Bouchez
Synopse Informatique - https://synopse.info
*** BEGIN LICENSE BLOCK *****
Version: MPL 1.1/GPL 2.0/LGPL 2.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the License.
The Original Code is Synopse mORMot framework.
The Initial Developer of the Original Code is Arnaud Bouchez.
Portions created by the Initial Developer are Copyright (C) 2017
the Initial Developer. All Rights Reserved.
Contributor(s):
- Esteban Martin (EMartin)
- Pavel (mpv)
Alternatively, the contents of this file may be used under the terms of
either the GNU General Public License Version 2 or later (the "GPL"), or
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
in which case the provisions of the GPL or the LGPL are applicable instead
of those above. If you wish to allow use of your version of this file only
under the terms of either the GPL or the LGPL, and not to allow others to
use your version of this file under the terms of the MPL, indicate your
decision by deleting the provisions above and replace them with the notice
and other provisions required by the GPL or the LGPL. If you do not delete
the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
***** END LICENSE BLOCK *****
Several implementation notes about Oracle and OleDB:
- Oracle OleDB provider by Microsoft do not handle BLOBs. Period. :(
- Oracle OleDB provider by Oracle will handle only 3/4 BLOBs. :(
See http://stackoverflow.com/questions/6147274/is-oraoledb-provider-in-net-unreliable-on-clob-fields/6640101#6640101
- Oracle OleDB provider by Oracle or Microsoft could trigger some ORA-80040e4B
error when accessing column data with very low dates value (like 0001-01-01)
- in all cases, that's why we wrote the SynDBOracle unit, for direct OCI
access - and it is from 2 to 10 times faster than OleDB, with no setup issue
- or take a look at latest patches from Oracle support, and pray it's fixed ;)
http://stackoverflow.com/questions/6147274/is-oraoledb-provider-in-net-unreliable-on-clob-fields/6661058#6661058
Version 1.14
- first public release, corresponding to SQLite3 Framework 1.14
Version 1.15
- SynDB unit extracted from previous SynOleDB.pas
- several fixes and speed enhancements
- made the code compatible with Delphi 5
- TOleDBStatement class now follows the prepared statement pattern introduced
with its parent TSQLDBStatement
- now able to retrieve table names and column information from OleDB metadata
including GetTableNames, GetFields, GetFieldDefinitions and GetForeignKey
methods - able to use faster direct SQL retrieval (e.g. for Oracle / MS SQL)
Version 1.16
- add some reference to https://synopse.info/fossil/tktview?name=213544b2f5
in case of wrong implementation of multi-thread connection (within the
THttpServerGeneric mORMot server, for instance)
Version 1.17
- fix issue (depending on OleDB Provider) about ordinal binding error
- fix issue about void string parameter binding
- fix issue in TOleDBStatement.BindCurrency() method
- fix retrieval of table and field metadata, for tables without schema
(e.g. Jet/MSAccess database)
- added TOleDBJetConnectionProperties kind of connection to direct
access of Microsoft Jet databases (.mdb files)
- added corresponding IsJetFile() function
- added FieldSize optional parameter to TOleDBStatement.ColumnType()
method (used e.g. by SynDBVCL to provide the expected field size on TDataSet)
- added TOleDBConnectionProperties.CreateDatabase able to create a database
from the supplied connection string (used e.g. to initialize .mdb files)
- code refactoring, especially about error handling and ODBC integration
- CoInit and CoUninit made public for user convenience, e.g. when using
custom COM objects in a mORMot multi-thread servers
Version 1.18
- SQL statements with no results will now be cached to increase speed
- TOleDBMSSQLConnectionProperties provider changed to more stable SQLNCLI10
- added TOleDBMSSQL2005ConnectionProperties, TOleDBMSSQL2008ConnectionProperties
and TOleDBMSSQL2012ConnectionProperties classes to specify every available
MS SQL Server providers SQLNCLI, SQLNCLI10 or SQLNCLI11
- now trim any spaces when retrieving database schema text values
- added TOleDBStatement.UpdateCount overridden method (dc proposal)
- fixed ticket [4c68975022] about broken SQL statement when logging active
- fixed ticket [a24cbd30e3] about 64 bit compilation
- now works as expected under Win64 (a lot of previous code was Win32 specific)
- fixed issue when binding NULL parameters with some DB providers (e.g. Jet)
- fixed issue in TOleDBConnectionProperties.ColumnTypeNativeToDB() about
unrecognized column type when table schema is retrieved from SQL
- fixed issue when running TOleDBStatement.Step(true)
- fixed issue [e8c211062e] when binding NULL values in multi INSERT statements
- exception during Commit should leave transaction state - see [ca035b8f0da]
- fixed logging SQL content of external OleDB statements
- added TOleDBStatement.BindArray for `array of Int64` & `array of RawUFT8`
binding for `select` statements( via additional TABLE variable)
- added TOleDBInformixConnectionProperties - by EMartin
}
{$I Synopse.inc} // define HASINLINE USETYPEINFO CPU32 CPU64 OWNNORMTOUPPER
interface
uses
Windows,
{$ifdef ISDELPHIXE2}System.Win.ComObj,{$else}ComObj,{$endif}
ActiveX,
SysUtils,
{$ifndef DELPHI5OROLDER}
Variants,
{$endif}
Classes,
Contnrs,
SynCommons,
SynLog,
SynDB;
{ -------------- OleDB interfaces, constants and types
(OleDB.pas is not provided e.g. in Delphi 7 Personal) }
const
IID_IUnknown: TGUID = '{00000000-0000-0000-C000-000000000046}';
IID_IAccessor: TGUID = '{0C733A8C-2A1C-11CE-ADE5-00AA0044773D}';
IID_IRowset: TGUID = '{0C733A7C-2A1C-11CE-ADE5-00AA0044773D}';
IID_IMultipleResults: TGUID = '{0C733A90-2A1C-11CE-ADE5-00AA0044773D}';
IID_IOpenRowset: TGUID = '{0C733A69-2A1C-11CE-ADE5-00AA0044773D}';
IID_IDataInitialize: TGUID = '{2206CCB1-19C1-11D1-89E0-00C04FD7A829}';
IID_IDBInitialize: TGUID = '{0C733A8B-2A1C-11CE-ADE5-00AA0044773D}';
IID_ICommandText: TGUID = '{0C733A27-2A1C-11CE-ADE5-00AA0044773D}';
IID_ISSCommandWithParameters: TGUID = '{EEC30162-6087-467C-B995-7C523CE96561}';
IID_ITransactionLocal: TGUID = '{0C733A5F-2A1C-11CE-ADE5-00AA0044773D}';
IID_IDBPromptInitialize: TGUID = '{2206CCB0-19C1-11D1-89E0-00C04FD7A829}';
CLSID_DATALINKS: TGUID = '{2206CDB2-19C1-11D1-89E0-00C04FD7A829}';
CLSID_MSDAINITIALIZE: TGUID = '{2206CDB0-19C1-11D1-89E0-00C04FD7A829}';
CLSID_ROWSET_TVP: TGUID = '{C7EF28D5-7BEE-443F-86DA-E3984FCD4DF9}';
DB_NULLGUID: TGuid = '{00000000-0000-0000-0000-000000000000}';
DBGUID_DEFAULT: TGUID = '{C8B521FB-5CF3-11CE-ADE5-00AA0044773D}';
DBSCHEMA_TABLES: TGUID = '{C8B52229-5CF3-11CE-ADE5-00AA0044773D}';
DBSCHEMA_COLUMNS: TGUID = '{C8B52214-5CF3-11CE-ADE5-00AA0044773D}';
DBSCHEMA_INDEXES: TGUID = '{C8B5221E-5CF3-11CE-ADE5-00AA0044773D}';
DBSCHEMA_FOREIGN_KEYS: TGUID = '{C8B522C4-5CF3-11CE-ADE5-00AA0044773D}';
DBPROPSET_SQLSERVERPARAMETER: TGUID = '{FEE09128-A67D-47EA-8D40-24A1D4737E8D}';
// PropIds for DBPROPSET_SQLSERVERPARAMETER
SSPROP_PARAM_XML_SCHEMACOLLECTION_CATALOGNAME = 24;
SSPROP_PARAM_XML_SCHEMACOLLECTION_SCHEMANAME = 25;
SSPROP_PARAM_XML_SCHEMACOLLECTIONNAME = 26;
SSPROP_PARAM_UDT_CATALOGNAME = 27;
SSPROP_PARAM_UDT_SCHEMANAME = 28;
SSPROP_PARAM_UDT_NAME = 29;
SSPROP_PARAM_TYPE_CATALOGNAME = 38;
SSPROP_PARAM_TYPE_SCHEMANAME = 39;
SSPROP_PARAM_TYPE_TYPENAME = 40;
SSPROP_PARAM_TABLE_DEFAULT_COLUMNS = 41;
SSPROP_PARAM_TABLE_COLUMN_SORT_ORDER = 42;
DBTYPE_EMPTY = $00000000;
DBTYPE_NULL = $00000001;
DBTYPE_I2 = $00000002;
DBTYPE_I4 = $00000003;
DBTYPE_R4 = $00000004;
DBTYPE_R8 = $00000005;
DBTYPE_CY = $00000006;
DBTYPE_DATE = $00000007;
DBTYPE_BSTR = $00000008;
DBTYPE_IDISPATCH = $00000009;
DBTYPE_ERROR = $0000000A;
DBTYPE_BOOL = $0000000B;
DBTYPE_VARIANT = $0000000C;
DBTYPE_IUNKNOWN = $0000000D;
DBTYPE_DECIMAL = $0000000E;
DBTYPE_UI1 = $00000011;
DBTYPE_ARRAY = $00002000;
DBTYPE_BYREF = $00004000;
DBTYPE_I1 = $00000010;
DBTYPE_UI2 = $00000012;
DBTYPE_UI4 = $00000013;
DBTYPE_I8 = $00000014;
DBTYPE_UI8 = $00000015;
DBTYPE_GUID = $00000048;
DBTYPE_VECTOR = $00001000;
DBTYPE_RESERVED = $00008000;
DBTYPE_BYTES = $00000080;
DBTYPE_STR = $00000081;
DBTYPE_WSTR = $00000082;
DBTYPE_NUMERIC = $00000083;
DBTYPE_UDT = $00000084;
DBTYPE_DBDATE = $00000085;
DBTYPE_DBTIME = $00000086;
DBTYPE_DBTIMESTAMP = $00000087;
DBTYPE_FILETIME = $00000040;
DBTYPE_DBFILETIME = $00000089;
DBTYPE_PROPVARIANT = $0000008A;
DBTYPE_VARNUMERIC = $0000008B;
DBTYPE_TABLE = $0000008F; // introduced in SQL 2008
DBPARAMIO_NOTPARAM = $00000000;
DBPARAMIO_INPUT = $00000001;
DBPARAMIO_OUTPUT = $00000002;
DBPARAMFLAGS_ISINPUT = $00000001;
DBPARAMFLAGS_ISOUTPUT = $00000002;
DBPARAMFLAGS_ISSIGNED = $00000010;
DBPARAMFLAGS_ISNULLABLE = $00000040;
DBPARAMFLAGS_ISLONG = $00000080;
DBPART_VALUE = $00000001;
DBPART_LENGTH = $00000002;
DBPART_STATUS = $00000004;
DBMEMOWNER_CLIENTOWNED = $00000000;
DBMEMOWNER_PROVIDEROWNED = $00000001;
DBACCESSOR_ROWDATA = $00000002;
DBACCESSOR_PARAMETERDATA = $00000004;
DBACCESSOR_OPTIMIZED = $00000008;
DB_E_CANCELED = HResult($80040E4E);
DB_E_NOTSUPPORTED = HResult($80040E53);
DBCOLUMNFLAGS_MAYBENULL = $00000040;
ISOLATIONLEVEL_READCOMMITTED = $00001000;
DBPROMPTOPTIONS_PROPERTYSHEET = $2;
DB_NULL_HCHAPTER = $00;
DB_S_ENDOFROWSET = $00040EC6;
XACTTC_SYNC = $00000002;
MAXBOUND = 65535; { High bound for arrays }
DBKIND_GUID_NAME = 0;
DBKIND_GUID_PROPID = ( DBKIND_GUID_NAME + 1 );
DBKIND_NAME = ( DBKIND_GUID_PROPID + 1 );
DBKIND_PGUID_NAME = ( DBKIND_NAME + 1 );
DBKIND_PGUID_PROPID = ( DBKIND_PGUID_NAME + 1 );
DBKIND_PROPID = ( DBKIND_PGUID_PROPID + 1 );
DBKIND_GUID = ( DBKIND_PROPID + 1 );
type
/// indicates whether the data value or some other value, such as a NULL,
// is to be used as the value of the column or parameter
// - see http://msdn.microsoft.com/en-us/library/ms722617
// and http://msdn.microsoft.com/en-us/library/windows/desktop/ms716934
TOleDBStatus = (
stOK, stBadAccessor, stCanNotConvertValue, stIsNull, stTruncated,
stSignMismatch, stDataoverFlow, stCanNotCreateValue, stUnavailable,
stPermissionDenied, stIntegrityViolation, stSchemaViolation, stBadStatus,
stDefault, stCellEmpty, stIgnoreColumn, stDoesNotExist, stInvalidURL,
stResourceLocked, stResoruceExists, stCannotComplete, stVolumeNotFound,
stOutOfSpace, stCannotDeleteSource, stAlreadyExists, stCanceled,
stNotCollection, stRowSetColumn);
/// binding status of a given column
// - see http://msdn.microsoft.com/en-us/library/windows/desktop/ms720969
// and http://msdn.microsoft.com/en-us/library/windows/desktop/ms716934
TOleDBBindStatus = (
bsOK, bsBadOrdinal, bsUnsupportedConversion, bsBadBindInfo,
bsBadStorageFlags, bsNoInterface, bsMultipleStorage);
PIUnknown = ^IUnknown;
HACCESSOR = PtrUInt;
HACCESSORDynArray = array of HACCESSOR;
HCHAPTER = PtrUInt;
HROW = PtrUInt;
PHROW = ^HROW;
DBPART = UINT;
DBMEMOWNER = UINT;
DBPARAMIO = UINT;
DBPROPSTATUS = UINT;
DBPROPID = UINT;
DBPROPOPTIONS = UINT;
DBCOLUMNFLAGS = UINT;
DBKIND = UINT;
DBSTATUS = DWORD;
DBPARAMFLAGS = DWORD;
DBTYPE = Word;
DBRESULTFLAG = UINT;
PBoid = ^TBoid;
{$ifdef CPU64}
{$A+} // un-packed records
{$else}
{$A-} // packed records
{$endif}
TBoid = record
rgb_: array[0..15] of Byte;
end;
TXactOpt = record
ulTimeout: UINT;
szDescription: array[0..39] of Shortint;
end;
TXactTransInfo = record
uow: PBoid;
isoLevel: Integer;
isoFlags: UINT;
grfTCSupported: UINT;
grfRMSupported: UINT;
grfTCSupportedRetaining: UINT;
grfRMSupportedRetaining: UINT;
end;
PErrorInfo = ^TErrorInfo;
TErrorInfo = record
hrError: HResult;
dwMinor: UINT;
clsid: TGUID;
iid: TGUID;
dispid: Integer;
end;
PDBParams = ^TDBParams;
TDBParams = record
pData: Pointer;
cParamSets: PtrUInt;
HACCESSOR: HACCESSOR;
end;
PDBObject = ^TDBObject;
TDBObject = record
dwFlags: UINT;
iid: TGUID;
end;
PDBBindExt = ^TDBBindExt;
TDBBindExt = record
pExtension: PByte;
ulExtension: PtrUInt;
end;
PDBBinding = ^TDBBinding;
TDBBinding = record
iOrdinal: PtrUInt;
obValue: PtrUInt;
obLength: PtrUInt;
obStatus: PtrUInt;
pTypeInfo: ITypeInfo;
pObject: PDBObject;
pBindExt: PDBBindExt;
dwPart: DBPART;
dwMemOwner: DBMEMOWNER;
eParamIO: DBPARAMIO;
cbMaxLen: PtrUInt;
dwFlags: UINT;
wType: DBTYPE;
bPrecision: Byte;
bScale: Byte;
end;
PDBBindingArray = ^TDBBindingArray;
TDBBindingArray = array[0..MAXBOUND] of TDBBinding;
TDBBindingDynArray = array of TDBBinding;
DBIDGUID = record
case Integer of
0: (guid: TGUID);
1: (pguid: ^TGUID);
end;
DBIDNAME = record
case Integer of
0: (pwszName: PWideChar);
1: (ulPropid: UINT);
end;
PDBID = ^DBID;
DBID = record
uGuid: DBIDGUID;
eKind: DBKIND;
uName: DBIDNAME;
end;
PDBIDArray = ^TDBIDArray;
TDBIDArray = array[0..MAXBOUND] of DBID;
PDBColumnInfo = ^TDBColumnInfo;
TDBColumnInfo = record
pwszName: PWideChar;
pTypeInfo: ITypeInfo;
iOrdinal: PtrUInt;
dwFlags: DBCOLUMNFLAGS;
ulColumnSize: PtrUInt;
wType: DBTYPE;
bPrecision: Byte;
bScale: Byte;
columnid: DBID;
end;
DBSOURCETYPE = DWORD;
PDBSOURCETYPE = ^DBSOURCETYPE;
TDBProp = record
dwPropertyID: DBPROPID;
dwOptions: DBPROPOPTIONS;
dwStatus: DBPROPSTATUS;
colid: DBID;
vValue: OleVariant;
end;
PDBPropArray = ^TDBPropArray;
TDBPropArray = array[0..MAXBOUND] of TDBProp;
TDBPropSet = record
rgProperties: PDBPropArray;
cProperties: UINT;
guidPropertySet: TGUID;
end;
PDBPropSet = ^TDBPropSet;
PDBPropSetArray = ^TDBPropSetArray;
TDBPropSetArray = array[0..MAXBOUND] of TDBPropSet;
TDBSchemaRec = record
SchemaGuid: TGuid;
SupportedRestrictions: Integer;
end;
TSSPARAMPROPS = record
iOrdinal: ULONG;
cPropertySets: ULONG;
rgPropertySets: PDBPropSet;
end;
PSSPARAMPROPS = ^TSSPARAMPROPS;
PSSPARAMPROPSArray = ^TSSPARAMPROPSArray;
TSSPARAMPROPSArray = array[0..MAXBOUND] of TSSPARAMPROPS;
TSSPARAMPROPSDynArray = array of TSSPARAMPROPS;
PDBParamInfo = ^TDBParamInfo;
DBPARAMINFO = packed record
dwFlags: UINT;
iOrdinal: UINT;
pwszName: PWideChar;
pTypeInfo: ITypeInfo;
ulParamSize: UINT;
wType: DBTYPE;
bPrecision: Byte;
bScale: Byte;
end;
TDBParamInfo = DBPARAMINFO;
PUintArray = ^TUintArray;
TUintArray = array[0..MAXBOUND] of UINT;
TUintDynArray = array of UINT;
PDBParamBindInfo = ^TDBParamBindInfo;
DBPARAMBINDINFO = packed record
pwszDataSourceType: PWideChar;
pwszName: PWideChar;
ulParamSize: UINT;
dwFlags: DBPARAMFLAGS;
bPrecision: Byte;
bScale: Byte;
end;
TDBParamBindInfo = DBPARAMBINDINFO;
PDBParamBindInfoArray = ^TDBParamBindInfoArray;
TDBParamBindInfoArray = array[0..MAXBOUND] of TDBParamBindInfo;
TDBParamBindInfoDynArray = array of TDBParamBindInfo;
{$ifndef CPU64}
{$A+} // packed records
{$endif}
/// initialize and uninitialize OleDB data source objects and enumerators
IDBInitialize = interface(IUnknown)
['{0C733A8B-2A1C-11CE-ADE5-00AA0044773D}']
function Initialize: HResult; stdcall;
function Uninitialize: HResult; stdcall;
end;
/// create an OleDB data source object using a connection string
IDataInitialize = interface(IUnknown)
['{2206CCB1-19C1-11D1-89E0-00C04FD7A829}']
function GetDataSource(const pUnkOuter: IUnknown; dwClsCtx: DWORD;
pwszInitializationString: POleStr; const riid: TIID;
var DataSource: IUnknown): HResult; stdcall;
function GetInitializationString(const DataSource: IUnknown;
fIncludePassword: Boolean; out pwszInitString: POleStr): HResult; stdcall;
function CreateDBInstance(const clsidProvider: TGUID;
const pUnkOuter: IUnknown; dwClsCtx: DWORD; pwszReserved: POleStr;
riid: TIID; var DataSource: IUnknown): HResult; stdcall;
function CreateDBInstanceEx(const clsidProvider: TGUID;
const pUnkOuter: IUnknown; dwClsCtx: DWORD; pwszReserved: POleStr;
pServerInfo: PCoServerInfo; cmq: ULONG; rgmqResults: PMultiQI): HResult; stdcall;
function LoadStringFromStorage(pwszFileName: POleStr;
out pwszInitializationString: POleStr): HResult; stdcall;
function WriteStringToStorage(pwszFileName, pwszInitializationString: POleStr;
dwCreationDisposition: DWORD): HResult; stdcall;
end;
/// obtain a new session to a given OleDB data source
IDBCreateSession = interface(IUnknown)
['{0C733A5D-2A1C-11CE-ADE5-00AA0044773D}']
function CreateSession(const punkOuter: IUnknown; const riid: TGUID;
out ppDBSession: IUnknown): HResult; stdcall;
end;
/// commit, abort, and obtain status information about OleDB transactions
ITransaction = interface(IUnknown)
['{0FB15084-AF41-11CE-BD2B-204C4F4F5020}']
function Commit(fRetaining: BOOL; grfTC: UINT; grfRM: UINT): HResult; stdcall;
function Abort(pboidReason: PBOID; fRetaining: BOOL; fAsync: BOOL): HResult; stdcall;
function GetTransactionInfo(out pinfo: TXactTransInfo): HResult; stdcall;
end;
/// gets and sets a suite of options associated with an OleDB transaction
ITransactionOptions = interface(IUnknown)
['{3A6AD9E0-23B9-11CF-AD60-00AA00A74CCD}']
function SetOptions(var pOptions: TXactOpt): HResult; stdcall;
function GetOptions(var pOptions: TXactOpt): HResult; stdcall;
end;
/// optional interface on OleDB sessions, used to start, commit, and abort
// transactions on the session
ITransactionLocal = interface(ITransaction)
['{0C733A5F-2A1C-11CE-ADE5-00AA0044773D}']
function GetOptionsObject(out ppOptions: ITransactionOptions): HResult; stdcall;
function StartTransaction(isoLevel: Integer; isoFlags: UINT;
const pOtherOptions: ITransactionOptions; pulTransactionLevel: PUINT): HResult; stdcall;
end;
/// provide methods to execute commands
ICommand = interface(IUnknown)
['{0C733A63-2A1C-11CE-ADE5-00AA0044773D}']
function Cancel: HResult; stdcall;
function Execute(const punkOuter: IUnknown; const riid: TGUID; var pParams: TDBParams;
pcRowsAffected: PInteger; ppRowset: PIUnknown): HResult; stdcall;
function GetDBSession(const riid: TGUID; out ppSession: IUnknown): HResult; stdcall;
end;
/// methods to access the ICommand text to be executed
ICommandText = interface(ICommand)
['{0C733A27-2A1C-11CE-ADE5-00AA0044773D}']
function GetCommandText(var pguidDialect: TGUID;
out ppwszCommand: PWideChar): HResult; stdcall;
function SetCommandText(const guidDialect: TGUID;
pwszCommand: PWideChar): HResult; stdcall;
end;
ICommandWithParameters = interface(IUnknown)
['{0C733A64-2A1C-11CE-ADE5-00AA0044773D}']
function GetParameterInfo(var pcParams: UINT; out prgParamInfo: PDBPARAMINFO;
ppNamesBuffer: PPOleStr): HResult; stdcall;
function MapParameterNames(cParamNames: UINT; rgParamNames: POleStrList;
rgParamOrdinals: PUintArray): HResult; stdcall;
function SetParameterInfo(cParams: UINT; rgParamOrdinals: PUintArray;
rgParamBindInfo: PDBParamBindInfoArray): HResult; stdcall;
end;
ISSCommandWithParameters = interface(ICommandWithParameters)
['{EEC30162-6087-467C-B995-7C523CE96561}']
function GetParameterProperties(var pcParams: PtrUInt; var prgParamProperties: PSSPARAMPROPS): HResult; stdcall;
function SetParameterProperties (cParams: PtrUInt; prgParamProperties: PSSPARAMPROPS): HResult; stdcall;
end;
/// provides methods for fetching rows sequentially, getting the data from
// those rows, and managing rows
IRowset = interface(IUnknown)
['{0C733A7C-2A1C-11CE-ADE5-00AA0044773D}']
/// Adds a reference count to an existing row handle
function AddRefRows(cRows: PtrUInt; rghRows: PPtrUIntArray;
rgRefCounts, rgRowStatus: PCardinalArray): HResult; stdcall;
/// Retrieves data from the rowset's copy of the row
function GetData(HROW: HROW; HACCESSOR: HACCESSOR; pData: Pointer): HResult; stdcall;
/// Fetches rows sequentially, remembering the previous position
// - this method has been modified from original OleDB.pas to allow direct
// typecast of prghRows parameter to pointer(fRowStepHandles)
function GetNextRows(hReserved: HCHAPTER; lRowsOffset: PtrInt; cRows: PtrInt;
out pcRowsObtained: PtrUInt; var prghRows: pointer): HResult; stdcall;
/// Releases rows
function ReleaseRows(cRows: UINT; rghRows: PPtrUIntArray; rgRowOptions,
rgRefCounts, rgRowStatus: PCardinalArray): HResult; stdcall;
/// Repositions the next fetch position to its initial position
// - that is, its position when the rowset was first created
function RestartPosition(hReserved: HCHAPTER): HResult; stdcall;
end;
IOpenRowset = interface(IUnknown)
['{0C733A69-2A1C-11CE-ADE5-00AA0044773D}']
function OpenRowset(const punkOuter: IUnknown; pTableID: PDBID; pIndexID: PDBID;
const riid: TGUID; cPropertySets: UINT; rgPropertySets: PDBPropSetArray;
ppRowset: PIUnknown): HResult; stdcall;
end;
IMultipleResults = interface(IUnknown)
['{0c733a8c-2a1c-11ce-ade5-00aa0044773d}']
function GetResult(const pUnkOuter: IUnknown; lResultFlag: DBRESULTFLAG;
const riid: TIID; pcRowsAffected: PInteger;ppRowset: PIUnknown): HResult; stdcall;
end;
/// interface used to retrieve enhanced custom error information
IErrorRecords = interface(IUnknown)
['{0c733a67-2a1c-11ce-ade5-00aa0044773d}']
function AddErrorRecord(pErrorInfo: PErrorInfo; dwLookupID: UINT;
pDispParams: pointer; const punkCustomError: IUnknown;
dwDynamicErrorID: UINT): HResult; stdcall;
function GetBasicErrorInfo(ulRecordNum: UINT;
pErrorInfo: PErrorInfo): HResult; stdcall;
function GetCustomErrorObject(ulRecordNum: UINT;
const riid: TGUID; var ppObject: IUnknown): HResult; stdcall;
function GetErrorInfo(ulRecordNum: UINT; lcid: LCID;
var ppErrorInfo: IErrorInfo): HResult; stdcall;
function GetErrorParameters(ulRecordNum: UINT;
pDispParams: pointer): HResult; stdcall;
function GetRecordCount(var pcRecords: UINT): HResult; stdcall;
end;
/// used on an OleDB session to obtain a new command
IDBCreateCommand = interface(IUnknown)
['{0C733A1D-2A1C-11CE-ADE5-00AA0044773D}']
function CreateCommand(const punkOuter: IUnknown; const riid: TGUID;
out ppCommand: ICommand): HResult; stdcall;
end;
/// provides methods for accessor management, to access OleDB data
// - An accessor is a data structure created by the consumer that describes
// how row or parameter data from the data store is to be laid out in the
// consumer's data buffer.
// - For each column in a row (or parameter in a set of parameters), the
// accessor contains a binding. A binding is a DBBinding data structure that
// holds information about a column or parameter value, such as its ordinal
// value, data type, and destination in the consumer's buffer.
IAccessor = interface(IUnknown)
['{0C733A8C-2A1C-11CE-ADE5-00AA0044773D}']
function AddRefAccessor(HACCESSOR: HACCESSOR; pcRefCount: PUINT): HResult; stdcall;
function CreateAccessor(dwAccessorFlags: UINT; cBindings: PtrUInt; rgBindings: PDBBindingArray;
cbRowSize: PtrUInt; var phAccessor: HACCESSOR; rgStatus: PCardinalArray): HResult; stdcall;
function GetBindings(HACCESSOR: HACCESSOR; pdwAccessorFlags: PUINT; var pcBindings: PtrUInt;
out prgBindings: PDBBinding): HResult; stdcall;
function ReleaseAccessor(HACCESSOR: HACCESSOR; pcRefCount: PUINT): HResult; stdcall;
end;
/// expose information about columns of an OleDB rowset or prepared command
IColumnsInfo = interface(IUnknown)
['{0C733A11-2A1C-11CE-ADE5-00AA0044773D}']
function GetColumnInfo(var pcColumns: PtrUInt; out prgInfo: PDBColumnInfo;
out ppStringsBuffer: PWideChar): HResult; stdcall;
function MapColumnIDs(cColumnIDs: PtrUInt; rgColumnIDs: PDBIDArray;
rgColumns: PPtrUIntArray): HResult; stdcall;
end;
/// allows the display of the data link dialog boxes programmatically
IDBPromptInitialize = interface(IUnknown)
['{2206CCB0-19C1-11D1-89E0-00C04FD7A829}']
function PromptDataSource(const pUnkOuter: IUnknown; hWndParent: HWND;
dwPromptOptions: UINT; cSourceTypeFilter: ULONG;
rgSourceTypeFilter: PDBSOURCETYPE; pszProviderFilter: POleStr;
const riid: TIID; var DataSource: IUnknown): HResult; stdcall;
function PromptFileName(hWndParent: HWND; dwPromptOptions: UINT;
pwszInitialDirectory, pwszInitialFile: POleStr;
var ppwszSelectedFile: POleStr): HResult; stdcall;
end;
/// used to retrieve the database metadata (e.g. tables and fields layout)
IDBSchemaRowset = interface(IUnknown)
['{0c733a7b-2a1c-11ce-ade5-00aa0044773d}']
function GetRowset(pUnkOuter: IUnknown; const rguidSchema: TGUID;
cRestrictions: Integer; rgRestrictions: pointer;
const riid: TIID; cPropertySets: Integer; rgPropertySets: PDBPROPSET;
var ppRowset: IRowset): HResult; stdcall;
function GetSchemas(var pcSchemas: Integer; var prgSchemas: PGUID;
var prgRestrictionSupport: PInteger): HResult; stdcall;
end;
{ -------------- TOleDB* OleDB classes and types }
type
/// generic Exception type, generated for OleDB connection
EOleDBException = class(ESQLDBException);
TOleDBConnection = class;
TOleDBOnCustomError = function(Connection: TOleDBConnection;
ErrorRecords: IErrorRecords; RecordNum: UINT): boolean of object;
/// will implement properties shared by OleDB connections
TOleDBConnectionProperties = class(TSQLDBConnectionPropertiesThreadSafe)
protected
fProviderName: RawUTF8;
fConnectionString: SynUnicode;
fOnCustomError: TOleDBOnCustomError;
fSchemaRec: array of TDBSchemaRec;
fSupportsOnlyIRowset: boolean;
function GetSchema(const aUID: TGUID; const Fields: array of RawUTF8;
var aResult: IRowSet): boolean;
/// will create the generic fConnectionString from supplied parameters
procedure SetInternalProperties; override;
/// initialize fForeignKeys content with all foreign keys of this DB
// - used by GetForeignKey method
procedure GetForeignKeys; override;
/// create the database
// - shall be called only if necessary (e.g. for file-based database, if
// the file does not exist yet)
function CreateDatabase: boolean; virtual;
public
/// create a new connection
// - call this method if the shared MainConnection is not enough (e.g. for
// multi-thread access)
// - the caller is responsible of freeing this instance
// - this overridden method will create an TOleDBConnection instance
function NewConnection: TSQLDBConnection; override;
/// display the OleDB/ADO Connection Settings dialog to customize the
// OleDB connection string
// - returns TRUE if the connection string has been modified
// - Parent is an optional GDI Window Handle for modal display
function ConnectionStringDialogExecute(Parent: HWND=0): boolean;
/// get all table names
// - will retrieve the corresponding metadata from OleDB interfaces if SQL
// direct access was not defined
procedure GetTableNames(out Tables: TRawUTF8DynArray); override;
/// retrieve the column/field layout of a specified table
// - will retrieve the corresponding metadata from OleDB interfaces if SQL
// direct access was not defined
procedure GetFields(const aTableName: RawUTF8; out Fields: TSQLDBColumnDefineDynArray); override;
/// convert a textual column data type, as retrieved e.g. from SQLGetField,
// into our internal primitive types
function ColumnTypeNativeToDB(const aNativeType: RawUTF8; aScale: integer): TSQLDBFieldType; override;
/// the associated OleDB connection string
// - is set by the Create() constructor most of the time from the supplied
// server name, user id and password, according to the database provider
// corresponding to the class
// - you may want to customize it via the ConnectionStringDialogExecute
// method, or to provide some additional parameters
property ConnectionString: SynUnicode read fConnectionString write fConnectionString;
/// custom Error handler for OleDB COM objects
// - returns TRUE if specific error was retrieved and has updated
// ErrorMessage and InfoMessage
// - default implementation just returns false
property OnCustomError: TOleDBOnCustomError read fOnCustomError write fOnCustomError;
published { to be loggged as JSON }
/// the associated OleDB provider name, as set for each class
property ProviderName: RawUTF8 read fProviderName;
end;
/// OleDB connection properties to an Oracle database using Oracle's Provider
// - this will use the native OleDB provider supplied by Oracle
// see @http://download.oracle.com/docs/cd/E11882_01/win.112/e17726/toc.htm
TOleDBOracleConnectionProperties = class(TOleDBConnectionProperties)
protected
/// will set the appropriate provider name, i.e. 'OraOLEDB.Oracle.1'
procedure SetInternalProperties; override;
end;
/// OleDB connection properties to an Oracle database using Microsoft's Provider
// - this will use the generic (older) OleDB provider supplied by Microsoft
// which would not be used any more:
// "This feature will be removed in a future version of Windows. Avoid
// using this feature in new development work, and plan to modify applications
// that currently use this feature. Instead, use Oracle's OLE DB provider."
// see http://msdn.microsoft.com/en-us/library/ms675851
TOleDBMSOracleConnectionProperties = class(TOleDBOracleConnectionProperties)
protected
/// will set the appropriate provider name, i.e. 'MSDAORA'
procedure SetInternalProperties; override;
end;
/// OleDB connection properties to Microsoft SQL Server 2008-2012, via
// SQL Server Native Client 10.0 (SQL Server 2008)
// - this will use the native OleDB provider supplied by Microsoft
// see http://msdn.microsoft.com/en-us/library/ms677227
// - is aUserID='' at Create, it will use Windows Integrated Security
// for the connection
// - will use the SQLNCLI10 provider, which will work on Windows XP;
// if you want all features, especially under MS SQL 2012, use the
// inherited class TOleDBMSSQL2012ConnectionProperties; if, on the other
// hand, you need to connect to a old MS SQL Server 2005, use
// TOleDBMSSQL2005ConnectionProperties, or set your own provider string
TOleDBMSSQLConnectionProperties = class(TOleDBConnectionProperties)
protected
/// will set the appropriate provider name, i.e. 'SQLNCLI10'
procedure SetInternalProperties; override;
/// custom Error handler for OleDB COM objects
// - will handle Microsoft SQL Server error messages (if any)
function MSOnCustomError(Connection: TOleDBConnection;
ErrorRecords: IErrorRecords; RecordNum: UINT): boolean;
public
end;
/// OleDB connection properties to Microsoft SQL Server 2005, via
// SQL Server Native Client (SQL Server 2005)
// - this overridden version will use the SQLNCLI provider, which is
// deprecated but may be an alternative with MS SQL Server 2005
// - is aUserID='' at Create, it will use Windows Integrated Security
// for the connection
TOleDBMSSQL2005ConnectionProperties = class(TOleDBMSSQLConnectionProperties)
protected
/// will set the appropriate provider name, i.e. 'SQLNCLI'
procedure SetInternalProperties; override;
public
/// initialize the connection properties
// - this overridden version will disable the MultipleValuesInsert()
// optimization as defined in TSQLDBConnectionProperties.Create(),
// since INSERT with multiple VALUES (..),(..),(..) is available only
// since SQL Server 2008
constructor Create(const aServerName, aDatabaseName, aUserID, aPassWord: RawUTF8); override;
end;
/// OleDB connection properties to Microsoft SQL Server 2008, via
// SQL Server Native Client 10.0 (SQL Server 2008)
// - just maps default TOleDBMSSQLConnectionProperties type
TOleDBMSSQL2008ConnectionProperties = TOleDBMSSQLConnectionProperties;
/// OleDB connection properties to Microsoft SQL Server 2008/2012, via
// SQL Server Native Client 11.0 (Microsoft SQL Server 2012 Native Client)
// - from http://www.microsoft.com/en-us/download/details.aspx?id=29065 get
// the sqlncli.msi package corresponding to your Operating System: note that
// the "X64 Package" will also install the 32-bit version of the client
// - this overridden version will use newer SQLNCLI11 provider, but won't work
// under Windows XP - in this case, it will fall back to SQLNCLI10 - see
// http://msdn.microsoft.com/en-us/library/ms131291
// - if aUserID='' at Create, it will use Windows Integrated Security
// for the connection
// - for SQL Express LocalDB edition, just use aServerName='(localdb)\v11.0'
TOleDBMSSQL2012ConnectionProperties = class(TOleDBMSSQLConnectionProperties)
protected
/// will set the appropriate provider name, i.e. 'SQLNCLI11'
// - will leave older 'SQLNCLI10' on Windows XP
procedure SetInternalProperties; override;
end;
/// OleDB connection properties to MySQL Server
TOleDBMySQLConnectionProperties = class(TOleDBConnectionProperties)
protected
/// will set the appropriate provider name, i.e. 'MySQLProv'
procedure SetInternalProperties; override;
end;
{$ifndef CPU64} // Jet is not available on Win64
/// OleDB connection properties to Jet/MSAccess .mdb files
// - the server name should be the .mdb file name
// - note that the Jet OleDB driver is not available under Win64 platform
TOleDBJetConnectionProperties = class(TOleDBConnectionProperties)
protected
/// will set the appropriate provider name, i.e. 'Microsoft.Jet.OLEDB.4.0'
procedure SetInternalProperties; override;
end;
{$endif}
/// OleDB connection properties to IBM AS/400
TOleDBAS400ConnectionProperties = class(TOleDBConnectionProperties)
protected
/// will set the appropriate provider name, i.e. 'IBMDA400.DataSource.1'
procedure SetInternalProperties; override;
end;
/// OleDB connection properties to Informix Server
TOleDBInformixConnectionProperties = class(TOleDBConnectionProperties)
protected
/// will set the appropriate provider name, i.e. 'Ifxoledbc'
procedure SetInternalProperties; override;
end;
/// OleDB connection properties via Microsoft Provider for ODBC
// - this will use the ODBC provider supplied by Microsoft
// see http://msdn.microsoft.com/en-us/library/ms675326(v=VS.85).aspx
// - an ODBC Driver should be specified at creation
// - you should better use direct connection classes, like
// TOleDBMSSQLConnectionProperties or TOleDBOracleConnectionProperties
// as defined in SynDBODBC.pas
TOleDBODBCSQLConnectionProperties = class(TOleDBConnectionProperties)
protected
fDriver: RawUTF8;
/// will set the appropriate provider name, i.e. 'MSDASQL'
procedure SetInternalProperties; override;
public
/// initialize the properties
// - an additional parameter is available to set the ODBC driver to use
// - you may also set aDriver='' and modify the connection string directly,
// e.g. adding '{ DSN=name | FileDSN=filename };'
constructor Create(const aDriver, aServerName, aDatabaseName,
aUserID, aPassWord: RawUTF8); reintroduce;
published { to be logged as JSON }
/// the associated ODBC Driver name, as specified at creation
property Driver: RawUTF8 read fDriver;
end;
/// implements an OleDB connection
// - will retrieve the remote DataBase behavior from a supplied
// TSQLDBConnectionProperties class, shared among connections
TOleDBConnection = class(TSQLDBConnectionThreadSafe)
protected
fMalloc: IMalloc;
fDBInitialize: IDBInitialize;
fTransaction: ITransactionLocal;
fSession: IUnknown;
fOleDBProperties: TOleDBConnectionProperties;
fOleDBErrorMessage, fOleDBInfoMessage: string;
/// Error handler for OleDB COM objects
// - will update ErrorMessage and InfoMessage
procedure OleDBCheck(aStmt: TSQLDBStatement; aResult: HRESULT;
const aStatus: TCardinalDynArray=nil); virtual;
/// called just after fDBInitialize.Initialized: could add parameters
procedure OnDBInitialized; virtual;
public
/// connect to a specified OleDB database
constructor Create(aProperties: TSQLDBConnectionProperties); override;
/// release all associated memory and OleDB COM objects
destructor Destroy; override;
/// initialize a new SQL query statement for the given connection
// - the caller should free the instance after use
function NewStatement: TSQLDBStatement; override;
/// connect to the specified database
// - should raise an EOleDBException on error
procedure Connect; override;
/// stop connection to the specified database
// - should raise an EOleDBException on error
procedure Disconnect; override;
/// return TRUE if Connect has been already successfully called
function IsConnected: boolean; override;
/// begin a Transaction for this connection
// - be aware that not all OleDB provider support nested transactions
// see http://msdn.microsoft.com/en-us/library/ms716985(v=vs.85).aspx
procedure StartTransaction; override;
/// commit changes of a Transaction for this connection
// - StartTransaction method must have been called before
procedure Commit; override;
/// discard changes of a Transaction for this connection
// - StartTransaction method must have been called before
procedure Rollback; override;
/// the associated OleDB database properties
property OleDBProperties: TOleDBConnectionProperties read fOleDBProperties;
/// internal error message, as retrieved from the OleDB provider
property OleDBErrorMessage: string read fOleDBErrorMessage;
/// internal information message, as retrieved from the OleDB provider
property OleDBInfoMessage: string read fOleDBInfoMessage;
end;
/// used to store properties and value about one TOleDBStatement Param
// - we don't use a Variant, not the standard TSQLDBParam record type,
// but manual storage for better performance
// - whole memory block of a TOleDBStatementParamDynArray will be used as the
// source Data for the OleDB parameters - so we should align data carefully
TOleDBStatementParam = packed record
/// storage used for BLOB (ftBlob) values
// - will be refered as DBTYPE_BYREF when sent as OleDB parameters, to
// avoid unnecessary memory copy
VBlob: RawByteString;
/// storage used for TEXT (ftUTF8) values
// - we store TEXT here as WideString, and not RawUTF8, since OleDB
// expects the text to be provided with Unicode encoding
// - for some providers (like Microsoft SQL Server 2008 R2, AFAIK), using
// DBTYPE_WSTR value (i.e. what the doc. says) will raise an OLEDB Error
// 80040E1D (DB_E_UNSUPPORTEDCONVERSION, i.e. 'Requested conversion is not
// supported'): we found out that only DBTYPE_BSTR type (i.e. OLE WideString)
// does work... so we'll use it here! Shame on Microsoft!
// - what's fine with DBTYPE_BSTR is that it can be resized by the provider
// in case of VInOut in [paramOut, paramInOut] - so let it be
VText: WideString;
/// storage used for ftInt64, ftDouble, ftDate and ftCurrency value
VInt64: Int64;
/// storage used for table variables
VIUnknown: IUnknown;
/// storage used for table variables
VArray: TRawUTF8DynArray;
/// storage used for the OleDB status field
// - if VStatus=ord(stIsNull), then it will bind a NULL with the type
// as set by VType (to avoid conversion error like in [e8c211062e])
VStatus: integer;
/// the column/parameter Value type
VType: TSQLDBFieldType;
/// define if parameter can be retrieved after a stored procedure execution
VInOut: TSQLDBParamInOutType;
// so that VInt64 will be 8 bytes aligned
VFill: array[sizeof(TSQLDBFieldType)+sizeof(TSQLDBParamInOutType)+sizeof(integer)..
SizeOf(Int64)-1] of byte;
end;
POleDBStatementParam = ^TOleDBStatementParam;
/// used to store properties about TOleDBStatement Parameters
// - whole memory block of a TOleDBStatementParamDynArray will be used as the
// source Data for the OleDB parameters
TOleDBStatementParamDynArray = array of TOleDBStatementParam;
/// implements an OleDB SQL query statement
// - this statement won't retrieve all rows of data, but will allow direct
// per-row access using the Step() and Column*() methods
TOleDBStatement = class(TSQLDBStatement)
protected
fParams: TOleDBStatementParamDynArray;
fColumns: TSQLDBColumnPropertyDynArray;
fParam: TDynArray;
fColumn: TDynArrayHashed;
fCommand: ICommandText;
fRowSet: IRowSet;
fRowSetAccessor: HACCESSOR;
fRowSize: integer;
fRowStepResult: HRESULT;
fRowStepHandleRetrieved: PtrUInt;
fRowStepHandleCurrent: PtrUInt;
fRowStepHandles: TPtrUIntDynArray;
fRowSetData: array of byte;
fParamBindings: TDBBindingDynArray;
fColumnBindings: TDBBindingDynArray;
fHasColumnValueInlined: boolean;
fOleDBConnection: TOleDBConnection;
fDBParams: TDBParams;
fRowBufferSize: integer;
fUpdateCount: integer;
fAlignBuffer: boolean;
procedure SetRowBufferSize(Value: integer);
/// resize fParams[] if necessary, set the VType and return pointer to
// the corresponding entry in fParams[]
// - first parameter has Param=1
function CheckParam(Param: Integer; NewType: TSQLDBFieldType;
IO: TSQLDBParamInOutType): POleDBStatementParam; overload;
function CheckParam(Param: Integer; NewType: TSQLDBFieldType;
IO: TSQLDBParamInOutType; ArrayCount: integer): POleDBStatementParam; overload;
/// raise an exception if Col is incorrect or no IRowSet is available
// - set Column to the corresponding fColumns[] item
// - return a pointer to status-data[-length] in fRowSetData[], or