-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQLiteConnection.cs
executable file
·6963 lines (6150 loc) · 248 KB
/
SQLiteConnection.cs
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
/********************************************************
* ADO.NET 2.0 Data Provider for SQLite Version 3.X
* Written by Robert Simpson ([email protected])
*
* Released to the public domain, use at your own risk!
********************************************************/
namespace System.Data.SQLite
{
using System;
using System.Data;
using System.Data.Common;
using System.Diagnostics;
using System.Collections.Generic;
using System.Globalization;
using System.ComponentModel;
using System.Reflection;
using System.Runtime.InteropServices;
using System.IO;
using System.Text;
/////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// This class represents a single value to be returned
/// from the <see cref="SQLiteDataReader" /> class via
/// its <see cref="SQLiteDataReader.GetBlob" />,
/// <see cref="SQLiteDataReader.GetBoolean" />,
/// <see cref="SQLiteDataReader.GetByte" />,
/// <see cref="SQLiteDataReader.GetBytes" />,
/// <see cref="SQLiteDataReader.GetChar" />,
/// <see cref="SQLiteDataReader.GetChars" />,
/// <see cref="SQLiteDataReader.GetDateTime" />,
/// <see cref="SQLiteDataReader.GetDecimal" />,
/// <see cref="SQLiteDataReader.GetDouble" />,
/// <see cref="SQLiteDataReader.GetFloat" />,
/// <see cref="SQLiteDataReader.GetGuid" />,
/// <see cref="SQLiteDataReader.GetInt16" />,
/// <see cref="SQLiteDataReader.GetInt32" />,
/// <see cref="SQLiteDataReader.GetInt64" />,
/// <see cref="SQLiteDataReader.GetString" />, or
/// <see cref="SQLiteDataReader.GetValue" /> method. If the value of the
/// associated public field of this class is null upon returning from the
/// callback, the null value will only be used if the return type for the
/// <see cref="SQLiteDataReader" /> method called is not a value type.
/// If the value to be returned from the <see cref="SQLiteDataReader" />
/// method is unsuitable (e.g. null with a value type), an exception will
/// be thrown.
/// </summary>
public sealed class SQLiteDataReaderValue
{
/// <summary>
/// The value to be returned from the
/// <see cref="SQLiteDataReader.GetBlob" /> method -OR- null to
/// indicate an error.
/// </summary>
public SQLiteBlob BlobValue;
/// <summary>
/// The value to be returned from the
/// <see cref="SQLiteDataReader.GetBoolean" /> method -OR- null to
/// indicate an error.
/// </summary>
public bool? BooleanValue;
/// <summary>
/// The value to be returned from the
/// <see cref="SQLiteDataReader.GetByte" /> method -OR- null to
/// indicate an error.
/// </summary>
public byte? ByteValue;
/// <summary>
/// The value to be returned from the
/// <see cref="SQLiteDataReader.GetBytes" /> method.
/// </summary>
public byte[] BytesValue;
/// <summary>
/// The value to be returned from the
/// <see cref="SQLiteDataReader.GetChar" /> method -OR- null to
/// indicate an error.
/// </summary>
public char? CharValue;
/// <summary>
/// The value to be returned from the
/// <see cref="SQLiteDataReader.GetChars" /> method.
/// </summary>
public char[] CharsValue;
/// <summary>
/// The value to be returned from the
/// <see cref="SQLiteDataReader.GetDateTime" /> method -OR- null to
/// indicate an error.
/// </summary>
public DateTime? DateTimeValue;
/// <summary>
/// The value to be returned from the
/// <see cref="SQLiteDataReader.GetDecimal" /> method -OR- null to
/// indicate an error.
/// </summary>
public decimal? DecimalValue;
/// <summary>
/// The value to be returned from the
/// <see cref="SQLiteDataReader.GetDouble" /> method -OR- null to
/// indicate an error.
/// </summary>
public double? DoubleValue;
/// <summary>
/// The value to be returned from the
/// <see cref="SQLiteDataReader.GetFloat" /> method -OR- null to
/// indicate an error.
/// </summary>
public float? FloatValue;
/// <summary>
/// The value to be returned from the
/// <see cref="SQLiteDataReader.GetGuid" /> method -OR- null to
/// indicate an error.
/// </summary>
public Guid? GuidValue;
/// <summary>
/// The value to be returned from the
/// <see cref="SQLiteDataReader.GetInt16" /> method -OR- null to
/// indicate an error.
/// </summary>
public short? Int16Value;
/// <summary>
/// The value to be returned from the
/// <see cref="SQLiteDataReader.GetInt32" /> method -OR- null to
/// indicate an error.
/// </summary>
public int? Int32Value;
/// <summary>
/// The value to be returned from the
/// <see cref="SQLiteDataReader.GetInt64" /> method -OR- null to
/// indicate an error.
/// </summary>
public long? Int64Value;
/// <summary>
/// The value to be returned from the
/// <see cref="SQLiteDataReader.GetString" /> method.
/// </summary>
public string StringValue;
/// <summary>
/// The value to be returned from the
/// <see cref="SQLiteDataReader.GetValue" /> method.
/// </summary>
public object Value;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// This class represents the parameters that are provided
/// to the <see cref="SQLiteDataReader" /> methods, with
/// the exception of the column index (provided separately).
/// </summary>
public abstract class SQLiteReadEventArgs : EventArgs
{
// nothing.
}
/////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// This class represents the parameters that are provided to
/// the <see cref="SQLiteDataReader.GetBlob" /> method, with
/// the exception of the column index (provided separately).
/// </summary>
public class SQLiteReadBlobEventArgs : SQLiteReadEventArgs
{
#region Private Data
/// <summary>
/// Provides the underlying storage for the
/// <see cref="ReadOnly" /> property.
/// </summary>
private bool readOnly;
#endregion
/////////////////////////////////////////////////////////////////////////
#region Private Constructors
/// <summary>
/// Constructs an instance of this class to pass into a user-defined
/// callback associated with the <see cref="SQLiteDataReader.GetBlob" />
/// method.
/// </summary>
/// <param name="readOnly">
/// The value that was originally specified for the "readOnly"
/// parameter to the <see cref="SQLiteDataReader.GetBlob" /> method.
/// </param>
internal SQLiteReadBlobEventArgs(
bool readOnly
)
{
this.readOnly = readOnly;
}
#endregion
/////////////////////////////////////////////////////////////////////////
#region Public Properties
/// <summary>
/// The value that was originally specified for the "readOnly"
/// parameter to the <see cref="SQLiteDataReader.GetBlob" /> method.
/// </summary>
public bool ReadOnly
{
get { return readOnly; }
set { readOnly = value; }
}
#endregion
}
/////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// This class represents the parameters that are provided
/// to the <see cref="SQLiteDataReader.GetBytes" /> and
/// <see cref="SQLiteDataReader.GetChars" /> methods, with
/// the exception of the column index (provided separately).
/// </summary>
public class SQLiteReadArrayEventArgs : SQLiteReadEventArgs
{
#region Private Data
/// <summary>
/// Provides the underlying storage for the
/// <see cref="DataOffset" /> property.
/// </summary>
private long dataOffset;
/// <summary>
/// Provides the underlying storage for the
/// <see cref="ByteBuffer" /> property.
/// </summary>
private byte[] byteBuffer;
/// <summary>
/// Provides the underlying storage for the
/// <see cref="CharBuffer" /> property.
/// </summary>
private char[] charBuffer;
/// <summary>
/// Provides the underlying storage for the
/// <see cref="BufferOffset" /> property.
/// </summary>
private int bufferOffset;
/// <summary>
/// Provides the underlying storage for the
/// <see cref="Length" /> property.
/// </summary>
private int length;
#endregion
/////////////////////////////////////////////////////////////////////////
#region Private Constructors
/// <summary>
/// Constructs an instance of this class to pass into a user-defined
/// callback associated with the <see cref="SQLiteDataReader.GetBytes" />
/// method.
/// </summary>
/// <param name="dataOffset">
/// The value that was originally specified for the "dataOffset"
/// parameter to the <see cref="SQLiteDataReader.GetBytes" /> or
/// <see cref="SQLiteDataReader.GetChars" /> methods.
/// </param>
/// <param name="byteBuffer">
/// The value that was originally specified for the "buffer"
/// parameter to the <see cref="SQLiteDataReader.GetBytes" />
/// method.
/// </param>
/// <param name="bufferOffset">
/// The value that was originally specified for the "bufferOffset"
/// parameter to the <see cref="SQLiteDataReader.GetBytes" /> or
/// <see cref="SQLiteDataReader.GetChars" /> methods.
/// </param>
/// <param name="length">
/// The value that was originally specified for the "length"
/// parameter to the <see cref="SQLiteDataReader.GetBytes" /> or
/// <see cref="SQLiteDataReader.GetChars" /> methods.
/// </param>
internal SQLiteReadArrayEventArgs(
long dataOffset,
byte[] byteBuffer,
int bufferOffset,
int length
)
{
this.dataOffset = dataOffset;
this.byteBuffer = byteBuffer;
this.bufferOffset = bufferOffset;
this.length = length;
}
/////////////////////////////////////////////////////////////////////////
/// <summary>
/// Constructs an instance of this class to pass into a user-defined
/// callback associated with the <see cref="SQLiteDataReader.GetChars" />
/// method.
/// </summary>
/// <param name="dataOffset">
/// The value that was originally specified for the "dataOffset"
/// parameter to the <see cref="SQLiteDataReader.GetBytes" /> or
/// <see cref="SQLiteDataReader.GetChars" /> methods.
/// </param>
/// <param name="charBuffer">
/// The value that was originally specified for the "buffer"
/// parameter to the <see cref="SQLiteDataReader.GetChars" />
/// method.
/// </param>
/// <param name="bufferOffset">
/// The value that was originally specified for the "bufferOffset"
/// parameter to the <see cref="SQLiteDataReader.GetBytes" /> or
/// <see cref="SQLiteDataReader.GetChars" /> methods.
/// </param>
/// <param name="length">
/// The value that was originally specified for the "length"
/// parameter to the <see cref="SQLiteDataReader.GetBytes" /> or
/// <see cref="SQLiteDataReader.GetChars" /> methods.
/// </param>
internal SQLiteReadArrayEventArgs(
long dataOffset,
char[] charBuffer,
int bufferOffset,
int length
)
{
this.dataOffset = dataOffset;
this.charBuffer = charBuffer;
this.bufferOffset = bufferOffset;
this.length = length;
}
#endregion
/////////////////////////////////////////////////////////////////////////
#region Public Properties
/// <summary>
/// The value that was originally specified for the "dataOffset"
/// parameter to the <see cref="SQLiteDataReader.GetBytes" /> or
/// <see cref="SQLiteDataReader.GetChars" /> methods.
/// </summary>
public long DataOffset
{
get { return dataOffset; }
set { dataOffset = value; }
}
/////////////////////////////////////////////////////////////////////////
/// <summary>
/// The value that was originally specified for the "buffer"
/// parameter to the <see cref="SQLiteDataReader.GetBytes" />
/// method.
/// </summary>
public byte[] ByteBuffer
{
get { return byteBuffer; }
}
/////////////////////////////////////////////////////////////////////////
/// <summary>
/// The value that was originally specified for the "buffer"
/// parameter to the <see cref="SQLiteDataReader.GetChars" />
/// method.
/// </summary>
public char[] CharBuffer
{
get { return charBuffer; }
}
/////////////////////////////////////////////////////////////////////////
/// <summary>
/// The value that was originally specified for the "bufferOffset"
/// parameter to the <see cref="SQLiteDataReader.GetBytes" /> or
/// <see cref="SQLiteDataReader.GetChars" /> methods.
/// </summary>
public int BufferOffset
{
get { return bufferOffset; }
set { bufferOffset = value; }
}
/////////////////////////////////////////////////////////////////////////
/// <summary>
/// The value that was originally specified for the "length"
/// parameter to the <see cref="SQLiteDataReader.GetBytes" /> or
/// <see cref="SQLiteDataReader.GetChars" /> methods.
/// </summary>
public int Length
{
get { return length; }
set { length = value; }
}
#endregion
}
/////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// This class represents the parameters and return values for the
/// <see cref="SQLiteDataReader.GetBlob" />,
/// <see cref="SQLiteDataReader.GetBoolean" />,
/// <see cref="SQLiteDataReader.GetByte" />,
/// <see cref="SQLiteDataReader.GetBytes" />,
/// <see cref="SQLiteDataReader.GetChar" />,
/// <see cref="SQLiteDataReader.GetChars" />,
/// <see cref="SQLiteDataReader.GetDateTime" />,
/// <see cref="SQLiteDataReader.GetDecimal" />,
/// <see cref="SQLiteDataReader.GetDouble" />,
/// <see cref="SQLiteDataReader.GetFloat" />,
/// <see cref="SQLiteDataReader.GetGuid" />,
/// <see cref="SQLiteDataReader.GetInt16" />,
/// <see cref="SQLiteDataReader.GetInt32" />,
/// <see cref="SQLiteDataReader.GetInt64" />,
/// <see cref="SQLiteDataReader.GetString" />, and
/// <see cref="SQLiteDataReader.GetValue" /> methods.
/// </summary>
public class SQLiteReadValueEventArgs : SQLiteReadEventArgs
{
#region Private Data
/// <summary>
/// Provides the underlying storage for the
/// <see cref="MethodName" /> property.
/// </summary>
private string methodName;
/// <summary>
/// Provides the underlying storage for the
/// <see cref="ExtraEventArgs" /> property.
/// </summary>
private SQLiteReadEventArgs extraEventArgs;
/// <summary>
/// Provides the underlying storage for the
/// <see cref="Value" /> property.
/// </summary>
private SQLiteDataReaderValue value;
#endregion
/////////////////////////////////////////////////////////////////////////
#region Private Constructors
/// <summary>
/// Constructs a new instance of this class. Depending on the method
/// being called, the <paramref name="extraEventArgs" /> and/or
/// <paramref name="value" /> parameters may be null.
/// </summary>
/// <param name="methodName">
/// The name of the <see cref="SQLiteDataReader" /> method that was
/// responsible for invoking this callback.
/// </param>
/// <param name="extraEventArgs">
/// If the <see cref="SQLiteDataReader.GetBytes" /> or
/// <see cref="SQLiteDataReader.GetChars" /> method is being called,
/// this object will contain the array related parameters for that
/// method. If the <see cref="SQLiteDataReader.GetBlob" /> method is
/// being called, this object will contain the blob related parameters
/// for that method.
/// </param>
/// <param name="value">
/// This may be used by the callback to set the return value for the
/// called <see cref="SQLiteDataReader" /> method.
/// </param>
internal SQLiteReadValueEventArgs(
string methodName,
SQLiteReadEventArgs extraEventArgs,
SQLiteDataReaderValue value
)
{
this.methodName = methodName;
this.extraEventArgs = extraEventArgs;
this.value = value;
}
#endregion
/////////////////////////////////////////////////////////////////////////
#region Public Properties
/// <summary>
/// The name of the <see cref="SQLiteDataReader" /> method that was
/// responsible for invoking this callback.
/// </summary>
public string MethodName
{
get { return methodName; }
}
/////////////////////////////////////////////////////////////////////////
/// <summary>
/// If the <see cref="SQLiteDataReader.GetBytes" /> or
/// <see cref="SQLiteDataReader.GetChars" /> method is being called,
/// this object will contain the array related parameters for that
/// method. If the <see cref="SQLiteDataReader.GetBlob" /> method is
/// being called, this object will contain the blob related parameters
/// for that method.
/// </summary>
public SQLiteReadEventArgs ExtraEventArgs
{
get { return extraEventArgs; }
}
/////////////////////////////////////////////////////////////////////////
/// <summary>
/// This may be used by the callback to set the return value for the
/// called <see cref="SQLiteDataReader" /> method.
/// </summary>
public SQLiteDataReaderValue Value
{
get { return value; }
}
#endregion
}
/////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// This represents a method that will be called in response to a request to
/// bind a parameter to a command. If an exception is thrown, it will cause
/// the parameter binding operation to fail -AND- it will continue to unwind
/// the call stack.
/// </summary>
/// <param name="convert">
/// The <see cref="SQLiteConvert" /> instance in use.
/// </param>
/// <param name="command">
/// The <see cref="SQLiteCommand" /> instance in use.
/// </param>
/// <param name="flags">
/// The flags associated with the <see cref="SQLiteConnection" /> instance
/// in use.
/// </param>
/// <param name="parameter">
/// The <see cref="SQLiteParameter" /> instance being bound to the command.
/// </param>
/// <param name="typeName">
/// The database type name associated with this callback.
/// </param>
/// <param name="index">
/// The ordinal of the parameter being bound to the command.
/// </param>
/// <param name="userData">
/// The data originally used when registering this callback.
/// </param>
/// <param name="complete">
/// Non-zero if the default handling for the parameter binding call should
/// be skipped (i.e. the parameter should not be bound at all). Great care
/// should be used when setting this to non-zero.
/// </param>
public delegate void SQLiteBindValueCallback(
SQLiteConvert convert,
SQLiteCommand command,
SQLiteConnectionFlags flags,
SQLiteParameter parameter,
string typeName,
int index,
object userData,
out bool complete
);
/////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// This represents a method that will be called in response to a request
/// to read a value from a data reader. If an exception is thrown, it will
/// cause the data reader operation to fail -AND- it will continue to unwind
/// the call stack.
/// </summary>
/// <param name="convert">
/// The <see cref="SQLiteConvert" /> instance in use.
/// </param>
/// <param name="dataReader">
/// The <see cref="SQLiteDataReader" /> instance in use.
/// </param>
/// <param name="flags">
/// The flags associated with the <see cref="SQLiteConnection" /> instance
/// in use.
/// </param>
/// <param name="eventArgs">
/// The parameter and return type data for the column being read from the
/// data reader.
/// </param>
/// <param name="typeName">
/// The database type name associated with this callback.
/// </param>
/// <param name="index">
/// The zero based index of the column being read from the data reader.
/// </param>
/// <param name="userData">
/// The data originally used when registering this callback.
/// </param>
/// <param name="complete">
/// Non-zero if the default handling for the data reader call should be
/// skipped. If this is set to non-zero and the necessary return value
/// is unavailable or unsuitable, an exception will be thrown.
/// </param>
public delegate void SQLiteReadValueCallback(
SQLiteConvert convert,
SQLiteDataReader dataReader,
SQLiteConnectionFlags flags,
SQLiteReadEventArgs eventArgs,
string typeName,
int index,
object userData,
out bool complete
);
/////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// This class represents the custom data type handling callbacks
/// for a single type name.
/// </summary>
public sealed class SQLiteTypeCallbacks
{
#region Private Data
/// <summary>
/// Provides the underlying storage for the
/// <see cref="TypeName" /> property.
/// </summary>
private string typeName;
/// <summary>
/// Provides the underlying storage for the
/// <see cref="BindValueCallback" /> property.
/// </summary>
private SQLiteBindValueCallback bindValueCallback;
/// <summary>
/// Provides the underlying storage for the
/// <see cref="ReadValueCallback" /> property.
/// </summary>
private SQLiteReadValueCallback readValueCallback;
/// <summary>
/// Provides the underlying storage for the
/// <see cref="BindValueUserData" /> property.
/// </summary>
private object bindValueUserData;
/// <summary>
/// Provides the underlying storage for the
/// <see cref="ReadValueUserData" /> property.
/// </summary>
private object readValueUserData;
#endregion
/////////////////////////////////////////////////////////////////////////
#region Private Constructors
/// <summary>
/// Constructs an instance of this class.
/// </summary>
/// <param name="bindValueCallback">
/// The custom paramater binding callback. This parameter may be null.
/// </param>
/// <param name="readValueCallback">
/// The custom data reader value callback. This parameter may be null.
/// </param>
/// <param name="bindValueUserData">
/// The extra data to pass into the parameter binding callback. This
/// parameter may be null.
/// </param>
/// <param name="readValueUserData">
/// The extra data to pass into the data reader value callback. This
/// parameter may be null.
/// </param>
private SQLiteTypeCallbacks(
SQLiteBindValueCallback bindValueCallback,
SQLiteReadValueCallback readValueCallback,
object bindValueUserData,
object readValueUserData
)
{
this.bindValueCallback = bindValueCallback;
this.readValueCallback = readValueCallback;
this.bindValueUserData = bindValueUserData;
this.readValueUserData = readValueUserData;
}
#endregion
/////////////////////////////////////////////////////////////////////////
#region Static "Factory" Methods
/// <summary>
/// Creates an instance of the <see cref="SQLiteTypeCallbacks" /> class.
/// </summary>
/// <param name="bindValueCallback">
/// The custom paramater binding callback. This parameter may be null.
/// </param>
/// <param name="readValueCallback">
/// The custom data reader value callback. This parameter may be null.
/// </param>
/// <param name="bindValueUserData">
/// The extra data to pass into the parameter binding callback. This
/// parameter may be null.
/// </param>
/// <param name="readValueUserData">
/// The extra data to pass into the data reader value callback. This
/// parameter may be null.
/// </param>
public static SQLiteTypeCallbacks Create(
SQLiteBindValueCallback bindValueCallback,
SQLiteReadValueCallback readValueCallback,
object bindValueUserData,
object readValueUserData
)
{
return new SQLiteTypeCallbacks(
bindValueCallback, readValueCallback, bindValueUserData,
readValueUserData);
}
#endregion
/////////////////////////////////////////////////////////////////////////
#region Public Properties
/// <summary>
/// The database type name that the callbacks contained in this class
/// will apply to. This value may not be null.
/// </summary>
public string TypeName
{
get { return typeName; }
internal set { typeName = value; }
}
/////////////////////////////////////////////////////////////////////////
/// <summary>
/// The custom paramater binding callback. This value may be null.
/// </summary>
public SQLiteBindValueCallback BindValueCallback
{
get { return bindValueCallback; }
}
/////////////////////////////////////////////////////////////////////////
/// <summary>
/// The custom data reader value callback. This value may be null.
/// </summary>
public SQLiteReadValueCallback ReadValueCallback
{
get { return readValueCallback; }
}
/////////////////////////////////////////////////////////////////////////
/// <summary>
/// The extra data to pass into the parameter binding callback. This
/// value may be null.
/// </summary>
public object BindValueUserData
{
get { return bindValueUserData; }
}
/////////////////////////////////////////////////////////////////////////
/// <summary>
/// The extra data to pass into the data reader value callback. This
/// value may be null.
/// </summary>
public object ReadValueUserData
{
get { return readValueUserData; }
}
#endregion
}
/////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// This class represents the mappings between database type names
/// and their associated custom data type handling callbacks.
/// </summary>
internal sealed class SQLiteTypeCallbacksMap
: Dictionary<string, SQLiteTypeCallbacks>
{
/// <summary>
/// Constructs an (empty) instance of this class.
/// </summary>
public SQLiteTypeCallbacksMap()
: base(new TypeNameStringComparer())
{
// do nothing.
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Event data for connection event handlers.
/// </summary>
public class ConnectionEventArgs : EventArgs
{
/// <summary>
/// The type of event being raised.
/// </summary>
public readonly SQLiteConnectionEventType EventType;
/// <summary>
/// The <see cref="StateChangeEventArgs" /> associated with this event, if any.
/// </summary>
public readonly StateChangeEventArgs EventArgs;
/// <summary>
/// The transaction associated with this event, if any.
/// </summary>
public readonly IDbTransaction Transaction;
/// <summary>
/// The command associated with this event, if any.
/// </summary>
public readonly IDbCommand Command;
/// <summary>
/// The data reader associated with this event, if any.
/// </summary>
public readonly IDataReader DataReader;
/// <summary>
/// The critical handle associated with this event, if any.
/// </summary>
#if !PLATFORM_COMPACTFRAMEWORK
public readonly CriticalHandle CriticalHandle;
#else
public readonly object CriticalHandle;
#endif
/// <summary>
/// Command or message text associated with this event, if any.
/// </summary>
public readonly string Text;
/// <summary>
/// Extra data associated with this event, if any.
/// </summary>
public readonly object Data;
/// <summary>
/// Constructs the object.
/// </summary>
/// <param name="eventType">The type of event being raised.</param>
/// <param name="eventArgs">The base <see cref="EventArgs" /> associated
/// with this event, if any.</param>
/// <param name="transaction">The transaction associated with this event, if any.</param>
/// <param name="command">The command associated with this event, if any.</param>
/// <param name="dataReader">The data reader associated with this event, if any.</param>
/// <param name="criticalHandle">The critical handle associated with this event, if any.</param>
/// <param name="text">The command or message text, if any.</param>
/// <param name="data">The extra data, if any.</param>
internal ConnectionEventArgs(
SQLiteConnectionEventType eventType,
StateChangeEventArgs eventArgs,
IDbTransaction transaction,
IDbCommand command,
IDataReader dataReader,
#if !PLATFORM_COMPACTFRAMEWORK
CriticalHandle criticalHandle,
#else
object criticalHandle,
#endif
string text,
object data
)
{
EventType = eventType;
EventArgs = eventArgs;
Transaction = transaction;
Command = command;
DataReader = dataReader;
CriticalHandle = criticalHandle;
Text = text;
Data = data;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Raised when an event pertaining to a connection occurs.
/// </summary>
/// <param name="sender">The connection involved.</param>
/// <param name="e">Extra information about the event.</param>
public delegate void SQLiteConnectionEventHandler(object sender, ConnectionEventArgs e);
/////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// SQLite implentation of DbConnection.
/// </summary>
/// <remarks>
/// The <see cref="ConnectionString" /> property can contain the following parameter(s), delimited with a semi-colon:
/// <list type="table">
/// <listheader>
/// <term>Parameter</term>
/// <term>Values</term>
/// <term>Required</term>
/// <term>Default</term>
/// </listheader>
/// <item>
/// <description>Data Source</description>
/// <description>
/// This may be a file name, the string ":memory:", or any supported URI (starting with SQLite 3.7.7).
/// Starting with release 1.0.86.0, in order to use more than one consecutive backslash (e.g. for a
/// UNC path), each of the adjoining backslash characters must be doubled (e.g. "\\Network\Share\test.db"
/// would become "\\\\Network\Share\test.db").
/// </description>
/// <description>Y</description>
/// <description></description>
/// </item>
/// <item>
/// <description>Uri</description>
/// <description>
/// If specified, this must be a file name that starts with "file://", "file:", or "/". Any leading
/// "file://" or "file:" prefix will be stripped off and the resulting file name will be used to open
/// the database.
/// </description>
/// <description>N</description>
/// <description>null</description>
/// </item>
/// <item>
/// <description>FullUri</description>
/// <description>
/// If specified, this must be a URI in a format recognized by the SQLite core library (starting with
/// SQLite 3.7.7). It will be passed verbatim to the SQLite core library.
/// </description>
/// <description>N</description>
/// <description>null</description>
/// </item>
/// <item>
/// <description>Version</description>
/// <description>3</description>
/// <description>N</description>
/// <description>3</description>
/// </item>
/// <item>
/// <description>UseUTF16Encoding</description>
/// <description>
/// <b>True</b> - The UTF-16 encoding should be used.
/// <br/>
/// <b>False</b> - The UTF-8 encoding should be used.
/// </description>
/// <description>N</description>
/// <description>False</description>
/// </item>
/// <item>
/// <description>DefaultDbType</description>
/// <description>
/// This is the default <see cref="DbType" /> to use when one cannot be determined based on the
/// column metadata and the configured type mappings.
/// </description>
/// <description>N</description>
/// <description>null</description>
/// </item>
/// <item>
/// <description>DefaultTypeName</description>
/// <description>
/// This is the default type name to use when one cannot be determined based on the column metadata
/// and the configured type mappings.
/// </description>
/// <description>N</description>
/// <description>null</description>
/// </item>
/// <item>
/// <description>NoDefaultFlags</description>
/// <description>
/// <b>True</b> - Do not combine the specified (or existing) connection flags with the value of the
/// <see cref="DefaultFlags" /> property.
/// <br/>
/// <b>False</b> - Combine the specified (or existing) connection flags with the value of the
/// <see cref="DefaultFlags" /> property.
/// </description>
/// <description>N</description>
/// <description>False</description>
/// </item>
/// <item>
/// <description>NoSharedFlags</description>
/// <description>