System.Data.SQLite
Check-in [3ebf811b1e]
Not logged in

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

Overview
Comment:1.0.12 updates and cleanup
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sourceforge
Files: files | file ages | folders
SHA1: 3ebf811b1ef30a57de5620b0d68a91087b2a006e
User & Date: rmsimpson 2005-08-04 15:25:26
Context
2005-08-04
15:31
1.0.12 updates check-in: 06e6a2d985 user: rmsimpson tags: sourceforge
15:25
1.0.12 updates and cleanup check-in: 3ebf811b1e user: rmsimpson tags: sourceforge
2005-08-03
06:43
1.0.12 updates check-in: e269288997 user: rmsimpson tags: sourceforge
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Doc/SQLite.NET.Internal.ndoc.

1
2
3
4
5
6
7
8
9
10
<project SchemaVersion="1.3">
    <assemblies>
        <assembly location="..\bin\System.Data.SQLite.dll" documentation="..\bin\System.Data.SQLite.XML" />
    </assemblies>
    <documenters>
        <documenter name="JavaDoc">
            <property name="OutputDirectory" value=".\doc\" />
        </documenter>
        <documenter name="LaTeX">
            <property name="OutputDirectory" value=".\doc\" />


|







1
2
3
4
5
6
7
8
9
10
<project SchemaVersion="1.3">
    <assemblies>
        <assembly location="..\bin\System.Data.SQLite.dll" documentation=".\System.Data.SQLite.XML" />
    </assemblies>
    <documenters>
        <documenter name="JavaDoc">
            <property name="OutputDirectory" value=".\doc\" />
        </documenter>
        <documenter name="LaTeX">
            <property name="OutputDirectory" value=".\doc\" />

Changes to Doc/SQLite.NET.chm.

cannot compute difference between binary files

Changes to Doc/SQLite.NET.ndoc.

1
2
3
4
5
6
7
8
9
10
<project SchemaVersion="1.3">
    <assemblies>
        <assembly location="..\bin\System.Data.SQLite.dll" documentation="..\bin\System.Data.SQLite.XML" />
    </assemblies>
    <documenters>
        <documenter name="JavaDoc">
            <property name="OutputDirectory" value=".\doc\" />
        </documenter>
        <documenter name="LaTeX">
            <property name="OutputDirectory" value=".\doc\" />


|







1
2
3
4
5
6
7
8
9
10
<project SchemaVersion="1.3">
    <assemblies>
        <assembly location="..\bin\System.Data.SQLite.dll" documentation=".\System.Data.SQLite.XML" />
    </assemblies>
    <documenters>
        <documenter name="JavaDoc">
            <property name="OutputDirectory" value=".\doc\" />
        </documenter>
        <documenter name="LaTeX">
            <property name="OutputDirectory" value=".\doc\" />

Changes to Doc/ndoc.log.

23
24
25
26
27
28
29

30
31
32
33
34
35
36
..
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
...
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
...
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
...
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
System.Data.SQLite.SQLiteCommand.html
System.Data.SQLite.SQLiteCommandMembers.html
System.Data.SQLite.SQLiteCommandConstructor.html
System.Data.SQLite.SQLiteCommandConstructor1.html
System.Data.SQLite.SQLiteCommandConstructor2.html
System.Data.SQLite.SQLiteCommandConstructor3.html
System.Data.SQLite.SQLiteCommandConstructor4.html

System.Data.SQLite.SQLiteCommandProperties.html
System.Data.SQLite.SQLiteCommand.CommandText.html
System.Data.SQLite.SQLiteCommand.CommandTimeout.html
System.Data.SQLite.SQLiteCommand.CommandType.html
System.Data.SQLite.SQLiteCommand.DesignTimeVisible.html
System.Data.SQLite.SQLiteCommand.UpdatedRowSource.html
System.Data.SQLite.SQLiteCommandMethods.html
................................................................................
System.Data.SQLite.SQLiteConvert.ToDateTime.html
System.Data.SQLite.SQLiteConvert.ToString_overloads.html
System.Data.SQLite.SQLiteConvert.ToString_overload_2.html
System.Data.SQLite.SQLiteConvert.ToString_overload_1.html
System.Data.SQLite.SQLiteConvert.ToUTF8_overloads.html
System.Data.SQLite.SQLiteConvert.ToUTF8_overload_2.html
System.Data.SQLite.SQLiteConvert.ToUTF8_overload_1.html
System.Data.SQLite.SQLiteConvert.TryToDateTime.html
System.Data.SQLite.SQLiteDataAdapter.html
System.Data.SQLite.SQLiteDataAdapterMembers.html
System.Data.SQLite.SQLiteDataAdapterConstructor.html
System.Data.SQLite.SQLiteDataAdapterConstructor1.html
System.Data.SQLite.SQLiteDataAdapterConstructor2.html
System.Data.SQLite.SQLiteDataAdapterConstructor3.html
System.Data.SQLite.SQLiteDataAdapterConstructor4.html
................................................................................
System.Data.SQLite.SQLiteException.html
System.Data.SQLite.SQLiteExceptionMembers.html
System.Data.SQLite.SQLiteFactory.html
System.Data.SQLite.SQLiteFactoryMembers.html
System.Data.SQLite.SQLiteFactoryConstructor.html
System.Data.SQLite.SQLiteFactoryFields.html
System.Data.SQLite.SQLiteFactory.Instance.html
System.Data.SQLite.SQLiteFactoryProperties.html
System.Data.SQLite.SQLiteFactory.SupportedClasses.html
System.Data.SQLite.SQLiteFactoryMethods.html
System.Data.SQLite.SQLiteFactory.CreateCommand.html
System.Data.SQLite.SQLiteFactory.CreateCommandBuilder.html
System.Data.SQLite.SQLiteFactory.CreateConnection.html
System.Data.SQLite.SQLiteFactory.CreateConnectionStringBuilder.html
System.Data.SQLite.SQLiteFactory.CreateDataAdapter.html
System.Data.SQLite.SQLiteFactory.CreateParameter.html
................................................................................
System.Data.SQLite.SQLiteFunctionMethods.html
System.Data.SQLite.SQLiteFunction.Compare.html
System.Data.SQLite.SQLiteFunction.Dispose_overloads.html
System.Data.SQLite.SQLiteFunction.Dispose_overload_2.html
System.Data.SQLite.SQLiteFunction.Dispose_overload_1.html
System.Data.SQLite.SQLiteFunction.Final.html
System.Data.SQLite.SQLiteFunction.Invoke.html
System.Data.SQLite.SQLiteFunction.RegisterFunction.html
System.Data.SQLite.SQLiteFunction.Step.html
System.Data.SQLite.SQLiteFunctionAttribute.html
System.Data.SQLite.SQLiteFunctionAttributeMembers.html
System.Data.SQLite.SQLiteFunctionAttributeConstructor.html
System.Data.SQLite.SQLiteFunctionAttributeFields.html
System.Data.SQLite.SQLiteFunctionAttribute.Arguments.html
System.Data.SQLite.SQLiteFunctionAttribute.FuncType.html
................................................................................
System.Data.SQLite.SQLiteParameterConstructor8.html
System.Data.SQLite.SQLiteParameterConstructor9.html
System.Data.SQLite.SQLiteParameterConstructor10.html
System.Data.SQLite.SQLiteParameterConstructor11.html
System.Data.SQLite.SQLiteParameterConstructor12.html
System.Data.SQLite.SQLiteParameterConstructor13.html
System.Data.SQLite.SQLiteParameterConstructor14.html



System.Data.SQLite.SQLiteParameterProperties.html
System.Data.SQLite.SQLiteParameter.DbType.html
System.Data.SQLite.SQLiteParameter.Direction.html
System.Data.SQLite.SQLiteParameter.IsNullable.html
System.Data.SQLite.SQLiteParameter.Offset.html
System.Data.SQLite.SQLiteParameter.ParameterName.html
System.Data.SQLite.SQLiteParameter.Size.html
System.Data.SQLite.SQLiteParameter.SourceColumn.html
System.Data.SQLite.SQLiteParameter.SourceColumnNullMapping.html
System.Data.SQLite.SQLiteParameter.SourceVersion.html
System.Data.SQLite.SQLiteParameter.Value.html
System.Data.SQLite.SQLiteParameterMethods.html
System.Data.SQLite.SQLiteParameter.CopyTo.html
System.Data.SQLite.SQLiteParameter.ResetDbType.html
System.Data.SQLite.SQLiteParameterCollection.html
System.Data.SQLite.SQLiteParameterCollectionMembers.html
System.Data.SQLite.SQLiteParameterCollectionProperties.html
System.Data.SQLite.SQLiteParameterCollection.Count.html
System.Data.SQLite.SQLiteParameterCollection.IsFixedSize.html
System.Data.SQLite.SQLiteParameterCollection.IsReadOnly.html
................................................................................
Compiling Html Help file
Microsoft HTML Help Compiler 4.74.8702

Compiling c:\src\SQLite.NET\Doc\ndoc_msdn_temp\SQLite.NET.chm


Compile time: 0 minutes, 3 seconds
233	Topics
1,346	Local links
0	Internet links
8	Graphics


Created c:\src\SQLite.NET\Doc\ndoc_msdn_temp\SQLite.NET.chm, 138,849 bytes
Compression decreased file by 749,742 bytes.

Html Help compile complete
Done.







>







 







<







 







<
<







 







<







 







>
>
>












<







 







|
|




|
|



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
..
87
88
89
90
91
92
93

94
95
96
97
98
99
100
...
140
141
142
143
144
145
146


147
148
149
150
151
152
153
...
159
160
161
162
163
164
165

166
167
168
169
170
171
172
...
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
...
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
System.Data.SQLite.SQLiteCommand.html
System.Data.SQLite.SQLiteCommandMembers.html
System.Data.SQLite.SQLiteCommandConstructor.html
System.Data.SQLite.SQLiteCommandConstructor1.html
System.Data.SQLite.SQLiteCommandConstructor2.html
System.Data.SQLite.SQLiteCommandConstructor3.html
System.Data.SQLite.SQLiteCommandConstructor4.html
System.Data.SQLite.SQLiteCommandConstructor5.html
System.Data.SQLite.SQLiteCommandProperties.html
System.Data.SQLite.SQLiteCommand.CommandText.html
System.Data.SQLite.SQLiteCommand.CommandTimeout.html
System.Data.SQLite.SQLiteCommand.CommandType.html
System.Data.SQLite.SQLiteCommand.DesignTimeVisible.html
System.Data.SQLite.SQLiteCommand.UpdatedRowSource.html
System.Data.SQLite.SQLiteCommandMethods.html
................................................................................
System.Data.SQLite.SQLiteConvert.ToDateTime.html
System.Data.SQLite.SQLiteConvert.ToString_overloads.html
System.Data.SQLite.SQLiteConvert.ToString_overload_2.html
System.Data.SQLite.SQLiteConvert.ToString_overload_1.html
System.Data.SQLite.SQLiteConvert.ToUTF8_overloads.html
System.Data.SQLite.SQLiteConvert.ToUTF8_overload_2.html
System.Data.SQLite.SQLiteConvert.ToUTF8_overload_1.html

System.Data.SQLite.SQLiteDataAdapter.html
System.Data.SQLite.SQLiteDataAdapterMembers.html
System.Data.SQLite.SQLiteDataAdapterConstructor.html
System.Data.SQLite.SQLiteDataAdapterConstructor1.html
System.Data.SQLite.SQLiteDataAdapterConstructor2.html
System.Data.SQLite.SQLiteDataAdapterConstructor3.html
System.Data.SQLite.SQLiteDataAdapterConstructor4.html
................................................................................
System.Data.SQLite.SQLiteException.html
System.Data.SQLite.SQLiteExceptionMembers.html
System.Data.SQLite.SQLiteFactory.html
System.Data.SQLite.SQLiteFactoryMembers.html
System.Data.SQLite.SQLiteFactoryConstructor.html
System.Data.SQLite.SQLiteFactoryFields.html
System.Data.SQLite.SQLiteFactory.Instance.html


System.Data.SQLite.SQLiteFactoryMethods.html
System.Data.SQLite.SQLiteFactory.CreateCommand.html
System.Data.SQLite.SQLiteFactory.CreateCommandBuilder.html
System.Data.SQLite.SQLiteFactory.CreateConnection.html
System.Data.SQLite.SQLiteFactory.CreateConnectionStringBuilder.html
System.Data.SQLite.SQLiteFactory.CreateDataAdapter.html
System.Data.SQLite.SQLiteFactory.CreateParameter.html
................................................................................
System.Data.SQLite.SQLiteFunctionMethods.html
System.Data.SQLite.SQLiteFunction.Compare.html
System.Data.SQLite.SQLiteFunction.Dispose_overloads.html
System.Data.SQLite.SQLiteFunction.Dispose_overload_2.html
System.Data.SQLite.SQLiteFunction.Dispose_overload_1.html
System.Data.SQLite.SQLiteFunction.Final.html
System.Data.SQLite.SQLiteFunction.Invoke.html

System.Data.SQLite.SQLiteFunction.Step.html
System.Data.SQLite.SQLiteFunctionAttribute.html
System.Data.SQLite.SQLiteFunctionAttributeMembers.html
System.Data.SQLite.SQLiteFunctionAttributeConstructor.html
System.Data.SQLite.SQLiteFunctionAttributeFields.html
System.Data.SQLite.SQLiteFunctionAttribute.Arguments.html
System.Data.SQLite.SQLiteFunctionAttribute.FuncType.html
................................................................................
System.Data.SQLite.SQLiteParameterConstructor8.html
System.Data.SQLite.SQLiteParameterConstructor9.html
System.Data.SQLite.SQLiteParameterConstructor10.html
System.Data.SQLite.SQLiteParameterConstructor11.html
System.Data.SQLite.SQLiteParameterConstructor12.html
System.Data.SQLite.SQLiteParameterConstructor13.html
System.Data.SQLite.SQLiteParameterConstructor14.html
System.Data.SQLite.SQLiteParameterConstructor15.html
System.Data.SQLite.SQLiteParameterConstructor16.html
System.Data.SQLite.SQLiteParameterConstructor17.html
System.Data.SQLite.SQLiteParameterProperties.html
System.Data.SQLite.SQLiteParameter.DbType.html
System.Data.SQLite.SQLiteParameter.Direction.html
System.Data.SQLite.SQLiteParameter.IsNullable.html
System.Data.SQLite.SQLiteParameter.Offset.html
System.Data.SQLite.SQLiteParameter.ParameterName.html
System.Data.SQLite.SQLiteParameter.Size.html
System.Data.SQLite.SQLiteParameter.SourceColumn.html
System.Data.SQLite.SQLiteParameter.SourceColumnNullMapping.html
System.Data.SQLite.SQLiteParameter.SourceVersion.html
System.Data.SQLite.SQLiteParameter.Value.html
System.Data.SQLite.SQLiteParameterMethods.html

System.Data.SQLite.SQLiteParameter.ResetDbType.html
System.Data.SQLite.SQLiteParameterCollection.html
System.Data.SQLite.SQLiteParameterCollectionMembers.html
System.Data.SQLite.SQLiteParameterCollectionProperties.html
System.Data.SQLite.SQLiteParameterCollection.Count.html
System.Data.SQLite.SQLiteParameterCollection.IsFixedSize.html
System.Data.SQLite.SQLiteParameterCollection.IsReadOnly.html
................................................................................
Compiling Html Help file
Microsoft HTML Help Compiler 4.74.8702

Compiling c:\src\SQLite.NET\Doc\ndoc_msdn_temp\SQLite.NET.chm


Compile time: 0 minutes, 3 seconds
232	Topics
1,341	Local links
0	Internet links
8	Graphics


Created c:\src\SQLite.NET\Doc\ndoc_msdn_temp\SQLite.NET.chm, 142,903 bytes
Compression decreased file by 746,084 bytes.

Html Help compile complete
Done.

Changes to System.Data.SQLite/AssemblyInfo.cs.

1
2
3

4
5
6
7
8
9
10
..
14
15
16
17
18
19
20


21
22
23
24
25
26
27
28
29
30
31
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;


// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("System.Data.SQLite")]
[assembly: AssemblyDescription("ADO.NET 2.0 Data Provider for SQLite")]
[assembly: AssemblyConfiguration("")]
................................................................................
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

//  Setting ComVisible to false makes the types in this assembly not visible 
//  to COM componenets.  If you need to access a type in this assembly from 
//  COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]



// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Revision and Build Numbers 
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.12.*")]



>







 







>
>











1
2
3
4
5
6
7
8
9
10
11
..
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System;

// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("System.Data.SQLite")]
[assembly: AssemblyDescription("ADO.NET 2.0 Data Provider for SQLite")]
[assembly: AssemblyConfiguration("")]
................................................................................
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

//  Setting ComVisible to false makes the types in this assembly not visible 
//  to COM componenets.  If you need to access a type in this assembly from 
//  COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

[assembly: CLSCompliant(true)]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Revision and Build Numbers 
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.12.*")]

Changes to System.Data.SQLite/SQLite3.cs.

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
..
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
...
112
113
114
115
116
117
118

119
120
121

122
123
124
125

126
127
128
129
130
131
132
...
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
...
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
...
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
    /// The user-defined functions registered on this connection
    /// </summary>
    protected SQLiteFunction[] _functionsArray;

    internal SQLite3(DateTimeFormat fmt)
      : base(fmt)
    {
      _sql = 0;
      _functionsArray = null;
    }

    protected override void Dispose(bool bDisposing)
    {
      Close();
    }

    internal override void Close()
    {
      if (_sql != 0)
      {
        int n = UnsafeNativeMethods.sqlite3_close_interop(_sql);
        if (n > 0) throw new SQLiteException(n, SQLiteLastError());
        SQLiteFunction.UnbindFunctions(this, _functionsArray);
      }
      _sql = 0;
    }

    internal override void Cancel()
    {
................................................................................
      }
    }

    internal override void Open(string strFilename)
    {
      if (_sql != 0) return;
      int n = UnsafeNativeMethods.sqlite3_open_interop(ToUTF8(strFilename), out _sql);
      if (n > 0) throw new SQLiteException(n, SQLiteLastError());

      _functionsArray = SQLiteFunction.BindFunctions(this);
    }

    internal override void SetTimeout(int nTimeoutMS)
    {
      int n = UnsafeNativeMethods.sqlite3_busy_timeout_interop(_sql, nTimeoutMS);
      if (n > 0) throw new SQLiteException(n, SQLiteLastError());
    }

    internal override void Execute(string strSql)
    {
      IntPtr p;
      string str = strSql;
      int len;
................................................................................

        if (n == 100) return true;
        if (n == 101) return false;

        if (n > 0)
        {
          int r;

          // An error occurred, attempt to reset the statement.  If the reset worked because the
          // schema has changed, re-try the step again.  Otherwise throw the original error.


          r = Reset(stmt);

          if (r == 0)
            throw new SQLiteException(n, "in Step()");

          else if (r == 6 && stmt._command != null) // SQLITE_LOCKED
          {
            // Keep trying
            if (dwtick == 0) // First time we've encountered the lock
            {
              dwtick = DateTime.Now.Ticks + (stmt._command._commandTimeout * 10000000);
              rnd = new Random();
................................................................................
            }
          }

        }
      }
    }

    internal override void Finalize(SQLiteStatement stmt)
    {
      if (stmt._sqlite_stmt > 0)
      {
        int n = UnsafeNativeMethods.sqlite3_finalize_interop(stmt._sqlite_stmt);
        if (n > 0) throw new SQLiteException(n, "in Finalize()");
      }
      stmt._sqlite_stmt = 0;
................................................................................
      {
        // Recreate a dummy statement
        int nc = 0;
        string str;
        using (SQLiteStatement tmp = Prepare(stmt._sqlStatement, ref nc, out str))
        {
          // Finalize the existing statement
          Finalize(stmt);

          // Reassign a new statement pointer to the old statement and clear the temporary one
          stmt._sqlite_stmt = tmp._sqlite_stmt;
          tmp._sqlite_stmt = 0;

          // Reapply parameters
          stmt.BindParameters();
................................................................................

      return cmd;
    }

    internal override void Bind_Double(SQLiteStatement stmt, int index, double value)
    {
      int n = UnsafeNativeMethods.sqlite3_bind_double_interop(stmt._sqlite_stmt, index, ref value);
      if (n > 0) throw new SQLiteException(n, SQLiteLastError());
    }

    internal override void Bind_Int32(SQLiteStatement stmt, int index, int value)
    {
      int n = UnsafeNativeMethods.sqlite3_bind_int_interop(stmt._sqlite_stmt, index, value);
      if (n > 0) throw new SQLiteException(n, SQLiteLastError());
    }

    internal override void Bind_Int64(SQLiteStatement stmt, int index, long value)
    {
      int n = UnsafeNativeMethods.sqlite3_bind_int64_interop(stmt._sqlite_stmt, index, ref value);
      if (n > 0) throw new SQLiteException(n, SQLiteLastError());
    }

    internal override void Bind_Text(SQLiteStatement stmt, int index, string value)
    {
      byte[] b = ToUTF8(value);
      int n = UnsafeNativeMethods.sqlite3_bind_text_interop(stmt._sqlite_stmt, index, b, b.Length - 1, -1);
      if (n > 0) throw new SQLiteException(n, SQLiteLastError());
    }

    internal override void Bind_DateTime(SQLiteStatement stmt, int index, DateTime dt)
    {
      byte[] b = ToUTF8(dt);
      int n = UnsafeNativeMethods.sqlite3_bind_text_interop(stmt._sqlite_stmt, index, b, b.Length - 1, -1);
      if (n > 0) throw new SQLiteException(n, SQLiteLastError());
    }

    internal override void Bind_Blob(SQLiteStatement stmt, int index, byte[] blobData)
    {
      int n = UnsafeNativeMethods.sqlite3_bind_blob_interop(stmt._sqlite_stmt, index, blobData, blobData.Length, -1);
      if (n > 0) throw new SQLiteException(n, SQLiteLastError());
    }

    internal override void Bind_Null(SQLiteStatement stmt, int index)
    {
      int n = UnsafeNativeMethods.sqlite3_bind_null_interop(stmt._sqlite_stmt, index);
      if (n > 0) throw new SQLiteException(n, SQLiteLastError());
    }

    internal override int Bind_ParamCount(SQLiteStatement stmt)
    {
      return UnsafeNativeMethods.sqlite3_bind_parameter_count_interop(stmt._sqlite_stmt);
    }

................................................................................
    }

    internal override int CreateFunction(string strFunction, int nArgs, SQLiteCallback func, SQLiteCallback funcstep, SQLiteCallback funcfinal)
    {
      int nCookie;

      int n = UnsafeNativeMethods.sqlite3_create_function_interop(_sql, ToUTF8(strFunction), nArgs, 1, func, funcstep, funcfinal, out nCookie);
      if (n > 0) throw new SQLiteException(n, SQLiteLastError());

      return nCookie;
    }

    internal override int CreateCollation(string strCollation, SQLiteCollation func)
    {
      int nCookie;

      int n = UnsafeNativeMethods.sqlite3_create_collation_interop(_sql, ToUTF8(strCollation), 1, 0, func, out nCookie);
      if (n > 0) throw new SQLiteException(n, SQLiteLastError());

      return nCookie;
    }

    internal override void FreeFunction(int nCookie)
    {
      UnsafeNativeMethods.sqlite3_function_free_callbackcookie(nCookie);







<
<












|







 







|







|







 







>

|
<
>




>







 







|







 







|







 







|





|





|






|






|





|





|







 







|









|







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
..
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
...
110
111
112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
127
128
129
130
131
132
...
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
...
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
...
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
    /// The user-defined functions registered on this connection
    /// </summary>
    protected SQLiteFunction[] _functionsArray;

    internal SQLite3(DateTimeFormat fmt)
      : base(fmt)
    {


    }

    protected override void Dispose(bool bDisposing)
    {
      Close();
    }

    internal override void Close()
    {
      if (_sql != 0)
      {
        int n = UnsafeNativeMethods.sqlite3_close_interop(_sql);
        if (n > 0) throw new SQLiteException(n, "in Dispose()");
        SQLiteFunction.UnbindFunctions(this, _functionsArray);
      }
      _sql = 0;
    }

    internal override void Cancel()
    {
................................................................................
      }
    }

    internal override void Open(string strFilename)
    {
      if (_sql != 0) return;
      int n = UnsafeNativeMethods.sqlite3_open_interop(ToUTF8(strFilename), out _sql);
      if (n > 0) throw new SQLiteException(n, "in Open()");

      _functionsArray = SQLiteFunction.BindFunctions(this);
    }

    internal override void SetTimeout(int nTimeoutMS)
    {
      int n = UnsafeNativeMethods.sqlite3_busy_timeout_interop(_sql, nTimeoutMS);
      if (n > 0) throw new SQLiteException(n, "in SetTimeout()");
    }

    internal override void Execute(string strSql)
    {
      IntPtr p;
      string str = strSql;
      int len;
................................................................................

        if (n == 100) return true;
        if (n == 101) return false;

        if (n > 0)
        {
          int r;

          // An error occurred, attempt to reset the statement.  If the reset worked because the
          // schema has changed, re-try the step again.  If it errored our because the database

          // is locked, then keep retrying until the command timeout occurs.
          r = Reset(stmt);

          if (r == 0)
            throw new SQLiteException(n, "in Step()");

          else if (r == 6 && stmt._command != null) // SQLITE_LOCKED
          {
            // Keep trying
            if (dwtick == 0) // First time we've encountered the lock
            {
              dwtick = DateTime.Now.Ticks + (stmt._command._commandTimeout * 10000000);
              rnd = new Random();
................................................................................
            }
          }

        }
      }
    }

    internal override void FinalizeStatement(SQLiteStatement stmt)
    {
      if (stmt._sqlite_stmt > 0)
      {
        int n = UnsafeNativeMethods.sqlite3_finalize_interop(stmt._sqlite_stmt);
        if (n > 0) throw new SQLiteException(n, "in Finalize()");
      }
      stmt._sqlite_stmt = 0;
................................................................................
      {
        // Recreate a dummy statement
        int nc = 0;
        string str;
        using (SQLiteStatement tmp = Prepare(stmt._sqlStatement, ref nc, out str))
        {
          // Finalize the existing statement
          FinalizeStatement(stmt);

          // Reassign a new statement pointer to the old statement and clear the temporary one
          stmt._sqlite_stmt = tmp._sqlite_stmt;
          tmp._sqlite_stmt = 0;

          // Reapply parameters
          stmt.BindParameters();
................................................................................

      return cmd;
    }

    internal override void Bind_Double(SQLiteStatement stmt, int index, double value)
    {
      int n = UnsafeNativeMethods.sqlite3_bind_double_interop(stmt._sqlite_stmt, index, ref value);
      if (n > 0) throw new SQLiteException(n, "in Bind_Double()");
    }

    internal override void Bind_Int32(SQLiteStatement stmt, int index, int value)
    {
      int n = UnsafeNativeMethods.sqlite3_bind_int_interop(stmt._sqlite_stmt, index, value);
      if (n > 0) throw new SQLiteException(n, "in Bind_Int32()");
    }

    internal override void Bind_Int64(SQLiteStatement stmt, int index, long value)
    {
      int n = UnsafeNativeMethods.sqlite3_bind_int64_interop(stmt._sqlite_stmt, index, ref value);
      if (n > 0) throw new SQLiteException(n, "in Bind_Int64()");
    }

    internal override void Bind_Text(SQLiteStatement stmt, int index, string value)
    {
      byte[] b = ToUTF8(value);
      int n = UnsafeNativeMethods.sqlite3_bind_text_interop(stmt._sqlite_stmt, index, b, b.Length - 1, -1);
      if (n > 0) throw new SQLiteException(n, "in Bind_Text()");
    }

    internal override void Bind_DateTime(SQLiteStatement stmt, int index, DateTime dt)
    {
      byte[] b = ToUTF8(dt);
      int n = UnsafeNativeMethods.sqlite3_bind_text_interop(stmt._sqlite_stmt, index, b, b.Length - 1, -1);
      if (n > 0) throw new SQLiteException(n, "in Bind_DateTime()");
    }

    internal override void Bind_Blob(SQLiteStatement stmt, int index, byte[] blobData)
    {
      int n = UnsafeNativeMethods.sqlite3_bind_blob_interop(stmt._sqlite_stmt, index, blobData, blobData.Length, -1);
      if (n > 0) throw new SQLiteException(n, "in Bind_Blob()");
    }

    internal override void Bind_Null(SQLiteStatement stmt, int index)
    {
      int n = UnsafeNativeMethods.sqlite3_bind_null_interop(stmt._sqlite_stmt, index);
      if (n > 0) throw new SQLiteException(n, "in Bind_Null()");
    }

    internal override int Bind_ParamCount(SQLiteStatement stmt)
    {
      return UnsafeNativeMethods.sqlite3_bind_parameter_count_interop(stmt._sqlite_stmt);
    }

................................................................................
    }

    internal override int CreateFunction(string strFunction, int nArgs, SQLiteCallback func, SQLiteCallback funcstep, SQLiteCallback funcfinal)
    {
      int nCookie;

      int n = UnsafeNativeMethods.sqlite3_create_function_interop(_sql, ToUTF8(strFunction), nArgs, 1, func, funcstep, funcfinal, out nCookie);
      if (n > 0) throw new SQLiteException(n, "in CreateFunction()");

      return nCookie;
    }

    internal override int CreateCollation(string strCollation, SQLiteCollation func)
    {
      int nCookie;

      int n = UnsafeNativeMethods.sqlite3_create_collation_interop(_sql, ToUTF8(strCollation), 1, 0, func, out nCookie);
      if (n > 0) throw new SQLiteException(n, "in CreateCollation()");

      return nCookie;
    }

    internal override void FreeFunction(int nCookie)
    {
      UnsafeNativeMethods.sqlite3_function_free_callbackcookie(nCookie);

Changes to System.Data.SQLite/SQLite3_UTF16.cs.

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
    }

    /// <summary>
    /// Another custom string marshaling function
    /// </summary>
    /// <param name="b">A pointer to a zero-terminated UTF-16 string</param>
    /// <returns>A .NET string</returns>
    internal string ToString(IntPtr b)
    {
      if (b == IntPtr.Zero) return "";
      return Marshal.PtrToStringUni(b);
    }

    internal override void Open(string strFilename)
    {







|







33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
    }

    /// <summary>
    /// Another custom string marshaling function
    /// </summary>
    /// <param name="b">A pointer to a zero-terminated UTF-16 string</param>
    /// <returns>A .NET string</returns>
    internal static string ToString(IntPtr b)
    {
      if (b == IntPtr.Zero) return "";
      return Marshal.PtrToStringUni(b);
    }

    internal override void Open(string strFilename)
    {

Changes to System.Data.SQLite/SQLiteBase.cs.

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
...
182
183
184
185
186
187
188

189
190
191
192
193
194
195
    /// <param name="stmt">The SQLiteStatement to step through</param>
    /// <returns>True if a row was returned, False if not.</returns>
    internal abstract bool Step(SQLiteStatement stmt);
    /// <summary>
    /// Finalizes a prepared statement.
    /// </summary>
    /// <param name="stmt">The statement to finalize</param>
    internal abstract void Finalize(SQLiteStatement stmt);
    /// <summary>
    /// Resets a prepared statement so it can be executed again.  If the error returned is SQLITE_SCHEMA, 
    /// transparently attempt to rebuild the SQL statement and throw an error if that was not possible.
    /// </summary>
    /// <param name="stmt">The statement to reset</param>
    /// <returns>Returns -1 if the schema changed while resetting, 0 if the reset was sucessful or 6 (SQLITE_LOCKED) if the reset failed due to a lock</returns>
    internal abstract int Reset(SQLiteStatement stmt);
................................................................................
    internal abstract void ReturnInt64(int context, Int64 value);
    internal abstract void ReturnNull(int context);
    internal abstract void ReturnText(int context, string value);

    protected virtual void Dispose(bool bDisposing)
    {
    }

    public void Dispose()
    {
      Dispose(true);
      GC.SuppressFinalize(this);
    }
  }
}







|







 







>







83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
...
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
    /// <param name="stmt">The SQLiteStatement to step through</param>
    /// <returns>True if a row was returned, False if not.</returns>
    internal abstract bool Step(SQLiteStatement stmt);
    /// <summary>
    /// Finalizes a prepared statement.
    /// </summary>
    /// <param name="stmt">The statement to finalize</param>
    internal abstract void FinalizeStatement(SQLiteStatement stmt);
    /// <summary>
    /// Resets a prepared statement so it can be executed again.  If the error returned is SQLITE_SCHEMA, 
    /// transparently attempt to rebuild the SQL statement and throw an error if that was not possible.
    /// </summary>
    /// <param name="stmt">The statement to reset</param>
    /// <returns>Returns -1 if the schema changed while resetting, 0 if the reset was sucessful or 6 (SQLITE_LOCKED) if the reset failed due to a lock</returns>
    internal abstract int Reset(SQLiteStatement stmt);
................................................................................
    internal abstract void ReturnInt64(int context, Int64 value);
    internal abstract void ReturnNull(int context);
    internal abstract void ReturnText(int context, string value);

    protected virtual void Dispose(bool bDisposing)
    {
    }

    public void Dispose()
    {
      Dispose(true);
      GC.SuppressFinalize(this);
    }
  }
}

Changes to System.Data.SQLite/SQLiteCommand.cs.

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
...
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
...
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
...
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
...
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
...
299
300
301
302
303
304
305
306
307
308
309
310
311


312
313
314
315
316
317
318
...
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
...
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
...
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
    {
      Initialize(null, null);
    }

    /// <summary>
    /// Initializes the command with the given command text
    /// </summary>
    /// <param name="strSql">The SQL command text</param>
    public SQLiteCommand(string strSql)
    {
      Initialize(strSql, null);
    }

    /// <summary>
    /// Initializes the command with the given SQL command text and attach the command to the specified
    /// connection.
    /// </summary>
    /// <param name="strSql">The SQL command text</param>
    /// <param name="cnn">The connection to associate with the command</param>
    public SQLiteCommand(string strSql, SQLiteConnection cnn)
    {
      Initialize(strSql, cnn);
    }

    /// <summary>
    /// Initializes the command and associates it with the specified connection.
    /// </summary>
    /// <param name="cnn"></param>
    public SQLiteCommand(SQLiteConnection cnn)
    {
      Initialize(null, cnn);
    }













    /// <summary>
    /// Initializes the command class
    /// </summary>
    /// <param name="strSql">The SQL command text</param>
    /// <param name="cnn">A connection to associate with the command</param>
    private void Initialize(string strSql, SQLiteConnection cnn)
................................................................................
          if (itm != null)
          {
            itm._command = this;
            lst.Add(itm);
          }
        }
      }
      catch (Exception e)
      {
        ClearCommands();
        throw (e);
      }
      _statementList = new SQLiteStatement[lst.Count];
      lst.CopyTo(_statementList, 0);
    }

    /// <summary>
    /// Not implemented
................................................................................
        if (_commandText == value) return;

        if (_isReaderOpen)
        {
          throw new InvalidOperationException("Cannot set CommandText while a DataReader is active");
        }

//        if (value == null)
//          throw new ArgumentNullException();

        ClearCommands();
        _commandText = value;

        if (_cnn == null) return;
      }
    }

................................................................................
      {
        return CommandType.Text;
      }
      set
      {
        if (value != CommandType.Text)
        {
          throw new NotImplementedException();
        }
      }
    }

    /// <summary>
    /// Create a new parameter
    /// </summary>
................................................................................
        {
          ClearCommands();
          _cnn._commandList.Remove(this);
        }

        _cnn = (SQLiteConnection)value;
        _cnn._commandList.Add(this);

        if (_commandText != null)
          BuildCommands();
      }
    }

    /// <summary>
    /// Returns the SQLiteParameterCollection for the given command
    /// </summary>
    protected override DbParameterCollection DbParameterCollection
................................................................................
    {
      get
      {
        return _cnn._activeTransaction;
      }
      set
      {
        if (_cnn == null) return;

        if (value != _cnn._activeTransaction && value != null)
        {
          throw new ArgumentOutOfRangeException();
        }


      }
    }

    /// <summary>
    /// This function ensures there are no active readers, that we have a valid connection,
    /// that the connection is open, that all statements are prepared and all parameters are assigned
    /// in preparation for allocating a data reader.
................................................................................

      if (_cnn == null)
        throw new InvalidOperationException("No connection associated with this command");

      if (_cnn.State != ConnectionState.Open)
        throw new InvalidOperationException("Database is not open");

      int n;
      int x;

      Prepare();

      // Make sure all parameters are mapped properly to associated statement(s)
      _parameterCollection.MapParameters();

      x = _statementList.Length;
      // Bind all parameters to their statements




      for (n = 0; n < x; n++)
        _statementList[n].BindParameters();



    }

    /// <summary>
    /// Creates a new SQLiteDataReader to execute/iterate the array of SQLite prepared statements
    /// </summary>
    /// <param name="behavior">The behavior the data reader should adopt</param>
    /// <returns>Returns a SQLiteDataReader object</returns>
    protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
    {
      InitializeForReader();

      _cnn._sql.SetTimeout(_commandTimeout * 1000);

      SQLiteDataReader rd = new SQLiteDataReader(this, behavior);
      _isReaderOpen = true;
        
      return rd;
    }

    /// <summary>
................................................................................

    /// <summary>
    /// Execute the command and return the number of rows inserted/updated affected by it.
    /// </summary>
    /// <returns></returns>
    public override int ExecuteNonQuery()
    {
      //using (DbDataReader rd = ExecuteDbDataReader(CommandBehavior.Default))
      //{
      //  rd.Close();
      //  return rd.RecordsAffected;
      //}
      InitializeForReader();

      _cnn._sql.SetTimeout(_commandTimeout * 1000);

      int nAffected = 0;
      int n;
      int x;

      x = _statementList.Length;

      for (n = 0; n < x; n++)
................................................................................
        _cnn._sql.Reset(_statementList[n]);
      }

      return nAffected;
    }

    /// <summary>
    /// Execute the command and return the first column of the first row of the resultset (if present), or null if no resultset was returned.

    /// </summary>
    /// <returns></returns>
    public override object ExecuteScalar()
    {
      //using (DbDataReader rd = ExecuteDbDataReader(CommandBehavior.Default))
      //{
      //  if (rd.Read())
      //    return rd[0];
      //}
      //return null;

      InitializeForReader();

      _cnn._sql.SetTimeout(_commandTimeout * 1000);

      int n;
      int x;
      object ret = null;
      SQLiteType typ = new SQLiteType();

      x = _statementList.Length;








|
|

|






|

|

|





|




>
>
>
>
>
>
>
>
>
>
>
>







 







|


|







 







<
<
<







 







|







 







<
<
<







 







|
|
|
<
|

>
>







 







|
<
<





<

>
>
>
>


>
>
>











<
<







 







<
<
<
<
<


<
<







 







|
>




<
<
<
<
<
<
<


<
<







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
...
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
...
208
209
210
211
212
213
214



215
216
217
218
219
220
221
...
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
...
279
280
281
282
283
284
285



286
287
288
289
290
291
292
...
305
306
307
308
309
310
311
312
313
314

315
316
317
318
319
320
321
322
323
324
325
...
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
...
378
379
380
381
382
383
384





385
386


387
388
389
390
391
392
393
...
397
398
399
400
401
402
403
404
405
406
407
408
409







410
411


412
413
414
415
416
417
418
    {
      Initialize(null, null);
    }

    /// <summary>
    /// Initializes the command with the given command text
    /// </summary>
    /// <param name="commandText">The SQL command text</param>
    public SQLiteCommand(string commandText)
    {
      Initialize(commandText, null);
    }

    /// <summary>
    /// Initializes the command with the given SQL command text and attach the command to the specified
    /// connection.
    /// </summary>
    /// <param name="commandText">The SQL command text</param>
    /// <param name="cnn">The connection to associate with the command</param>
    public SQLiteCommand(string commandText, SQLiteConnection cnn)
    {
      Initialize(commandText, cnn);
    }

    /// <summary>
    /// Initializes the command and associates it with the specified connection.
    /// </summary>
    /// <param name="cnn">The connection to associate with the command</param>
    public SQLiteCommand(SQLiteConnection cnn)
    {
      Initialize(null, cnn);
    }

    /// <summary>
    /// Initializes a command with the given SQL, connection and transaction
    /// </summary>
    /// <param name="commandText">The SQL command text</param>
    /// <param name="cnn">The connection to associate with the command</param>
    /// <param name="trans">The transaction the command should be associated with</param>
    public SQLiteCommand(string commandText, SQLiteConnection cnn, SQLiteTransaction trans)
    {
      Initialize(commandText, cnn);
      Transaction = trans;
    }

    /// <summary>
    /// Initializes the command class
    /// </summary>
    /// <param name="strSql">The SQL command text</param>
    /// <param name="cnn">A connection to associate with the command</param>
    private void Initialize(string strSql, SQLiteConnection cnn)
................................................................................
          if (itm != null)
          {
            itm._command = this;
            lst.Add(itm);
          }
        }
      }
      catch (Exception)
      {
        ClearCommands();
        throw;
      }
      _statementList = new SQLiteStatement[lst.Count];
      lst.CopyTo(_statementList, 0);
    }

    /// <summary>
    /// Not implemented
................................................................................
        if (_commandText == value) return;

        if (_isReaderOpen)
        {
          throw new InvalidOperationException("Cannot set CommandText while a DataReader is active");
        }




        ClearCommands();
        _commandText = value;

        if (_cnn == null) return;
      }
    }

................................................................................
      {
        return CommandType.Text;
      }
      set
      {
        if (value != CommandType.Text)
        {
          throw new NotSupportedException();
        }
      }
    }

    /// <summary>
    /// Create a new parameter
    /// </summary>
................................................................................
        {
          ClearCommands();
          _cnn._commandList.Remove(this);
        }

        _cnn = (SQLiteConnection)value;
        _cnn._commandList.Add(this);



      }
    }

    /// <summary>
    /// Returns the SQLiteParameterCollection for the given command
    /// </summary>
    protected override DbParameterCollection DbParameterCollection
................................................................................
    {
      get
      {
        return _cnn._activeTransaction;
      }
      set
      {
        if (_cnn != null)
        {
          if (value != _cnn._activeTransaction && value != null)

            throw new ArgumentOutOfRangeException("DbTransaction", "Transaction is for a different connection than the one associated with this Command");
        }
        else if (value != null)
          throw new ArgumentOutOfRangeException("DbTransaction", "Not associated with a connection");
      }
    }

    /// <summary>
    /// This function ensures there are no active readers, that we have a valid connection,
    /// that the connection is open, that all statements are prepared and all parameters are assigned
    /// in preparation for allocating a data reader.
................................................................................

      if (_cnn == null)
        throw new InvalidOperationException("No connection associated with this command");

      if (_cnn.State != ConnectionState.Open)
        throw new InvalidOperationException("Database is not open");

      // Make sure all statements are prepared


      Prepare();

      // Make sure all parameters are mapped properly to associated statement(s)
      _parameterCollection.MapParameters();


      // Bind all parameters to their statements
      int n;
      int x;

      x = _statementList.Length;
      for (n = 0; n < x; n++)
        _statementList[n].BindParameters();

      // Set the default command timeout
      _cnn._sql.SetTimeout(_commandTimeout * 1000);
    }

    /// <summary>
    /// Creates a new SQLiteDataReader to execute/iterate the array of SQLite prepared statements
    /// </summary>
    /// <param name="behavior">The behavior the data reader should adopt</param>
    /// <returns>Returns a SQLiteDataReader object</returns>
    protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
    {
      InitializeForReader();



      SQLiteDataReader rd = new SQLiteDataReader(this, behavior);
      _isReaderOpen = true;
        
      return rd;
    }

    /// <summary>
................................................................................

    /// <summary>
    /// Execute the command and return the number of rows inserted/updated affected by it.
    /// </summary>
    /// <returns></returns>
    public override int ExecuteNonQuery()
    {





      InitializeForReader();



      int nAffected = 0;
      int n;
      int x;

      x = _statementList.Length;

      for (n = 0; n < x; n++)
................................................................................
        _cnn._sql.Reset(_statementList[n]);
      }

      return nAffected;
    }

    /// <summary>
    /// Execute the command and return the first column of the first row of the resultset
    /// (if present), or null if no resultset was returned.
    /// </summary>
    /// <returns></returns>
    public override object ExecuteScalar()
    {







      InitializeForReader();



      int n;
      int x;
      object ret = null;
      SQLiteType typ = new SQLiteType();

      x = _statementList.Length;

Changes to System.Data.SQLite/SQLiteCommandBuilder.cs.

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
    {
      throw new NotImplementedException();
    }

    /// <summary>
    /// Not implemented.
    /// </summary>
    /// <param name="parameterOrdinal">The ordinal of the parameter</param>
    /// <returns>Error</returns>
    protected override string GetParameterName(int parameterOrdinal)
    {
      return null;
    }

    /// <summary>
    /// Returns a placeholder character for the specified parameter ordinal.
    /// </summary>
    /// <param name="parameterOrdinal">The index of the parameter to provide a placeholder for</param>
    /// <returns>Returns a "?" character, used for all placeholders.</returns>
    protected override string GetParameterPlaceholder(int parameterOrdinal)
    {
      return "?";
    }







|







|







55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
    {
      throw new NotImplementedException();
    }

    /// <summary>
    /// Not implemented.
    /// </summary>
    /// <param name="parameterOrdinal">The i of the parameter</param>
    /// <returns>Error</returns>
    protected override string GetParameterName(int parameterOrdinal)
    {
      return null;
    }

    /// <summary>
    /// Returns a placeholder character for the specified parameter i.
    /// </summary>
    /// <param name="parameterOrdinal">The index of the parameter to provide a placeholder for</param>
    /// <returns>Returns a "?" character, used for all placeholders.</returns>
    protected override string GetParameterPlaceholder(int parameterOrdinal)
    {
      return "?";
    }

Changes to System.Data.SQLite/SQLiteConnection.cs.

201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
...
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
...
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
...
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
...
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
...
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
...
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
...
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
...
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
      if (connectionString != null)
        ConnectionString = connectionString;
    }

    /// <summary>
    /// Disposes of the SQLiteConnection, closing it if it is active.
    /// </summary>
    /// <param name="bDisposing">True if the connection is being explicitly closed.</param>
    protected override void Dispose(bool bDisposing)
    {
      base.Dispose(bDisposing);
      Close();
    }

    /// <summary>
    /// Raises the state change event when the state of the connection changes
    /// </summary>
    /// <param name="newState">The new state.  If it is different from the previous state, an event is raised.</param>
................................................................................
    /// <summary>
    /// Looks for a key in the array of key/values of the parameter string.  If not found, return the specified default value
    /// </summary>
    /// <param name="opts">The Key/Value pair array to look in</param>
    /// <param name="key">The key to find</param>
    /// <param name="defValue">The default value to return if the key is not found</param>
    /// <returns>The value corresponding to the specified key, or the default value if not found.</returns>
    internal string FindKey(KeyValuePair<string, string>[] opts, string key, string defValue)
    {
      int x = opts.Length;
      for (int n = 0; n < x; n++)
      {
        if (String.Compare(opts[n].Key, key, true) == 0)
        {
          return opts[n].Value;
................................................................................
        throw new InvalidOperationException();

      Close();

      KeyValuePair<string, string>[] opts = ParseConnectionString();

      if (Convert.ToInt32(FindKey(opts, "Version", "3")) != 3)
        throw new NotImplementedException("Only SQLite Version 3 is supported at this time");

      try
      {
        string strFile = FindKey(opts, "Data Source", "");
        bool bUTF16 = (Convert.ToBoolean(FindKey(opts, "UseUTF16Encoding", "False")) == true);

        if (bUTF16)
................................................................................
          _sql.Execute("PRAGMA encoding = 'UTF-8'");

        _sql.Execute(String.Format("PRAGMA Synchronous={0}", FindKey(opts, "Synchronous", "Normal")));
        _sql.Execute(String.Format("PRAGMA Cache_Size={0}", FindKey(opts, "Cache Size", "2000")));
        if (String.Compare(strFile, ":MEMORY:", true) != 0)
          _sql.Execute(String.Format("PRAGMA Page_Size={0}", FindKey(opts, "Page Size", "1024")));
      }
      catch (SQLiteException e)
      {
        OnStateChange(ConnectionState.Broken);
        throw (e);
      }
      OnStateChange(ConnectionState.Open);
    }

    /// <summary>
    /// Returns the version of the underlying SQLite database engine
    /// </summary>
................................................................................
      return null;
    }

    /// <summary>
    /// Builds a MetaDataCollections schema datatable
    /// </summary>
    /// <returns>DataTable</returns>
    private DataTable Schema_MetaDataCollections()
    {
      DataTable tbl = new DataTable("MetaDataCollections");
      DataRow row;

      tbl.Columns.Add("CollectionName", typeof(string));
      tbl.Columns.Add("NumberOfRestrictions", typeof(int));
      tbl.Columns.Add("NumberOfIdentifierParts", typeof(int));
................................................................................
      tbl.Columns.Add("COLLATION_NAME", typeof(string));
      tbl.Columns.Add("DOMAIN_CATALOG", typeof(string));
      tbl.Columns.Add("DOMAIN_NAME", typeof(string));
      tbl.Columns.Add("DESCRIPTION", typeof(string));

      tbl.BeginLoadData();

      if (strCatalog == null || strCatalog == "") strCatalog = "main";

      using (SQLiteCommand cmd = new SQLiteCommand(String.Format("SELECT * FROM [{0}].[{1}]", strCatalog, strTable), this))
      {
        using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader(CommandBehavior.SchemaOnly))
        {
          using (DataTable tblSchema = rd.GetSchemaTable())
          {
................................................................................
      tbl.Columns.Add("CARDINALITY", typeof(Decimal));
      tbl.Columns.Add("PAGES", typeof(int));
      tbl.Columns.Add("FILTER_CONDITION", typeof(string));
      tbl.Columns.Add("INTEGRATED", typeof(bool));

      tbl.BeginLoadData();

      if (strCatalog == null || strCatalog == "") strCatalog = "main";

      using (SQLiteCommand cmd = new SQLiteCommand(String.Format("SELECT * FROM [{0}].[sqlite_master] WHERE [type] = 'index'", strCatalog), this))
      {
        using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader())
        {
          while (rd.Read())
          {
................................................................................
      tbl.Columns.Add("DESCRIPTION", typeof(string));
      tbl.Columns.Add("TABLE_PROPID", typeof(long));
      tbl.Columns.Add("DATE_CREATED", typeof(DateTime));
      tbl.Columns.Add("DATE_MODIFIED", typeof(DateTime));

      tbl.BeginLoadData();

      if (strCatalog == null || strCatalog == "") strCatalog = "main";

      using (SQLiteCommand cmd = new SQLiteCommand(String.Format("SELECT * FROM [{0}].[sqlite_master] WHERE [type] NOT LIKE 'index'", strCatalog), this))
      {
        using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader())
        {
          while (rd.Read())
          {
................................................................................
      tbl.Columns.Add("IS_UPDATEABLE", typeof(bool));
      tbl.Columns.Add("DESCRIPTION", typeof(string));
      tbl.Columns.Add("DATE_CREATED", typeof(DateTime));
      tbl.Columns.Add("DATE_MODIFIED", typeof(DateTime));

      tbl.BeginLoadData();

      if (strCatalog == null || strCatalog == "") strCatalog = "main";

      using (SQLiteCommand cmd = new SQLiteCommand(String.Format("SELECT * FROM [{0}].[sqlite_master] WHERE [type] LIKE 'view'", strCatalog), this))
      {
        using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader())
        {
          while (rd.Read())
          {







|
|

|







 







|







 







|







 







|


|







 







|







 







|







 







|







 







|







 







|







201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
...
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
...
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
...
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
...
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
...
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
...
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
...
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
...
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
      if (connectionString != null)
        ConnectionString = connectionString;
    }

    /// <summary>
    /// Disposes of the SQLiteConnection, closing it if it is active.
    /// </summary>
    /// <param name="disposing">True if the connection is being explicitly closed.</param>
    protected override void Dispose(bool disposing)
    {
      base.Dispose(disposing);
      Close();
    }

    /// <summary>
    /// Raises the state change event when the state of the connection changes
    /// </summary>
    /// <param name="newState">The new state.  If it is different from the previous state, an event is raised.</param>
................................................................................
    /// <summary>
    /// Looks for a key in the array of key/values of the parameter string.  If not found, return the specified default value
    /// </summary>
    /// <param name="opts">The Key/Value pair array to look in</param>
    /// <param name="key">The key to find</param>
    /// <param name="defValue">The default value to return if the key is not found</param>
    /// <returns>The value corresponding to the specified key, or the default value if not found.</returns>
    static internal string FindKey(KeyValuePair<string, string>[] opts, string key, string defValue)
    {
      int x = opts.Length;
      for (int n = 0; n < x; n++)
      {
        if (String.Compare(opts[n].Key, key, true) == 0)
        {
          return opts[n].Value;
................................................................................
        throw new InvalidOperationException();

      Close();

      KeyValuePair<string, string>[] opts = ParseConnectionString();

      if (Convert.ToInt32(FindKey(opts, "Version", "3")) != 3)
        throw new NotSupportedException("Only SQLite Version 3 is supported at this time");

      try
      {
        string strFile = FindKey(opts, "Data Source", "");
        bool bUTF16 = (Convert.ToBoolean(FindKey(opts, "UseUTF16Encoding", "False")) == true);

        if (bUTF16)
................................................................................
          _sql.Execute("PRAGMA encoding = 'UTF-8'");

        _sql.Execute(String.Format("PRAGMA Synchronous={0}", FindKey(opts, "Synchronous", "Normal")));
        _sql.Execute(String.Format("PRAGMA Cache_Size={0}", FindKey(opts, "Cache Size", "2000")));
        if (String.Compare(strFile, ":MEMORY:", true) != 0)
          _sql.Execute(String.Format("PRAGMA Page_Size={0}", FindKey(opts, "Page Size", "1024")));
      }
      catch (SQLiteException)
      {
        OnStateChange(ConnectionState.Broken);
        throw;
      }
      OnStateChange(ConnectionState.Open);
    }

    /// <summary>
    /// Returns the version of the underlying SQLite database engine
    /// </summary>
................................................................................
      return null;
    }

    /// <summary>
    /// Builds a MetaDataCollections schema datatable
    /// </summary>
    /// <returns>DataTable</returns>
    private static DataTable Schema_MetaDataCollections()
    {
      DataTable tbl = new DataTable("MetaDataCollections");
      DataRow row;

      tbl.Columns.Add("CollectionName", typeof(string));
      tbl.Columns.Add("NumberOfRestrictions", typeof(int));
      tbl.Columns.Add("NumberOfIdentifierParts", typeof(int));
................................................................................
      tbl.Columns.Add("COLLATION_NAME", typeof(string));
      tbl.Columns.Add("DOMAIN_CATALOG", typeof(string));
      tbl.Columns.Add("DOMAIN_NAME", typeof(string));
      tbl.Columns.Add("DESCRIPTION", typeof(string));

      tbl.BeginLoadData();

      if (String.IsNullOrEmpty(strCatalog)) strCatalog = "main";

      using (SQLiteCommand cmd = new SQLiteCommand(String.Format("SELECT * FROM [{0}].[{1}]", strCatalog, strTable), this))
      {
        using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader(CommandBehavior.SchemaOnly))
        {
          using (DataTable tblSchema = rd.GetSchemaTable())
          {
................................................................................
      tbl.Columns.Add("CARDINALITY", typeof(Decimal));
      tbl.Columns.Add("PAGES", typeof(int));
      tbl.Columns.Add("FILTER_CONDITION", typeof(string));
      tbl.Columns.Add("INTEGRATED", typeof(bool));

      tbl.BeginLoadData();

      if (String.IsNullOrEmpty(strCatalog)) strCatalog = "main";

      using (SQLiteCommand cmd = new SQLiteCommand(String.Format("SELECT * FROM [{0}].[sqlite_master] WHERE [type] = 'index'", strCatalog), this))
      {
        using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader())
        {
          while (rd.Read())
          {
................................................................................
      tbl.Columns.Add("DESCRIPTION", typeof(string));
      tbl.Columns.Add("TABLE_PROPID", typeof(long));
      tbl.Columns.Add("DATE_CREATED", typeof(DateTime));
      tbl.Columns.Add("DATE_MODIFIED", typeof(DateTime));

      tbl.BeginLoadData();

      if (String.IsNullOrEmpty(strCatalog)) strCatalog = "main";

      using (SQLiteCommand cmd = new SQLiteCommand(String.Format("SELECT * FROM [{0}].[sqlite_master] WHERE [type] NOT LIKE 'index'", strCatalog), this))
      {
        using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader())
        {
          while (rd.Read())
          {
................................................................................
      tbl.Columns.Add("IS_UPDATEABLE", typeof(bool));
      tbl.Columns.Add("DESCRIPTION", typeof(string));
      tbl.Columns.Add("DATE_CREATED", typeof(DateTime));
      tbl.Columns.Add("DATE_MODIFIED", typeof(DateTime));

      tbl.BeginLoadData();

      if (String.IsNullOrEmpty(strCatalog)) strCatalog = "main";

      using (SQLiteCommand cmd = new SQLiteCommand(String.Format("SELECT * FROM [{0}].[sqlite_master] WHERE [type] LIKE 'view'", strCatalog), this))
      {
        using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader())
        {
          while (rd.Read())
          {

Changes to System.Data.SQLite/SQLiteConnectionStringBuilder.cs.

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
..
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
    {
      Initialize(null);
    }

    /// <summary>
    /// Constructs a new instance of the class using the specified connection string.
    /// </summary>
    /// <param name="cnnString">The connection string to parse</param>
    public SQLiteConnectionStringBuilder(string cnnString)
    {
      Initialize(cnnString);
    }

    /// <summary>
    /// Private initializer, which assigns the connection string and resets the builder
    /// </summary>
    /// <param name="cnnString">The connection string to assign</param>
    private void Initialize(string cnnString)
................................................................................
      get
      {
        return Convert.ToInt32(this["Version"]);
      }
      set
      {
        if (value != 3)
          throw new NotImplementedException();

        this["Version"] = value;
      }
    }

    /// <summary>
    /// Gets/Sets the synchronous mode of the connection string.  Default is "Normal".







|
|

|







 







|







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
..
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
    {
      Initialize(null);
    }

    /// <summary>
    /// Constructs a new instance of the class using the specified connection string.
    /// </summary>
    /// <param name="connectionString">The connection string to parse</param>
    public SQLiteConnectionStringBuilder(string connectionString)
    {
      Initialize(connectionString);
    }

    /// <summary>
    /// Private initializer, which assigns the connection string and resets the builder
    /// </summary>
    /// <param name="cnnString">The connection string to assign</param>
    private void Initialize(string cnnString)
................................................................................
      get
      {
        return Convert.ToInt32(this["Version"]);
      }
      set
      {
        if (value != 3)
          throw new NotSupportedException();

        this["Version"] = value;
      }
    }

    /// <summary>
    /// Gets/Sets the synchronous mode of the connection string.  Default is "Normal".

Changes to System.Data.SQLite/SQLiteConvert.cs.

14
15
16
17
18
19
20




21
22
23
24
25
26
27
..
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
..
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
...
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
...
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
...
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
  /// <summary>
  /// SQLite has very limited types, and is inherently text-based.  The first 5 types below represent the sum of all types SQLite
  /// understands.  The DateTime extension to the spec is for internal use only.
  /// </summary>
  public enum TypeAffinity
  {
    /// <summary>




    /// All integers in SQLite default to Int64
    /// </summary>
    Int64 = 1,
    /// <summary>
    /// All floating point numbers in SQLite default to double
    /// </summary>
    Double = 2,
................................................................................
    /// <summary>
    /// Null types can be returned from functions
    /// </summary>
    Null = 5,
    /// <summary>
    /// Used internally by this provider
    /// </summary>
    DateTime = 128,
    /// <summary>
    /// Used internally by this provider
    /// </summary>
    None=256,
  }

  /// <summary>
  /// This implementation of SQLite for ADO.NET can process date/time fields in databases in only one of two formats.  Ticks and ISO8601.
  /// Ticks is inherently more accurate, but less compatible with 3rd party tools that query the database, and renders the DateTime field
  /// unreadable without post-processing.
  /// ISO8601 is more compatible, readable, fully-processable, but less accurate as it doesn't provide time down to fractions of a second.
................................................................................
  /// This base class provides datatype conversion services for the SQLite provider.
  /// </summary>
  public abstract class SQLiteConvert
  {
    /// <summary>
    /// An array of ISO8601 datetime formats we support conversion from
    /// </summary>
    private static string[] _datetimeFormats;









    /// <summary>
    /// An UTF-8 Encoding instance, so we can convert strings to and from UTF8
    /// </summary>
    private static Text.UTF8Encoding _utf8 = new Text.UTF8Encoding();
    /// <summary>
    /// The default DateTime format for this instance
    /// </summary>
    private DateTimeFormat _datetimeFormat;

    /// <summary>
    /// Static constructor, initializes the supported ISO8601 date time formats
    /// </summary>
    static SQLiteConvert()
    {
      _datetimeFormats = new string[] {"yyyy-MM-dd HH:mm:ss",
																	  "yyyyMMddHHmmss",
																	  "yyyyMMddTHHmmssfffffff",
																	  "yyyy-MM-dd",
																	  "yy-MM-dd",
																	  "yyyyMMdd",
																	  "HH:mm:ss",
																	  "THHmmss"
															 };
    }

    /// <summary>
    /// Initializes the conversion class
    /// </summary>
    /// <param name="fmt">The default date/time format to use for this instance</param>
    internal SQLiteConvert(DateTimeFormat fmt)
    {
      _datetimeFormat = fmt;
    }

    #region UTF-8 Conversion Functions
    /// <summary>
    /// Converts a string to a UTF-8 encoded byte array sized to include a null-terminating character.
    /// </summary>
    /// <param name="strSrc">The string to convert to UTF-8</param>
    /// <returns>A byte array containing the converted string plus an extra 0 terminating byte at the end of the array.</returns>
    public byte[] ToUTF8(string strSrc)
    {
      Byte[] b;
      int nlen = _utf8.GetByteCount(strSrc) + 1;

      b = new byte[nlen];
      nlen = _utf8.GetBytes(strSrc, 0, strSrc.Length, b, 0);
      b[nlen] = 0;

      return b;
    }

    /// <summary>
    /// Convert a DateTime to a UTF-8 encoded, zero-terminated byte array.
    /// </summary>
    /// <remarks>
    /// This function is a convenience function, which first calls ToString() on the DateTime, and then calls ToUTF8() with the
    /// string result.
    /// </remarks>
    /// <param name="dtSrc">The DateTime to convert.</param>
    /// <returns>The UTF-8 encoded string, including a 0 terminating byte at the end of the array.</returns>
    public byte[] ToUTF8(DateTime dtSrc)
    {
      return ToUTF8(ToString(dtSrc));
    }

    /// <summary>
    /// Converts a UTF-8 encoded IntPtr of the specified length into a .NET string
    /// </summary>
    /// <param name="b">The pointer to the memory where the UTF-8 string is encoded</param>
    /// <param name="nlen">The number of bytes to decode</param>
    /// <returns>A string containing the translated character(s)</returns>
    public virtual string ToString(IntPtr b, int nlen)
    {
      if (nlen == 0) return "";

      byte[] byt;

      byt = new byte[nlen];
      Marshal.Copy(b, byt, 0, nlen);

      return _utf8.GetString(byt, 0, nlen);
    }

    #endregion

    #region DateTime Conversion Functions
    /// <summary>
    /// Converts a string into a DateTime, using the current DateTimeFormat specified for the connection when it was opened.
................................................................................
    ///   yyyyMMddTHHmmssfffffff
    ///   yyyy-MM-dd
    ///   yy-MM-dd
    ///   yyyyMMdd
    ///   HH:mm:ss
    ///   THHmmss
    /// </remarks>
    /// <param name="strSrc">The string containing either a Tick value or an ISO8601-format string</param>
    /// <returns>A DateTime value</returns>
    public DateTime ToDateTime(string strSrc)
    {
      switch (_datetimeFormat)
      {
        case DateTimeFormat.Ticks:
          return new DateTime(Convert.ToInt64(strSrc));
        default:
          return DateTime.ParseExact(strSrc, _datetimeFormats, System.Globalization.DateTimeFormatInfo.InvariantInfo, System.Globalization.DateTimeStyles.None);
      }
    }

    ///// <summary>
    ///// Attempt to convert the specified string to a datetime value.
    ///// </summary>
    ///// <param name="strSrc">The string to parse into a datetime</param>
................................................................................
    //  result = DateTime.Now;
    //  return false;
    //}

    /// <summary>
    /// Converts a DateTime to a string value, using the current DateTimeFormat specified for the connection when it was opened.
    /// </summary>
    /// <param name="dtSrc">The DateTime value to convert</param>
    /// <returns>Either a string consisting of the tick count for DateTimeFormat.Ticks, or a date/time in ISO8601 format.</returns>
    public string ToString(DateTime dtSrc)
    {
      switch (_datetimeFormat)
      {
        case DateTimeFormat.Ticks:
          return dtSrc.Ticks.ToString();
        default:
          return dtSrc.ToString(_datetimeFormats[0]);
      }
    }

    /// <summary>
    /// Internal function to convert a UTF-8 encoded IntPtr of the specified length to a DateTime.
    /// </summary>
    /// <remarks>
................................................................................
    /// [0] One<br/>
    /// [1] Two<br/>
    /// [2] Three, Four<br/>
    /// [3] Five<br/>
    /// <br/>
    /// Note that the leading and trailing spaces were removed from each item during the split.
    /// </remarks>
    /// <param name="src">Source string to split apart</param>
    /// <param name="sep">Separator character</param>
    /// <returns>A string array of the split up elements</returns>
    public static string[] Split(string src, char sep)
    {
      char[] toks = new char[2] { '\"', sep };
      char[] quot = new char[1] { '\"' };
      int n = 0;
      List<string> ls = new List<string>();
      string s;

      while (src.Length > 0)
      {
        n = src.IndexOfAny(toks, n);
        if (n == -1) break;
        if (src[n] == toks[0])
        {
          src = src.Remove(n, 1);
          n = src.IndexOfAny(quot, n);
          if (n == -1)
          {
            src = "\"" + src;
            break;
          }
          src = src.Remove(n, 1);
        }
        else
        {
          s = src.Substring(0, n).Trim();
          src = src.Substring(n + 1).Trim();
          if (s.Length > 0) ls.Add(s);
          n = 0;
        }
      }
      if (src.Length > 0) ls.Add(src);

      string[] ar = new string[ls.Count];
      ls.CopyTo(ar, 0);

      return ar;
    }

    #region Type Conversions
    /// <summary>
    /// Determines the data type of a column in a statement
    /// </summary>
    /// <param name="stmt">The statement to retrieve information for</param>
    /// <param name="ordinal">The column to retrieve type information on</param>
    /// <returns>Returns a SQLiteType struct</returns>
    internal static SQLiteType ColumnToType(SQLiteStatement stmt, int ordinal)
    {
      SQLiteType typ;

      typ.Type = TypeNameToDbType(stmt._sql.ColumnType(stmt, ordinal, out typ.Affinity));

      return typ;
    }

    /// <summary>
    /// Converts a SQLiteType to a .NET Type object
    /// </summary>







>
>
>
>







 







|

|

|







 







|
>
>
>
>
>
>
>
>









<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<













|

|

|
|

|
|
|

|









|

|

|





|
|

|

|

|

|
|

|







 







|

|




|

|







 







|

|




|

|







 







|
|

|

|





|

|

|

|
|


|


|



|
|




|












|

|



|







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
..
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
..
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
...
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
...
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
...
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
  /// <summary>
  /// SQLite has very limited types, and is inherently text-based.  The first 5 types below represent the sum of all types SQLite
  /// understands.  The DateTime extension to the spec is for internal use only.
  /// </summary>
  public enum TypeAffinity
  {
    /// <summary>
    /// Not used
    /// </summary>
    Uninitialized = 0,
    /// <summary>
    /// All integers in SQLite default to Int64
    /// </summary>
    Int64 = 1,
    /// <summary>
    /// All floating point numbers in SQLite default to double
    /// </summary>
    Double = 2,
................................................................................
    /// <summary>
    /// Null types can be returned from functions
    /// </summary>
    Null = 5,
    /// <summary>
    /// Used internally by this provider
    /// </summary>
    DateTime = 10,
    /// <summary>
    /// Used internally
    /// </summary>
    None = 256,
  }

  /// <summary>
  /// This implementation of SQLite for ADO.NET can process date/time fields in databases in only one of two formats.  Ticks and ISO8601.
  /// Ticks is inherently more accurate, but less compatible with 3rd party tools that query the database, and renders the DateTime field
  /// unreadable without post-processing.
  /// ISO8601 is more compatible, readable, fully-processable, but less accurate as it doesn't provide time down to fractions of a second.
................................................................................
  /// This base class provides datatype conversion services for the SQLite provider.
  /// </summary>
  public abstract class SQLiteConvert
  {
    /// <summary>
    /// An array of ISO8601 datetime formats we support conversion from
    /// </summary>
    private static string[] _datetimeFormats = new string[] {"yyyy-MM-dd HH:mm:ss",
																	  "yyyyMMddHHmmss",
																	  "yyyyMMddTHHmmssfffffff",
																	  "yyyy-MM-dd",
																	  "yy-MM-dd",
																	  "yyyyMMdd",
																	  "HH:mm:ss",
																	  "THHmmss"
															 };

    /// <summary>
    /// An UTF-8 Encoding instance, so we can convert strings to and from UTF8
    /// </summary>
    private static Text.UTF8Encoding _utf8 = new Text.UTF8Encoding();
    /// <summary>
    /// The default DateTime format for this instance
    /// </summary>
    private DateTimeFormat _datetimeFormat;

















    /// <summary>
    /// Initializes the conversion class
    /// </summary>
    /// <param name="fmt">The default date/time format to use for this instance</param>
    internal SQLiteConvert(DateTimeFormat fmt)
    {
      _datetimeFormat = fmt;
    }

    #region UTF-8 Conversion Functions
    /// <summary>
    /// Converts a string to a UTF-8 encoded byte array sized to include a null-terminating character.
    /// </summary>
    /// <param name="sourceText">The string to convert to UTF-8</param>
    /// <returns>A byte array containing the converted string plus an extra 0 terminating byte at the end of the array.</returns>
    public static byte[] ToUTF8(string sourceText)
    {
      Byte[] byteArray;
      int nlen = _utf8.GetByteCount(sourceText) + 1;

      byteArray = new byte[nlen];
      nlen = _utf8.GetBytes(sourceText, 0, sourceText.Length, byteArray, 0);
      byteArray[nlen] = 0;

      return byteArray;
    }

    /// <summary>
    /// Convert a DateTime to a UTF-8 encoded, zero-terminated byte array.
    /// </summary>
    /// <remarks>
    /// This function is a convenience function, which first calls ToString() on the DateTime, and then calls ToUTF8() with the
    /// string result.
    /// </remarks>
    /// <param name="dateTimeValue">The DateTime to convert.</param>
    /// <returns>The UTF-8 encoded string, including a 0 terminating byte at the end of the array.</returns>
    public byte[] ToUTF8(DateTime dateTimeValue)
    {
      return ToUTF8(ToString(dateTimeValue));
    }

    /// <summary>
    /// Converts a UTF-8 encoded IntPtr of the specified length into a .NET string
    /// </summary>
    /// <param name="nativestring">The pointer to the memory where the UTF-8 string is encoded</param>
    /// <param name="nativestringlen">The number of bytes to decode</param>
    /// <returns>A string containing the translated character(s)</returns>
    public virtual string ToString(IntPtr nativestring, int nativestringlen)
    {
      if (nativestringlen == 0) return "";

      byte[] byteArray;

      byteArray = new byte[nativestringlen];
      Marshal.Copy(nativestring, byteArray, 0, nativestringlen);

      return _utf8.GetString(byteArray, 0, nativestringlen);
    }

    #endregion

    #region DateTime Conversion Functions
    /// <summary>
    /// Converts a string into a DateTime, using the current DateTimeFormat specified for the connection when it was opened.
................................................................................
    ///   yyyyMMddTHHmmssfffffff
    ///   yyyy-MM-dd
    ///   yy-MM-dd
    ///   yyyyMMdd
    ///   HH:mm:ss
    ///   THHmmss
    /// </remarks>
    /// <param name="dateText">The string containing either a Tick value or an ISO8601-format string</param>
    /// <returns>A DateTime value</returns>
    public DateTime ToDateTime(string dateText)
    {
      switch (_datetimeFormat)
      {
        case DateTimeFormat.Ticks:
          return new DateTime(Convert.ToInt64(dateText));
        default:
          return DateTime.ParseExact(dateText, _datetimeFormats, System.Globalization.DateTimeFormatInfo.InvariantInfo, System.Globalization.DateTimeStyles.None);
      }
    }

    ///// <summary>
    ///// Attempt to convert the specified string to a datetime value.
    ///// </summary>
    ///// <param name="strSrc">The string to parse into a datetime</param>
................................................................................
    //  result = DateTime.Now;
    //  return false;
    //}

    /// <summary>
    /// Converts a DateTime to a string value, using the current DateTimeFormat specified for the connection when it was opened.
    /// </summary>
    /// <param name="dateValue">The DateTime value to convert</param>
    /// <returns>Either a string consisting of the tick count for DateTimeFormat.Ticks, or a date/time in ISO8601 format.</returns>
    public string ToString(DateTime dateValue)
    {
      switch (_datetimeFormat)
      {
        case DateTimeFormat.Ticks:
          return dateValue.Ticks.ToString();
        default:
          return dateValue.ToString(_datetimeFormats[0]);
      }
    }

    /// <summary>
    /// Internal function to convert a UTF-8 encoded IntPtr of the specified length to a DateTime.
    /// </summary>
    /// <remarks>
................................................................................
    /// [0] One<br/>
    /// [1] Two<br/>
    /// [2] Three, Four<br/>
    /// [3] Five<br/>
    /// <br/>
    /// Note that the leading and trailing spaces were removed from each item during the split.
    /// </remarks>
    /// <param name="source">Source string to split apart</param>
    /// <param name="separator">Separator character</param>
    /// <returns>A string array of the split up elements</returns>
    public static string[] Split(string source, char separator)
    {
      char[] toks = new char[2] { '\"', separator };
      char[] quot = new char[1] { '\"' };
      int n = 0;
      List<string> ls = new List<string>();
      string s;

      while (source.Length > 0)
      {
        n = source.IndexOfAny(toks, n);
        if (n == -1) break;
        if (source[n] == toks[0])
        {
          source = source.Remove(n, 1);
          n = source.IndexOfAny(quot, n);
          if (n == -1)
          {
            source = "\"" + source;
            break;
          }
          source = source.Remove(n, 1);
        }
        else
        {
          s = source.Substring(0, n).Trim();
          source = source.Substring(n + 1).Trim();
          if (s.Length > 0) ls.Add(s);
          n = 0;
        }
      }
      if (source.Length > 0) ls.Add(source);

      string[] ar = new string[ls.Count];
      ls.CopyTo(ar, 0);

      return ar;
    }

    #region Type Conversions
    /// <summary>
    /// Determines the data type of a column in a statement
    /// </summary>
    /// <param name="stmt">The statement to retrieve information for</param>
    /// <param name="i">The column to retrieve type information on</param>
    /// <returns>Returns a SQLiteType struct</returns>
    internal static SQLiteType ColumnToType(SQLiteStatement stmt, int i)
    {
      SQLiteType typ;

      typ.Type = TypeNameToDbType(stmt._sql.ColumnType(stmt, i, out typ.Affinity));

      return typ;
    }

    /// <summary>
    /// Converts a SQLiteType to a .NET Type object
    /// </summary>

Changes to System.Data.SQLite/SQLiteDataAdapter.cs.

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
    {
      SelectCommand = cmd;
    }

    /// <summary>
    /// Constructs a data adapter with the supplied select command text and associated with the specified connection.
    /// </summary>
    /// <param name="CommandText">The select command text to associate with the data adapter.</param>
    /// <param name="cnn">The connection to associate with the select command.</param>
    public SQLiteDataAdapter(string CommandText, SQLiteConnection cnn)
    {
      SelectCommand = new SQLiteCommand(CommandText, cnn);
    }

    /// <summary>
    /// Constructs a data adapter with the specified select command text, and using the specified database connection string.
    /// </summary>
    /// <param name="CommandText">The select command text to use to construct a select command.</param>
    /// <param name="ConnectionString">A connection string suitable for passing to a new SQLiteConnection, which is associated with the select command.</param>
    public SQLiteDataAdapter(string CommandText, string ConnectionString)
    {
      SQLiteConnection cnn = new SQLiteConnection(ConnectionString);
      SelectCommand = new SQLiteCommand(CommandText, cnn);
    }
  }
}







|

|

|





|
|
|

|
|



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
    {
      SelectCommand = cmd;
    }

    /// <summary>
    /// Constructs a data adapter with the supplied select command text and associated with the specified connection.
    /// </summary>
    /// <param name="commandText">The select command text to associate with the data adapter.</param>
    /// <param name="cnn">The connection to associate with the select command.</param>
    public SQLiteDataAdapter(string commandText, SQLiteConnection cnn)
    {
      SelectCommand = new SQLiteCommand(commandText, cnn);
    }

    /// <summary>
    /// Constructs a data adapter with the specified select command text, and using the specified database connection string.
    /// </summary>
    /// <param name="commandText">The select command text to use to construct a select command.</param>
    /// <param name="connectionString">A connection string suitable for passing to a new SQLiteConnection, which is associated with the select command.</param>
    public SQLiteDataAdapter(string commandText, string connectionString)
    {
      SQLiteConnection cnn = new SQLiteConnection(connectionString);
      SelectCommand = new SQLiteCommand(commandText, cnn);
    }
  }
}

Changes to System.Data.SQLite/SQLiteDataReader.cs.

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
...
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
...
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
...
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
...
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
...
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
    /// This function attempts to verify that the type of data being requested of a column matches the datatype of the column.  In
    /// the case of columns that are not backed into a table definition, we attempt to match up the affinity of a column (int, double, string or blob)
    /// to a set of known types that closely match that affinity.  It's not an exact science, but its the best we can do.
    /// </summary>
    /// <returns>
    /// This function throws an InvalidTypeCast() exception if the requested type doesn't match the column's definition or affinity.
    /// </returns>
    /// <param name="ordinal">The index of the column to type-check</param>
    /// <param name="typ">The type we want to get out of the column</param>
    private void VerifyType(int ordinal, DbType typ)
    {
      SQLiteType t = GetSQLiteType(ordinal);

      if (t.Type == typ) return;

      if (t.Type != DbType.Object)
      {
        // Coercable type, usually a literal of some kind
        switch (_fieldTypeArray[ordinal].Affinity)
        {
          case TypeAffinity.Int64:
            if (typ == DbType.Int16) return;
            if (typ == DbType.Int32) return;
            if (typ == DbType.Int64) return;
            if (typ == DbType.Boolean) return;
            if (typ == DbType.Byte) return;
................................................................................

      throw new InvalidCastException();
    }

    /// <summary>
    /// Retrieves the column as a boolean value
    /// </summary>
    /// <param name="ordinal">The index of the column to retrieve</param>
    /// <returns>bool</returns>
    public override bool GetBoolean(int ordinal)
    {
      VerifyType(ordinal, DbType.Boolean);
      return Convert.ToBoolean(GetValue(ordinal));
    }

    /// <summary>
    /// Retrieves the column as a single byte value
    /// </summary>
    /// <param name="ordinal">The index of the column to retrieve</param>
    /// <returns>byte</returns>
    public override byte GetByte(int ordinal)
    {
      VerifyType(ordinal, DbType.Byte);
      return Convert.ToByte(_activeStatement._sql.GetInt32(_activeStatement, ordinal));
    }

    /// <summary>
    /// Retrieves a column as an array of bytes (blob)
    /// </summary>
    /// <param name="ordinal">The index of the column to retrieve</param>
    /// <param name="dataOffset">The zero-based index of where to begin reading the data</param>
    /// <param name="buffer">The buffer to write the bytes into</param>
    /// <param name="bufferOffset">The zero-based index of where to begin writing into the array</param>
    /// <param name="length">The number of bytes to retrieve</param>
    /// <returns>The actual number of bytes written into the array</returns>
    /// <remarks>
    /// To determine the number of bytes in the column, pass a null value for the buffer.  The total length will be returned.
    /// </remarks>
    public override long GetBytes(int ordinal, long dataOffset, byte[] buffer, int bufferOffset, int length)
    {
      VerifyType(ordinal, DbType.Binary);
      return _activeStatement._sql.GetBytes(_activeStatement, ordinal, (int)dataOffset, buffer, bufferOffset, length);
    }

    /// <summary>
    /// Returns the column as a single character
    /// </summary>
    /// <param name="ordinal">The index of the column to retrieve</param>
    /// <returns>char</returns>
    public override char GetChar(int ordinal)
    {
      VerifyType(ordinal, DbType.SByte);
      return Convert.ToChar(_activeStatement._sql.GetInt32(_activeStatement, ordinal));
    }

    /// <summary>
    /// Retrieves a column as an array of chars (blob)
    /// </summary>
    /// <param name="ordinal">The index of the column to retrieve</param>
    /// <param name="dataOffset">The zero-based index of where to begin reading the data</param>
    /// <param name="buffer">The buffer to write the characters into</param>
    /// <param name="bufferOffset">The zero-based index of where to begin writing into the array</param>
    /// <param name="length">The number of bytes to retrieve</param>
    /// <returns>The actual number of characters written into the array</returns>
    /// <remarks>
    /// To determine the number of characters in the column, pass a null value for the buffer.  The total length will be returned.
    /// </remarks>
    public override long GetChars(int ordinal, long dataOffset, char[] buffer, int bufferOffset, int length)
    {
      VerifyType(ordinal, DbType.String);
      return _activeStatement._sql.GetChars(_activeStatement, ordinal, (int)dataOffset, buffer, bufferOffset, length);
    }

    /// <summary>
    /// Retrieves the name of the back-end datatype of the column
    /// </summary>
    /// <param name="ordinal">The index of the column to retrieve</param>
    /// <returns>string</returns>
    public override string GetDataTypeName(int ordinal)
    {
      CheckClosed();
      SQLiteType typ = GetSQLiteType(ordinal);

      if (typ.Type == DbType.Object) return SQLiteConvert.SQLiteTypeToType(typ).Name;

      return _activeStatement._sql.ColumnType(_activeStatement, ordinal, out typ.Affinity);
    }

    /// <summary>
    /// Retrieve the column as a date/time value
    /// </summary>
    /// <param name="ordinal">The index of the column to retrieve</param>
    /// <returns>DateTime</returns>
    public override DateTime GetDateTime(int ordinal)
    {
      VerifyType(ordinal, DbType.DateTime);
      return _activeStatement._sql.GetDateTime(_activeStatement, ordinal);
    }

    /// <summary>
    /// Retrieve the column as a decimal value
    /// </summary>
    /// <param name="ordinal">The index of the column to retrieve</param>
    /// <returns>decimal</returns>
    public override decimal GetDecimal(int ordinal)
    {
      VerifyType(ordinal, DbType.Decimal);
      return Convert.ToDecimal(_activeStatement._sql.GetDouble(_activeStatement, ordinal));
    }

    /// <summary>
    /// Returns the column as a double
    /// </summary>
    /// <param name="ordinal">The index of the column to retrieve</param>
    /// <returns>double</returns>
    public override double GetDouble(int ordinal)
    {
      VerifyType(ordinal, DbType.Double);
      return _activeStatement._sql.GetDouble(_activeStatement, ordinal);
    }

    /// <summary>
    /// Returns the .NET type of a given column
    /// </summary>
    /// <param name="ordinal">The index of the column to retrieve</param>
    /// <returns>Type</returns>
    public override Type GetFieldType(int ordinal)
    {
      return SQLiteConvert.SQLiteTypeToType(GetSQLiteType(ordinal));
    }

    /// <summary>
    /// Returns a column as a float value
    /// </summary>
    /// <param name="ordinal">The index of the column to retrieve</param>
    /// <returns>float</returns>
    public override float GetFloat(int ordinal)
    {
      VerifyType(ordinal, DbType.Single);
      return Convert.ToSingle(_activeStatement._sql.GetDouble(_activeStatement, ordinal));
    }

    /// <summary>
    /// Returns the column as a Guid
    /// </summary>
    /// <param name="ordinal">The index of the column to retrieve</param>
    /// <returns>Guid</returns>
    public override Guid GetGuid(int ordinal)
    {
      VerifyType(ordinal, DbType.Guid);
      return new Guid(_activeStatement._sql.GetText(_activeStatement, ordinal));
    }

    /// <summary>
    /// Returns the column as a short
    /// </summary>
    /// <param name="ordinal">The index of the column to retrieve</param>
    /// <returns>Int16</returns>
    public override Int16 GetInt16(int ordinal)
    {
      VerifyType(ordinal, DbType.Int16);
      return Convert.ToInt16(_activeStatement._sql.GetInt32(_activeStatement, ordinal));
    }

    /// <summary>
    /// Retrieves the column as an int
    /// </summary>
    /// <param name="ordinal">The index of the column to retrieve</param>
    /// <returns>Int32</returns>
    public override Int32 GetInt32(int ordinal)
    {
      VerifyType(ordinal, DbType.Int32);
      return _activeStatement._sql.GetInt32(_activeStatement, ordinal);
    }

    /// <summary>
    /// Retrieves the column as a long
    /// </summary>
    /// <param name="ordinal">The index of the column to retrieve</param>
    /// <returns>Int64</returns>
    public override Int64 GetInt64(int ordinal)
    {
      VerifyType(ordinal, DbType.Int64);
      return _activeStatement._sql.GetInt64(_activeStatement, ordinal);
    }

    /// <summary>
    /// Retrieves the name of the column
    /// </summary>
    /// <param name="ordinal">The index of the column to retrieve</param>
    /// <returns>string</returns>
    public override string GetName(int ordinal)
    {
      CheckClosed();
      return _activeStatement._sql.ColumnName(_activeStatement, ordinal);
    }

    /// <summary>
    /// Retrieves the ordinal of a column, given its name
    /// </summary>
    /// <param name="name">The name of the column to retrieve</param>
    /// <returns>The int ordinal of the column</returns>
    public override int GetOrdinal(string name)
    {
      CheckClosed();
      return _activeStatement._sql.ColumnIndex(_activeStatement, name);
    }

    /// <summary>
................................................................................

      return tbl;
    }

    /// <summary>
    /// Retrieves the column as a string
    /// </summary>
    /// <param name="ordinal">The index of the column to retrieve</param>
    /// <returns>string</returns>
    public override string GetString(int ordinal)
    {
      VerifyType(ordinal, DbType.String);
      return _activeStatement._sql.GetText(_activeStatement, ordinal);
    }

    /// <summary>
    /// Retrieves the column as an object corresponding to the underlying datatype of the column
    /// </summary>
    /// <param name="ordinal">The index of the column to retrieve</param>
    /// <returns>object</returns>
    public override object GetValue(int ordinal)
    {
      SQLiteType typ = GetSQLiteType(ordinal);

      return _activeStatement._sql.GetValue(_activeStatement, ordinal, ref typ);
    }

    /// <summary>
    /// Retreives the values of multiple columns, up to the size of the supplied array
    /// </summary>
    /// <param name="values">The array to fill with values from the columns in the current resultset</param>
    /// <returns>The number of columns retrieved</returns>
................................................................................
    {
      get { return (_command == null); }
    }

    /// <summary>
    /// Returns True if the specified column is null
    /// </summary>
    /// <param name="ordinal">The index of the column to retrieve</param>
    /// <returns>True or False</returns>
    public override bool IsDBNull(int ordinal)
    {
      CheckClosed();
      return _activeStatement._sql.IsNull(_activeStatement, ordinal);
    }

    /// <summary>
    /// Moves to the next resultset in multiple row-returning SQL command.
    /// </summary>
    /// <returns>True if the command was successful and a new resultset is available, False otherwise.</returns>
    public override bool NextResult()
................................................................................
        return true;
      }
    }

    /// <summary>
    /// Retrieves the SQLiteType for a given column, and caches it to avoid repetetive interop calls.
    /// </summary>
    /// <param name="ordinal">The index of the column to retrieve</param>
    /// <returns>A SQLiteType structure</returns>
    private SQLiteType GetSQLiteType(int ordinal)
    {
      CheckClosed();
      if (_fieldTypeArray == null) _fieldTypeArray = new SQLiteType[_fieldCount];

      if (_fieldTypeArray[ordinal].Affinity == 0)
        _fieldTypeArray[ordinal].Type = SQLiteConvert.TypeNameToDbType(_activeStatement._sql.ColumnType(_activeStatement, ordinal, out _fieldTypeArray[ordinal].Affinity));
      return _fieldTypeArray[ordinal];
    }

    /// <summary>
    /// Reads the next row from the resultset
    /// </summary>
    /// <returns>True if a new row was successfully loaded and is ready for processing</returns>
    public override bool Read()
................................................................................
    /// <returns>The value contained in the column</returns>
    public override object this[string name]
    {
      get { return GetValue(GetOrdinal(name)); }
    }

    /// <summary>
    /// Indexer to retrieve data from a column given its ordinal
    /// </summary>
    /// <param name="ordinal">The index of the column to retrieve</param>
    /// <returns>The value contained in the column</returns>
    public override object this[int ordinal]
    {
      get { return GetValue(ordinal); }
    }
  }
}







|

|

|






|







 







|

|

|
|





|

|

|
|





|
|

|





|

|
|





|

|

|
|





|
|

|





|

|
|





|

|


|



|





|

|

|
|





|

|

|
|





|

|

|
|





|

|

|





|

|

|
|





|

|

|
|





|

|

|
|





|

|

|
|





|

|

|
|





|

|


|



|


|







 







|

|

|
|





|

|

|

|







 







|

|


|







 







|

|




|
|
|







 







|

|

|

|



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
...
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
...
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
...
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
...
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
...
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
    /// This function attempts to verify that the type of data being requested of a column matches the datatype of the column.  In
    /// the case of columns that are not backed into a table definition, we attempt to match up the affinity of a column (int, double, string or blob)
    /// to a set of known types that closely match that affinity.  It's not an exact science, but its the best we can do.
    /// </summary>
    /// <returns>
    /// This function throws an InvalidTypeCast() exception if the requested type doesn't match the column's definition or affinity.
    /// </returns>
    /// <param name="i">The index of the column to type-check</param>
    /// <param name="typ">The type we want to get out of the column</param>
    private void VerifyType(int i, DbType typ)
    {
      SQLiteType t = GetSQLiteType(i);

      if (t.Type == typ) return;

      if (t.Type != DbType.Object)
      {
        // Coercable type, usually a literal of some kind
        switch (_fieldTypeArray[i].Affinity)
        {
          case TypeAffinity.Int64:
            if (typ == DbType.Int16) return;
            if (typ == DbType.Int32) return;
            if (typ == DbType.Int64) return;
            if (typ == DbType.Boolean) return;
            if (typ == DbType.Byte) return;
................................................................................

      throw new InvalidCastException();
    }

    /// <summary>
    /// Retrieves the column as a boolean value
    /// </summary>
    /// <param name="i">The index of the column to retrieve</param>
    /// <returns>bool</returns>
    public override bool GetBoolean(int i)
    {
      VerifyType(i, DbType.Boolean);
      return Convert.ToBoolean(GetValue(i));
    }

    /// <summary>
    /// Retrieves the column as a single byte value
    /// </summary>
    /// <param name="i">The index of the column to retrieve</param>
    /// <returns>byte</returns>
    public override byte GetByte(int i)
    {
      VerifyType(i, DbType.Byte);
      return Convert.ToByte(_activeStatement._sql.GetInt32(_activeStatement, i));
    }

    /// <summary>
    /// Retrieves a column as an array of bytes (blob)
    /// </summary>
    /// <param name="i">The index of the column to retrieve</param>
    /// <param name="fieldOffset">The zero-based index of where to begin reading the data</param>
    /// <param name="buffer">The buffer to write the bytes into</param>
    /// <param name="bufferoffset">The zero-based index of where to begin writing into the array</param>
    /// <param name="length">The number of bytes to retrieve</param>
    /// <returns>The actual number of bytes written into the array</returns>
    /// <remarks>
    /// To determine the number of bytes in the column, pass a null value for the buffer.  The total length will be returned.
    /// </remarks>
    public override long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length)
    {
      VerifyType(i, DbType.Binary);
      return _activeStatement._sql.GetBytes(_activeStatement, i, (int)fieldOffset, buffer, bufferoffset, length);
    }

    /// <summary>
    /// Returns the column as a single character
    /// </summary>
    /// <param name="i">The index of the column to retrieve</param>
    /// <returns>char</returns>
    public override char GetChar(int i)
    {
      VerifyType(i, DbType.SByte);
      return Convert.ToChar(_activeStatement._sql.GetInt32(_activeStatement, i));
    }

    /// <summary>
    /// Retrieves a column as an array of chars (blob)
    /// </summary>
    /// <param name="i">The index of the column to retrieve</param>
    /// <param name="fieldoffset">The zero-based index of where to begin reading the data</param>
    /// <param name="buffer">The buffer to write the characters into</param>
    /// <param name="bufferoffset">The zero-based index of where to begin writing into the array</param>
    /// <param name="length">The number of bytes to retrieve</param>
    /// <returns>The actual number of characters written into the array</returns>
    /// <remarks>
    /// To determine the number of characters in the column, pass a null value for the buffer.  The total length will be returned.
    /// </remarks>
    public override long GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, int length)
    {
      VerifyType(i, DbType.String);
      return _activeStatement._sql.GetChars(_activeStatement, i, (int)fieldoffset, buffer, bufferoffset, length);
    }

    /// <summary>
    /// Retrieves the name of the back-end datatype of the column
    /// </summary>
    /// <param name="i">The index of the column to retrieve</param>
    /// <returns>string</returns>
    public override string GetDataTypeName(int i)
    {
      CheckClosed();
      SQLiteType typ = GetSQLiteType(i);

      if (typ.Type == DbType.Object) return SQLiteConvert.SQLiteTypeToType(typ).Name;

      return _activeStatement._sql.ColumnType(_activeStatement, i, out typ.Affinity);
    }

    /// <summary>
    /// Retrieve the column as a date/time value
    /// </summary>
    /// <param name="i">The index of the column to retrieve</param>
    /// <returns>DateTime</returns>
    public override DateTime GetDateTime(int i)
    {
      VerifyType(i, DbType.DateTime);
      return _activeStatement._sql.GetDateTime(_activeStatement, i);
    }

    /// <summary>
    /// Retrieve the column as a decimal value
    /// </summary>
    /// <param name="i">The index of the column to retrieve</param>
    /// <returns>decimal</returns>
    public override decimal GetDecimal(int i)
    {
      VerifyType(i, DbType.Decimal);
      return Convert.ToDecimal(_activeStatement._sql.GetDouble(_activeStatement, i));
    }

    /// <summary>
    /// Returns the column as a double
    /// </summary>
    /// <param name="i">The index of the column to retrieve</param>
    /// <returns>double</returns>
    public override double GetDouble(int i)
    {
      VerifyType(i, DbType.Double);
      return _activeStatement._sql.GetDouble(_activeStatement, i);
    }

    /// <summary>
    /// Returns the .NET type of a given column
    /// </summary>
    /// <param name="i">The index of the column to retrieve</param>
    /// <returns>Type</returns>
    public override Type GetFieldType(int i)
    {
      return SQLiteConvert.SQLiteTypeToType(GetSQLiteType(i));
    }

    /// <summary>
    /// Returns a column as a float value
    /// </summary>
    /// <param name="i">The index of the column to retrieve</param>
    /// <returns>float</returns>
    public override float GetFloat(int i)
    {
      VerifyType(i, DbType.Single);
      return Convert.ToSingle(_activeStatement._sql.GetDouble(_activeStatement, i));
    }

    /// <summary>
    /// Returns the column as a Guid
    /// </summary>
    /// <param name="i">The index of the column to retrieve</param>
    /// <returns>Guid</returns>
    public override Guid GetGuid(int i)
    {
      VerifyType(i, DbType.Guid);
      return new Guid(_activeStatement._sql.GetText(_activeStatement, i));
    }

    /// <summary>
    /// Returns the column as a short
    /// </summary>
    /// <param name="i">The index of the column to retrieve</param>
    /// <returns>Int16</returns>
    public override Int16 GetInt16(int i)
    {
      VerifyType(i, DbType.Int16);
      return Convert.ToInt16(_activeStatement._sql.GetInt32(_activeStatement, i));
    }

    /// <summary>
    /// Retrieves the column as an int
    /// </summary>
    /// <param name="i">The index of the column to retrieve</param>
    /// <returns>Int32</returns>
    public override Int32 GetInt32(int i)
    {
      VerifyType(i, DbType.Int32);
      return _activeStatement._sql.GetInt32(_activeStatement, i);
    }

    /// <summary>
    /// Retrieves the column as a long
    /// </summary>
    /// <param name="i">The index of the column to retrieve</param>
    /// <returns>Int64</returns>
    public override Int64 GetInt64(int i)
    {
      VerifyType(i, DbType.Int64);
      return _activeStatement._sql.GetInt64(_activeStatement, i);
    }

    /// <summary>
    /// Retrieves the name of the column
    /// </summary>
    /// <param name="i">The index of the column to retrieve</param>
    /// <returns>string</returns>
    public override string GetName(int i)
    {
      CheckClosed();
      return _activeStatement._sql.ColumnName(_activeStatement, i);
    }

    /// <summary>
    /// Retrieves the i of a column, given its name
    /// </summary>
    /// <param name="name">The name of the column to retrieve</param>
    /// <returns>The int i of the column</returns>
    public override int GetOrdinal(string name)
    {
      CheckClosed();
      return _activeStatement._sql.ColumnIndex(_activeStatement, name);
    }

    /// <summary>
................................................................................

      return tbl;
    }

    /// <summary>
    /// Retrieves the column as a string
    /// </summary>
    /// <param name="i">The index of the column to retrieve</param>
    /// <returns>string</returns>
    public override string GetString(int i)
    {
      VerifyType(i, DbType.String);
      return _activeStatement._sql.GetText(_activeStatement, i);
    }

    /// <summary>
    /// Retrieves the column as an object corresponding to the underlying datatype of the column
    /// </summary>
    /// <param name="i">The index of the column to retrieve</param>
    /// <returns>object</returns>
    public override object GetValue(int i)
    {
      SQLiteType typ = GetSQLiteType(i);

      return _activeStatement._sql.GetValue(_activeStatement, i, ref typ);
    }

    /// <summary>
    /// Retreives the values of multiple columns, up to the size of the supplied array
    /// </summary>
    /// <param name="values">The array to fill with values from the columns in the current resultset</param>
    /// <returns>The number of columns retrieved</returns>
................................................................................
    {
      get { return (_command == null); }
    }

    /// <summary>
    /// Returns True if the specified column is null
    /// </summary>
    /// <param name="i">The index of the column to retrieve</param>
    /// <returns>True or False</returns>
    public override bool IsDBNull(int i)
    {
      CheckClosed();
      return _activeStatement._sql.IsNull(_activeStatement, i);
    }

    /// <summary>
    /// Moves to the next resultset in multiple row-returning SQL command.
    /// </summary>
    /// <returns>True if the command was successful and a new resultset is available, False otherwise.</returns>
    public override bool NextResult()
................................................................................
        return true;
      }
    }

    /// <summary>
    /// Retrieves the SQLiteType for a given column, and caches it to avoid repetetive interop calls.
    /// </summary>
    /// <param name="i">The index of the column to retrieve</param>
    /// <returns>A SQLiteType structure</returns>
    private SQLiteType GetSQLiteType(int i)
    {
      CheckClosed();
      if (_fieldTypeArray == null) _fieldTypeArray = new SQLiteType[_fieldCount];

      if (_fieldTypeArray[i].Affinity == 0)
        _fieldTypeArray[i].Type = SQLiteConvert.TypeNameToDbType(_activeStatement._sql.ColumnType(_activeStatement, i, out _fieldTypeArray[i].Affinity));
      return _fieldTypeArray[i];
    }

    /// <summary>
    /// Reads the next row from the resultset
    /// </summary>
    /// <returns>True if a new row was successfully loaded and is ready for processing</returns>
    public override bool Read()
................................................................................
    /// <returns>The value contained in the column</returns>
    public override object this[string name]
    {
      get { return GetValue(GetOrdinal(name)); }
    }

    /// <summary>
    /// Indexer to retrieve data from a column given its i
    /// </summary>
    /// <param name="i">The index of the column to retrieve</param>
    /// <returns>The value contained in the column</returns>
    public override object this[int i]
    {
      get { return GetValue(i); }
    }
  }
}

Changes to System.Data.SQLite/SQLiteException.cs.

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
 ********************************************************/

namespace System.Data.SQLite
{
  using System;
  using System.Collections.Generic;
  using System.Text;






  /// <summary>
  /// SQLite exception class.
  /// </summary>



  public sealed class SQLiteException : Exception
  {
    internal SQLiteException(int nCode) : base(Initialize(nCode, null))
    {
      HResult = (int)((uint)0x800F0000 | (uint)nCode);
    }

    internal SQLiteException(int nCode, string strMessage) : base(Initialize(nCode, strMessage))
    {
      HResult = (int)((uint)0x800F0000 | (uint)nCode);




























    }

    /// <summary>
    /// Initializes the exception class with the SQLite error code.
    /// </summary>
    /// <param name="nCode">The SQLite error code</param>
    /// <param name="strMessage">A detailed error message</param>
    /// <returns>An error message string</returns>
    /// <remarks>
    /// The SQLite error code is OR'd with 0x800F0000 to generate an HResult
    /// </remarks>
    private static string Initialize(int nCode, string strMessage)
    {
      if (strMessage != null)
      {
        if (strMessage.Length > 0)
          strMessage = "\r\n\r\n" + strMessage;
      }

      switch (nCode)
      {
        case 1:
          return "SQLite error" + strMessage;
        case 2:
          return "An internal logic error in SQLite" + strMessage;







>
>
>
>
>




>
>
>


|




|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>













|
|
|
|
<







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
 ********************************************************/

namespace System.Data.SQLite
{
  using System;
  using System.Collections.Generic;
  using System.Text;
  using System.Data.Common;

#if !PLATFORM_COMPACTFRAMEWORK
  using System.Runtime.Serialization;
#endif

  /// <summary>
  /// SQLite exception class.
  /// </summary>
#if !PLATFORM_COMPACTFRAMEWORK
  [Serializable]
#endif
  public sealed class SQLiteException : Exception
  {
    internal SQLiteException(int nCode, string strMessage) : base(Initialize(nCode, strMessage))
    {
      HResult = (int)((uint)0x800F0000 | (uint)nCode);
    }

#if !PLATFORM_COMPACTFRAMEWORK

    private SQLiteException(SerializationInfo info, StreamingContext context) : base(info, context)
    {
    }
#endif

    /// <summary>
    /// Various public constructors that just pass along to the base DbException
    /// </summary>
    /// <param name="message">Passed verbatim to DbException</param>
    public SQLiteException(string message)
      : base(message)
    {
    }

    /// <summary>
    /// Various public constructors that just pass along to the base DbException
    /// </summary>
    public SQLiteException()
    {
    }

    /// <summary>
    /// Various public constructors that just pass along to the base DbException
    /// <param name="message">Passed to DbException</param>
    /// <param name="innerException">Passed to DbException</param>
    /// </summary>
    public SQLiteException(string message, Exception innerException)
      : base(message, innerException)
    {
    }

    /// <summary>
    /// Initializes the exception class with the SQLite error code.
    /// </summary>
    /// <param name="nCode">The SQLite error code</param>
    /// <param name="strMessage">A detailed error message</param>
    /// <returns>An error message string</returns>
    /// <remarks>
    /// The SQLite error code is OR'd with 0x800F0000 to generate an HResult
    /// </remarks>
    private static string Initialize(int nCode, string strMessage)
    {
      if (strMessage == null) strMessage = "";

      if (strMessage.Length > 0)
        strMessage = "\r\n" + strMessage;


      switch (nCode)
      {
        case 1:
          return "SQLite error" + strMessage;
        case 2:
          return "An internal logic error in SQLite" + strMessage;

Changes to System.Data.SQLite/SQLiteFunction.cs.

107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
...
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
...
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
...
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
...
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
...
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
...
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477

    /// <summary>
    /// Internal constructor, initializes the function's internal variables.
    /// </summary>
    protected SQLiteFunction()
    {
      _contextDataList = new SortedList<int, object>();
      _InvokeFunc = null;
      _StepFunc = null;
      _FinalFunc = null;
      _CompareFunc = null;
    }

    /// <summary>
    /// Returns a reference to the underlying connection's SQLiteConvert class, which can be used to convert
    /// strings and DateTime's into the current connection's encoding schema.
    /// </summary>
    public SQLiteConvert SQLiteConvert
................................................................................
    /// <summary>
    /// Aggregate functions override this method to do their magic.
    /// </summary>
    /// <remarks>
    /// Typically you'll be updating whatever you've placed in the contextData field and returning as quickly as possible.
    /// </remarks>
    /// <param name="args">The arguments for the command to process</param>
    /// <param name="nStep">The 1-based step number.  This is incrememted each time the step method is called.</param>
    /// <param name="contextData">A placeholder for implementers to store contextual data pertaining to the current context.</param>
    public virtual void Step(object[] args, int nStep, ref object contextData)
    {
    }

    /// <summary>
    /// Aggregate functions override this method to finish their aggregate processing.
    /// </summary>
    /// <remarks>
................................................................................
      return parms;
    }

    /// <summary>
    /// Takes the return value from Invoke() and Final() and figures out how to return it to SQLite's context.
    /// </summary>
    /// <param name="context">The context the return value applies to</param>
    /// <param name="obj">The parameter to return to SQLite</param>
    void SetReturnValue(int context, object obj)
    {
      if (obj == null || obj == DBNull.Value)
      {
        _base.ReturnNull(context);
        return;
      }

      Type t = obj.GetType();
      if (t == typeof(DateTime))
      {
        _base.ReturnText(context, _base.ToString((DateTime)obj));
        return;
      }
      else if (obj as Exception != null)
      {




        _base.ReturnError(context, ((Exception)obj).Message);
        return;

      }

      switch (SQLiteConvert.TypeToAffinity(t))
      {
        case TypeAffinity.Null:
          _base.ReturnNull(context);
          return;
        case TypeAffinity.Int64:
          _base.ReturnInt64(context, Convert.ToInt64(obj));
          return;
        case TypeAffinity.Double:
          _base.ReturnDouble(context, Convert.ToDouble(obj));
          return;
        case TypeAffinity.Text:
          _base.ReturnText(context, obj.ToString());
          return;
        case TypeAffinity.Blob:
          _base.ReturnBlob(context, (byte[])obj);
          return;
      }
    }

    /// <summary>
    /// Internal scalar callback function, which wraps the raw context pointer and calls the virtual Invoke() method.
    /// </summary>
................................................................................
      IDisposable disp = obj as IDisposable;
      if (disp != null) disp.Dispose();
    }

    /// <summary>
    /// Placeholder for a user-defined disposal routine
    /// </summary>
    /// <param name="bDisposing">True if the object is being disposed explicitly</param>
    protected virtual void Dispose(bool bDisposing)
    {
    }

    /// <summary>
    /// Disposes of any active contextData variables that were not automatically cleaned up.  Sometimes this can happen if
    /// someone closes the connection while a DataReader is open.
    /// </summary>
................................................................................
          object[] arAtt = arTypes[x].GetCustomAttributes(false);
          int u = arAtt.Length;
          for (int y = 0; y < u; y++)
          {
            at = arAtt[y] as SQLiteFunctionAttribute;
            if (at != null)
            {
              at.InstanceType = arTypes[x];
              _registeredFunctions.Add(at);
            }
          }
        }
      }
    }
#else
................................................................................
      SQLiteFunctionAttribute at;

      for (int y = 0; y < u; y++)
      {
        at = arAtt[y] as SQLiteFunctionAttribute;
        if (at != null)
        {
          at.InstanceType = typ;
          _registeredFunctions.Add(at);
        }
      }
    }
#endif

    /// <summary>
................................................................................
    internal static SQLiteFunction[] BindFunctions(SQLiteBase sqlbase)
    {
      SQLiteFunction f;
      List<SQLiteFunction> lFunctions = new List<SQLiteFunction>();

      foreach (SQLiteFunctionAttribute pr in _registeredFunctions)
      {
        f = (SQLiteFunction)Activator.CreateInstance(pr.InstanceType);
        f._base = sqlbase;
        f._InvokeFunc = (pr.FuncType == FunctionType.Scalar) ? new SQLiteCallback(f.ScalarCallback) : null;
        f._StepFunc = (pr.FuncType == FunctionType.Aggregate) ? new SQLiteCallback(f.StepCallback) : null;
        f._FinalFunc = (pr.FuncType == FunctionType.Aggregate) ? new SQLiteCallback(f.FinalCallback) : null;
        f._CompareFunc = (pr.FuncType == FunctionType.Collation) ? new SQLiteCollation(f.CompareCallback) : null;

        if (pr.FuncType != FunctionType.Collation)







<
<
<
<







 







|

|







 







|
|

|





|


|


|

>
>
>
>
|
|
>








|


|


|


|







 







|
|







 







|







 







|







 







|







107
108
109
110
111
112
113




114
115
116
117
118
119
120
...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
...
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
...
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
...
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
...
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
...
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478

    /// <summary>
    /// Internal constructor, initializes the function's internal variables.
    /// </summary>
    protected SQLiteFunction()
    {
      _contextDataList = new SortedList<int, object>();




    }

    /// <summary>
    /// Returns a reference to the underlying connection's SQLiteConvert class, which can be used to convert
    /// strings and DateTime's into the current connection's encoding schema.
    /// </summary>
    public SQLiteConvert SQLiteConvert
................................................................................
    /// <summary>
    /// Aggregate functions override this method to do their magic.
    /// </summary>
    /// <remarks>
    /// Typically you'll be updating whatever you've placed in the contextData field and returning as quickly as possible.
    /// </remarks>
    /// <param name="args">The arguments for the command to process</param>
    /// <param name="stepNumber">The 1-based step number.  This is incrememted each time the step method is called.</param>
    /// <param name="contextData">A placeholder for implementers to store contextual data pertaining to the current context.</param>
    public virtual void Step(object[] args, int stepNumber, ref object contextData)
    {
    }

    /// <summary>
    /// Aggregate functions override this method to finish their aggregate processing.
    /// </summary>
    /// <remarks>
................................................................................
      return parms;
    }

    /// <summary>
    /// Takes the return value from Invoke() and Final() and figures out how to return it to SQLite's context.
    /// </summary>
    /// <param name="context">The context the return value applies to</param>
    /// <param name="returnValue">The parameter to return to SQLite</param>
    void SetReturnValue(int context, object returnValue)
    {
      if (returnValue == null || returnValue == DBNull.Value)
      {
        _base.ReturnNull(context);
        return;
      }

      Type t = returnValue.GetType();
      if (t == typeof(DateTime))
      {
        _base.ReturnText(context, _base.ToString((DateTime)returnValue));
        return;
      }
      else
      {
        Exception r = returnValue as Exception;

        if (r != null)
        {
          _base.ReturnError(context, r.Message);
          return;
        }
      }

      switch (SQLiteConvert.TypeToAffinity(t))
      {
        case TypeAffinity.Null:
          _base.ReturnNull(context);
          return;
        case TypeAffinity.Int64:
          _base.ReturnInt64(context, Convert.ToInt64(returnValue));
          return;
        case TypeAffinity.Double:
          _base.ReturnDouble(context, Convert.ToDouble(returnValue));
          return;
        case TypeAffinity.Text:
          _base.ReturnText(context, returnValue.ToString());
          return;
        case TypeAffinity.Blob:
          _base.ReturnBlob(context, (byte[])returnValue);
          return;
      }
    }

    /// <summary>
    /// Internal scalar callback function, which wraps the raw context pointer and calls the virtual Invoke() method.
    /// </summary>
................................................................................
      IDisposable disp = obj as IDisposable;
      if (disp != null) disp.Dispose();
    }

    /// <summary>
    /// Placeholder for a user-defined disposal routine
    /// </summary>
    /// <param name="disposing">True if the object is being disposed explicitly</param>
    protected virtual void Dispose(bool disposing)
    {
    }

    /// <summary>
    /// Disposes of any active contextData variables that were not automatically cleaned up.  Sometimes this can happen if
    /// someone closes the connection while a DataReader is open.
    /// </summary>
................................................................................
          object[] arAtt = arTypes[x].GetCustomAttributes(false);
          int u = arAtt.Length;
          for (int y = 0; y < u; y++)
          {
            at = arAtt[y] as SQLiteFunctionAttribute;
            if (at != null)
            {
              at._instanceType = arTypes[x];
              _registeredFunctions.Add(at);
            }
          }
        }
      }
    }
#else
................................................................................
      SQLiteFunctionAttribute at;

      for (int y = 0; y < u; y++)
      {
        at = arAtt[y] as SQLiteFunctionAttribute;
        if (at != null)
        {
          at._instanceType = typ;
          _registeredFunctions.Add(at);
        }
      }
    }
#endif

    /// <summary>
................................................................................
    internal static SQLiteFunction[] BindFunctions(SQLiteBase sqlbase)
    {
      SQLiteFunction f;
      List<SQLiteFunction> lFunctions = new List<SQLiteFunction>();

      foreach (SQLiteFunctionAttribute pr in _registeredFunctions)
      {
        f = (SQLiteFunction)Activator.CreateInstance(pr._instanceType);
        f._base = sqlbase;
        f._InvokeFunc = (pr.FuncType == FunctionType.Scalar) ? new SQLiteCallback(f.ScalarCallback) : null;
        f._StepFunc = (pr.FuncType == FunctionType.Aggregate) ? new SQLiteCallback(f.StepCallback) : null;
        f._FinalFunc = (pr.FuncType == FunctionType.Aggregate) ? new SQLiteCallback(f.FinalCallback) : null;
        f._CompareFunc = (pr.FuncType == FunctionType.Collation) ? new SQLiteCollation(f.CompareCallback) : null;

        if (pr.FuncType != FunctionType.Collation)

Changes to System.Data.SQLite/SQLiteFunctionAttribute.cs.

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




















  /// <summary>
  /// A simple custom attribute to enable us to easily find user-defined functions in
  /// the loaded assemblies and initialize them in SQLite as connections are made.
  /// </summary>
  [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
  public sealed class SQLiteFunctionAttribute : Attribute
  {
    /// <summary>
    /// The function's name as it will be used in SQLite command text.
    /// </summary>
    public string       Name;
    /// <summary>
    /// The number of arguments this function expects.  -1 if the number of arguments is variable.
    /// </summary>
    public int          Arguments;
    /// <summary>
    /// The type of function this implementation will be.
    /// </summary>
    public FunctionType FuncType;

    internal Type       InstanceType;

    /// <summary>
    /// Default constructor, initializes the internal variables for the function.
    /// </summary>
    public SQLiteFunctionAttribute()
    {
      Name = "";
      Arguments = -1;
      FuncType = FunctionType.Scalar;
      InstanceType = null;
    }
  }







}



























<
<
<
|
<
<
<
|
<
<
<
|
<
|









<

|
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
  /// <summary>
  /// A simple custom attribute to enable us to easily find user-defined functions in
  /// the loaded assemblies and initialize them in SQLite as connections are made.
  /// </summary>
  [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
  public sealed class SQLiteFunctionAttribute : Attribute
  {



    private string       _name;



    private int          _arguments;



    private FunctionType _functionType;

    internal Type        _instanceType;

    /// <summary>
    /// Default constructor, initializes the internal variables for the function.
    /// </summary>
    public SQLiteFunctionAttribute()
    {
      Name = "";
      Arguments = -1;
      FuncType = FunctionType.Scalar;

    }

    /// <summary>
    /// The function's name as it will be used in SQLite command text.
    /// </summary>
    public string Name
    {
      get { return _name; }
      set { _name = value; }
    }

    /// <summary>
    /// The number of arguments this function expects.  -1 if the number of arguments is variable.
    /// </summary>
    public int Arguments
    {
      get { return _arguments; }
      set { _arguments = value; }
    }

    /// <summary>
    /// The type of function this implementation will be.
    /// </summary>
    public FunctionType FuncType
    {
      get { return _functionType; }
      set { _functionType = value; }
    }
  }
}

Changes to System.Data.SQLite/SQLiteParameter.cs.

53
54
55
56
57
58
59











60
61
62
63
64
65
66
..
95
96
97
98
99
100
101











102
103
104
105
106
107
108
...
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
...
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
    /// Constructs a named parameter given the specified parameter name
    /// </summary>
    /// <param name="parameterName">The parameter name</param>
    public SQLiteParameter(string parameterName)
    {
      Initialize(parameterName, -1, 0, null, DataRowVersion.Current);
    }












    /// <summary>
    /// Constructs a named parameter of the specified type
    /// </summary>
    /// <param name="parameterName">The parameter name</param>
    /// <param name="dbType">The datatype of the parameter</param>
    public SQLiteParameter(string parameterName, DbType dbType)
................................................................................
    /// Constructs an unnamed parameter of the specified data type
    /// </summary>
    /// <param name="dbType">The datatype of the parameter</param>
    public SQLiteParameter(DbType dbType)
    {
      Initialize(null, (int)dbType, 0, null, DataRowVersion.Current);
    }












    /// <summary>
    /// Constructs an unnamed parameter of the specified data type and source column
    /// </summary>
    /// <param name="dbType">The datatype of the parameter</param>
    /// <param name="sourceColumn">The source column</param>
    public SQLiteParameter(DbType dbType, string sourceColumn)
................................................................................
      Initialize(null, (int)dbType, 0, sourceColumn, rowVersion);
    }

    /// <summary>
    /// Constructs a named parameter of the specified type and size
    /// </summary>
    /// <param name="parameterName">The parameter name</param>
    /// <param name="dbType">The data type</param>
    /// <param name="nSize">The size of the parameter</param>
    public SQLiteParameter(string parameterName, DbType dbType, int nSize)
    {
      Initialize(parameterName, (int)dbType, nSize, null, DataRowVersion.Current);
    }

    /// <summary>
    /// Constructs a named parameter of the specified type, size and source column
    /// </summary>
    /// <param name="parameterName">The name of the parameter</param>
    /// <param name="dbType">The data type</param>
    /// <param name="nSize">The size of the parameter</param>
    /// <param name="sourceColumn">The source column</param>
    public SQLiteParameter(string parameterName, DbType dbType, int nSize, string sourceColumn)
    {
      Initialize(parameterName, (int)dbType, nSize, sourceColumn, DataRowVersion.Current);













    }

    /// <summary>
    /// Constructs a named parameter of the specified type, size, source column and row version
    /// </summary>
    /// <param name="parameterName">The name of the parameter</param>
    /// <param name="dbType">The data type</param>
    /// <param name="nSize">The size of the parameter</param>




    /// <param name="sourceColumn">The source column</param>
    /// <param name="rowVersion">The row version information</param>
    public SQLiteParameter(string parameterName, DbType dbType, int nSize, string sourceColumn, DataRowVersion rowVersion)


    {
      Initialize(parameterName, (int)dbType, nSize, sourceColumn, rowVersion);



    }

    /// <summary>
    /// Constructs an unnamed parameter of the specified type and size
    /// </summary>
    /// <param name="dbType">The data type</param>
    /// <param name="nSize">The size of the parameter</param>
    public SQLiteParameter(DbType dbType, int nSize)
    {
      Initialize(null, (int)dbType, nSize, null, DataRowVersion.Current);
    }

    /// <summary>
    /// Constructs an unnamed parameter of the specified type, size, and source column
    /// </summary>
    /// <param name="dbType">The data type</param>
    /// <param name="nSize">The size of the parameter</param>
    /// <param name="sourceColumn">The source column</param>
    public SQLiteParameter(DbType dbType, int nSize, string sourceColumn)
    {
      Initialize(null, (int)dbType, nSize, sourceColumn, DataRowVersion.Current);
    }

    /// <summary>
    /// Constructs an unnamed parameter of the specified type, size, source column and row version
    /// </summary>
    /// <param name="dbType">The data type</param>
    /// <param name="nSize">The size of the parameter</param>
    /// <param name="sourceColumn">The source column</param>
    /// <param name="rowVersion">The row version information</param>
    public SQLiteParameter(DbType dbType, int nSize, string sourceColumn, DataRowVersion rowVersion)
    {
      Initialize(null, (int)dbType, nSize, sourceColumn, rowVersion);
    }

    /// <summary>
    /// Initializes the parameter member variables
    /// </summary>
    /// <param name="parameterName">The parameter name</param>
    /// <param name="dbType">The data type</param>
    /// <param name="nSize">The size</param>
    /// <param name="sourceColumn">The source column</param>
    /// <param name="rowVersion">The row version</param>
    private void Initialize(string parameterName, int dbType, int nSize, string sourceColumn, DataRowVersion rowVersion)
    {
      _columnName = parameterName;
      _dbType = dbType;
      _sourceColumn = sourceColumn;
      _rowVersion = rowVersion;
      _objValue = null;
      _dataSize = nSize;
    }

    /// <summary>
................................................................................
      get
      {
        return ParameterDirection.Input;
      }
      set
      {
        if (value != ParameterDirection.Input)
          throw new NotImplementedException();
      }
    }

    /// <summary>
    /// Not implemented
    /// </summary>
    public override int Offset







>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>







 







|
|
|

|






|
|

|

|
>
>
>
>
>
>
>
>
>
>
>
>
>






|
|
>
>
>
>


<
>
>

|
>
>
>





|
|
|

|





|
|

|

|





|
|


|

|






|



|


|







 







|







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
...
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
...
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
...
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
    /// Constructs a named parameter given the specified parameter name
    /// </summary>
    /// <param name="parameterName">The parameter name</param>
    public SQLiteParameter(string parameterName)
    {
      Initialize(parameterName, -1, 0, null, DataRowVersion.Current);
    }

    /// <summary>
    /// Constructs a named parameter given the specified parameter name and initial value
    /// </summary>
    /// <param name="parameterName">The parameter name</param>
    /// <param name="value">The initial value of the parameter</param>
    public SQLiteParameter(string parameterName, object value)
    {
      Initialize(parameterName, -1, 0, null, DataRowVersion.Current);
      Value = value;
    }

    /// <summary>
    /// Constructs a named parameter of the specified type
    /// </summary>
    /// <param name="parameterName">The parameter name</param>
    /// <param name="dbType">The datatype of the parameter</param>
    public SQLiteParameter(string parameterName, DbType dbType)
................................................................................
    /// Constructs an unnamed parameter of the specified data type
    /// </summary>
    /// <param name="dbType">The datatype of the parameter</param>
    public SQLiteParameter(DbType dbType)
    {
      Initialize(null, (int)dbType, 0, null, DataRowVersion.Current);
    }

    /// <summary>
    /// Constructs an unnamed parameter of the specified data type and sets the initial value
    /// </summary>
    /// <param name="dbType">The datatype of the parameter</param>
    /// <param name="value">The initial value of the parameter</param>
    public SQLiteParameter(DbType dbType, object value)
    {
      Initialize(null, (int)dbType, 0, null, DataRowVersion.Current);
      Value = value;
    }

    /// <summary>
    /// Constructs an unnamed parameter of the specified data type and source column
    /// </summary>
    /// <param name="dbType">The datatype of the parameter</param>
    /// <param name="sourceColumn">The source column</param>
    public SQLiteParameter(DbType dbType, string sourceColumn)
................................................................................
      Initialize(null, (int)dbType, 0, sourceColumn, rowVersion);
    }

    /// <summary>
    /// Constructs a named parameter of the specified type and size
    /// </summary>
    /// <param name="parameterName">The parameter name</param>
    /// <param name="parameterType">The data type</param>
    /// <param name="parameterSize">The size of the parameter</param>
    public SQLiteParameter(string parameterName, DbType parameterType, int parameterSize)
    {
      Initialize(parameterName, (int)parameterType, parameterSize, null, DataRowVersion.Current);
    }

    /// <summary>
    /// Constructs a named parameter of the specified type, size and source column
    /// </summary>
    /// <param name="parameterName">The name of the parameter</param>
    /// <param name="parameterType">The data type</param>
    /// <param name="parameterSize">The size of the parameter</param>
    /// <param name="sourceColumn">The source column</param>
    public SQLiteParameter(string parameterName, DbType parameterType, int parameterSize, string sourceColumn)
    {
      Initialize(parameterName, (int)parameterType, parameterSize, sourceColumn, DataRowVersion.Current);
    }

    /// <summary>
    /// Constructs a named parameter of the specified type, size, source column and row version
    /// </summary>
    /// <param name="parameterName">The name of the parameter</param>
    /// <param name="parameterType">The data type</param>
    /// <param name="parameterSize">The size of the parameter</param>
    /// <param name="sourceColumn">The source column</param>
    /// <param name="rowVersion">The row version information</param>
    public SQLiteParameter(string parameterName, DbType parameterType, int parameterSize, string sourceColumn, DataRowVersion rowVersion)
    {
      Initialize(parameterName, (int)parameterType, parameterSize, sourceColumn, rowVersion);
    }

    /// <summary>
    /// Constructs a named parameter of the specified type, size, source column and row version
    /// </summary>
    /// <param name="parameterName">The name of the parameter</param>
    /// <param name="parameterType">The data type</param>
    /// <param name="parameterSize">The size of the parameter</param>
    /// <param name="direction">Only input parameters are supported in SQLite</param>
    /// <param name="isNullable">Ignored</param>
    /// <param name="precision">Ignored</param>
    /// <param name="scale">Ignored</param>
    /// <param name="sourceColumn">The source column</param>
    /// <param name="rowVersion">The row version information</param>

    /// <param name="value">The initial value to assign the parameter</param>
    public SQLiteParameter(string parameterName, DbType parameterType, int parameterSize, ParameterDirection direction, bool isNullable, byte precision, byte scale, string sourceColumn, DataRowVersion rowVersion, object value)
    {
      Initialize(parameterName, (int)parameterType, parameterSize, sourceColumn, rowVersion);
      Direction = direction;
      IsNullable = isNullable;
      Value = value;
    }

    /// <summary>
    /// Constructs an unnamed parameter of the specified type and size
    /// </summary>
    /// <param name="parameterType">The data type</param>
    /// <param name="parameterSize">The size of the parameter</param>
    public SQLiteParameter(DbType parameterType, int parameterSize)
    {
      Initialize(null, (int)parameterType, parameterSize, null, DataRowVersion.Current);
    }

    /// <summary>
    /// Constructs an unnamed parameter of the specified type, size, and source column
    /// </summary>
    /// <param name="parameterType">The data type</param>
    /// <param name="parameterSize">The size of the parameter</param>
    /// <param name="sourceColumn">The source column</param>
    public SQLiteParameter(DbType parameterType, int parameterSize, string sourceColumn)
    {
      Initialize(null, (int)parameterType, parameterSize, sourceColumn, DataRowVersion.Current);
    }

    /// <summary>
    /// Constructs an unnamed parameter of the specified type, size, source column and row version
    /// </summary>
    /// <param name="parameterType">The data type</param>
    /// <param name="parameterSize">The size of the parameter</param>
    /// <param name="sourceColumn">The source column</param>
    /// <param name="rowVersion">The row version information</param>
    public SQLiteParameter(DbType parameterType, int parameterSize, string sourceColumn, DataRowVersion rowVersion)
    {
      Initialize(null, (int)parameterType, parameterSize, sourceColumn, rowVersion);
    }

    /// <summary>
    /// Initializes the parameter member variables
    /// </summary>
    /// <param name="parameterName">The parameter name</param>
    /// <param name="paramType">The data type</param>
    /// <param name="nSize">The size</param>
    /// <param name="sourceColumn">The source column</param>
    /// <param name="rowVersion">The row version</param>
    private void Initialize(string parameterName, int paramType, int nSize, string sourceColumn, DataRowVersion rowVersion)
    {
      _columnName = parameterName;
      _dbType = paramType;
      _sourceColumn = sourceColumn;
      _rowVersion = rowVersion;
      _objValue = null;
      _dataSize = nSize;
    }

    /// <summary>
................................................................................
      get
      {
        return ParameterDirection.Input;
      }
      set
      {
        if (value != ParameterDirection.Input)
          throw new NotSupportedException();
      }
    }

    /// <summary>
    /// Not implemented
    /// </summary>
    public override int Offset

Changes to System.Data.SQLite/SQLiteParameterCollection.cs.

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
...
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
    {
      return _parameterList.GetEnumerator();
    }

    /// <summary>
    /// Adds a parameter to the collection
    /// </summary>
    /// <param name="paramName">The parameter name</param>
    /// <param name="dbType">The data type</param>
    /// <param name="nSize">The size of the value</param>
    /// <param name="sourceColumn">The source column</param>
    /// <returns>A SQLiteParameter object</returns>
    public SQLiteParameter Add(string paramName, DbType dbType, int nSize, string sourceColumn)
    {
      SQLiteParameter param = new SQLiteParameter(paramName, dbType, nSize, sourceColumn);
      Add(param);

      return param;
    }

    /// <summary>
    /// Adds a parameter to the collection
    /// </summary>
    /// <param name="paramName">The parameter name</param>
    /// <param name="dbType">The data type</param>
    /// <param name="nSize">The size of the value</param>
    /// <returns>A SQLiteParameter object</returns>
    public SQLiteParameter Add(string paramName, DbType dbType, int nSize)
    {
      SQLiteParameter param = new SQLiteParameter(paramName, dbType, nSize);
      Add(param);

      return param;
    }

    /// <summary>
    /// Adds a parameter to the collection
    /// </summary>
    /// <param name="paramName">The parameter name</param>
    /// <param name="dbType">The data type</param>
    /// <returns>A SQLiteParameter object</returns>
    public SQLiteParameter Add(string paramName, DbType dbType)
    {
      SQLiteParameter param = new SQLiteParameter(paramName, dbType);
      Add(param);

      return param;
    }

    /// <summary>
    /// Adds a parameter to the collection
    /// </summary>
    /// <param name="p">The parameter to add</param>
    /// <returns>A zero-based index of where the parameter is located in the array</returns>
    public int Add(SQLiteParameter p)
    {
      int n = -1;

      if (p.ParameterName != null)
      {
        n = IndexOf(p.ParameterName);
      }

      if (n == -1)
      {
        n = _parameterList.Count;
        _parameterList.Add(p);
      }

      SetParameter(n, p);

      return n;
    }

    /// <summary>
    /// Adds a parameter to the collection
    /// </summary>
................................................................................
      _unboundFlag = true;
      _parameterList.Clear();
    }

    /// <summary>
    /// Determines if the named parameter exists in the collection
    /// </summary>
    /// <param name="value">The name of the parameter to check</param>
    /// <returns>True if the parameter is in the collection</returns>
    public override bool Contains(string value)
    {
      return (IndexOf(value) != -1);
    }

    /// <summary>
    /// Determines if the parameter exists in the collection
    /// </summary>
    /// <param name="value">The SQLiteParameter to check</param>
    /// <returns>True if the parameter is in the collection</returns>







|
|
|


|

|








|
|
|

|

|








|
|

|

|








|

|



|

|





|


|







 







|

|

|







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
...
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
    {
      return _parameterList.GetEnumerator();
    }

    /// <summary>
    /// Adds a parameter to the collection
    /// </summary>
    /// <param name="parameterName">The parameter name</param>
    /// <param name="parameterType">The data type</param>
    /// <param name="parameterSize">The size of the value</param>
    /// <param name="sourceColumn">The source column</param>
    /// <returns>A SQLiteParameter object</returns>
    public SQLiteParameter Add(string parameterName, DbType parameterType, int parameterSize, string sourceColumn)
    {
      SQLiteParameter param = new SQLiteParameter(parameterName, parameterType, parameterSize, sourceColumn);
      Add(param);

      return param;
    }

    /// <summary>
    /// Adds a parameter to the collection
    /// </summary>
    /// <param name="parameterName">The parameter name</param>
    /// <param name="parameterType">The data type</param>
    /// <param name="parameterSize">The size of the value</param>
    /// <returns>A SQLiteParameter object</returns>
    public SQLiteParameter Add(string parameterName, DbType parameterType, int parameterSize)
    {
      SQLiteParameter param = new SQLiteParameter(parameterName, parameterType, parameterSize);
      Add(param);

      return param;
    }

    /// <summary>
    /// Adds a parameter to the collection
    /// </summary>
    /// <param name="parameterName">The parameter name</param>
    /// <param name="parameterType">The data type</param>
    /// <returns>A SQLiteParameter object</returns>
    public SQLiteParameter Add(string parameterName, DbType parameterType)
    {
      SQLiteParameter param = new SQLiteParameter(parameterName, parameterType);
      Add(param);

      return param;
    }

    /// <summary>
    /// Adds a parameter to the collection
    /// </summary>
    /// <param name="parameter">The parameter to add</param>
    /// <returns>A zero-based index of where the parameter is located in the array</returns>
    public int Add(SQLiteParameter parameter)
    {
      int n = -1;

      if (parameter.ParameterName != null)
      {
        n = IndexOf(parameter.ParameterName);
      }

      if (n == -1)
      {
        n = _parameterList.Count;
        _parameterList.Add(parameter);
      }

      SetParameter(n, parameter);

      return n;
    }

    /// <summary>
    /// Adds a parameter to the collection
    /// </summary>
................................................................................
      _unboundFlag = true;
      _parameterList.Clear();
    }

    /// <summary>
    /// Determines if the named parameter exists in the collection
    /// </summary>
    /// <param name="parameterName">The name of the parameter to check</param>
    /// <returns>True if the parameter is in the collection</returns>
    public override bool Contains(string parameterName)
    {
      return (IndexOf(parameterName) != -1);
    }

    /// <summary>
    /// Determines if the parameter exists in the collection
    /// </summary>
    /// <param name="value">The SQLiteParameter to check</param>
    /// <returns>True if the parameter is in the collection</returns>

Changes to System.Data.SQLite/SQLiteStatement.cs.

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
..
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
...
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
    /// </summary>
    /// <param name="sqlbase">The base SQLite object</param>
    /// <param name="stmt">The statement</param>
    /// <param name="strCommand">The command text for this statement</param>
    /// <param name="nCmdStart">The index at which to start numbering unnamed parameters</param>
    internal SQLiteStatement(SQLiteBase sqlbase, int stmt, string strCommand, ref int nCmdStart)
    {
      _paramNames = null;
      _paramValues = null;
      _command = null;

      _unnamedParameterStart   = nCmdStart;
      _sql     = sqlbase;
      _sqlite_stmt = stmt;
      _sqlStatement  = strCommand;

      // Determine parameters for this statement (if any) and prepare space for them.
      int n = _sql.Bind_ParamCount(this);
................................................................................
      {
        _paramNames = new string[n];
        _paramValues = new SQLiteParameter[n];

        for (x = 0; x < n; x++)
        {
          s = _sql.Bind_ParamName(this, x + 1);
          if (s == null || s == "")
          {
            s = String.Format(";{0}", nCmdStart);
            nCmdStart++;
          }
          _paramNames[x] = s;
          _paramValues[x] = null;
        }
................................................................................

    #region IDisposable Members
    /// <summary>
    /// Disposes and finalizes the statement
    /// </summary>
    public void Dispose()
    {
      _sql.Finalize(this);
      
      _paramNames = null;
      _paramValues = null;
      _sql = null;
      _sqlStatement = null;

      GC.SuppressFinalize(this);







<
<
<
<







 







|







 







|







49
50
51
52
53
54
55




56
57
58
59
60
61
62
..
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
    /// </summary>
    /// <param name="sqlbase">The base SQLite object</param>
    /// <param name="stmt">The statement</param>
    /// <param name="strCommand">The command text for this statement</param>
    /// <param name="nCmdStart">The index at which to start numbering unnamed parameters</param>
    internal SQLiteStatement(SQLiteBase sqlbase, int stmt, string strCommand, ref int nCmdStart)
    {




      _unnamedParameterStart   = nCmdStart;
      _sql     = sqlbase;
      _sqlite_stmt = stmt;
      _sqlStatement  = strCommand;

      // Determine parameters for this statement (if any) and prepare space for them.
      int n = _sql.Bind_ParamCount(this);
................................................................................
      {
        _paramNames = new string[n];
        _paramValues = new SQLiteParameter[n];

        for (x = 0; x < n; x++)
        {
          s = _sql.Bind_ParamName(this, x + 1);
          if (String.IsNullOrEmpty(s))
          {
            s = String.Format(";{0}", nCmdStart);
            nCmdStart++;
          }
          _paramNames[x] = s;
          _paramValues[x] = null;
        }
................................................................................

    #region IDisposable Members
    /// <summary>
    /// Disposes and finalizes the statement
    /// </summary>
    public void Dispose()
    {
      _sql.FinalizeStatement(this);
      
      _paramNames = null;
      _paramValues = null;
      _sql = null;
      _sqlStatement = null;

      GC.SuppressFinalize(this);

Changes to System.Data.SQLite/SQLiteTransaction.cs.

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
..
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
..
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
  /// SQLite implementation of DbTransaction.
  /// </summary>
  public sealed class SQLiteTransaction : DbTransaction
  {
    /// <summary>
    /// The connection to which this transaction is bound
    /// </summary>
    private SQLiteConnection _cnn;

    /// <summary>
    /// Constructs the transaction object, binding it to the supplied connection
    /// </summary>
    /// <param name="cnn">The connection to open a transaction on</param>
    internal SQLiteTransaction(SQLiteConnection cnn)
    {
      try
      {
        cnn._sql.Execute("BEGIN");
        _cnn = cnn;
      }
      catch (SQLiteException e)
      {
        BaseDispose();
        throw (e);
      }
    }

    /// <summary>
    /// Commits the current transaction.
    /// </summary>
    public override void Commit()
................................................................................
      if (_cnn == null)
        throw new ArgumentNullException();

      try
      {
        _cnn._sql.Execute("COMMIT");
      }
      catch (SQLiteException e)
      {
        BaseDispose();
        throw (e);
      }
      BaseDispose();
    }

    /// <summary>
    /// Returns the underlying connection to which this transaction applies.
    /// </summary>
................................................................................
      if (_cnn == null)
        throw new ArgumentNullException();

      try
      {
        _cnn._sql.Execute("ROLLBACK");
      }
      catch (SQLiteException e)
      {
        BaseDispose();
        throw (e);
      }
      BaseDispose();
    }

    private void BaseDispose()
    {
      _cnn._activeTransaction = null;
      _cnn = null;
    }
  }
}







|












|


|







 







|


|







 







|


|











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
..
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
..
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
  /// SQLite implementation of DbTransaction.
  /// </summary>
  public sealed class SQLiteTransaction : DbTransaction
  {
    /// <summary>
    /// The connection to which this transaction is bound
    /// </summary>
    internal SQLiteConnection _cnn;

    /// <summary>
    /// Constructs the transaction object, binding it to the supplied connection
    /// </summary>
    /// <param name="cnn">The connection to open a transaction on</param>
    internal SQLiteTransaction(SQLiteConnection cnn)
    {
      try
      {
        cnn._sql.Execute("BEGIN");
        _cnn = cnn;
      }
      catch (SQLiteException)
      {
        BaseDispose();
        throw;
      }
    }

    /// <summary>
    /// Commits the current transaction.
    /// </summary>
    public override void Commit()
................................................................................
      if (_cnn == null)
        throw new ArgumentNullException();

      try
      {
        _cnn._sql.Execute("COMMIT");
      }
      catch (SQLiteException)
      {
        BaseDispose();
        throw;
      }
      BaseDispose();
    }

    /// <summary>
    /// Returns the underlying connection to which this transaction applies.
    /// </summary>
................................................................................
      if (_cnn == null)
        throw new ArgumentNullException();

      try
      {
        _cnn._sql.Execute("ROLLBACK");
      }
      catch (SQLiteException)
      {
        BaseDispose();
        throw;
      }
      BaseDispose();
    }

    private void BaseDispose()
    {
      _cnn._activeTransaction = null;
      _cnn = null;
    }
  }
}

Changes to System.Data.SQLite/System.Data.SQLite.csproj.

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
    <OutputPath>..\bin\CompactFramework\</OutputPath>
    <DefineConstants>TRACE;DEBUG;PocketPC;PLATFORM_COMPACTFRAMEWORK</DefineConstants>
    <NoStdLib>true</NoStdLib>
    <NoConfig>true</NoConfig>
    <ErrorReport>prompt</ErrorReport>
    <FileAlignment>512</FileAlignment>
    <WarningLevel>4</WarningLevel>

  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>none</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>..\bin\CompactFramework\</OutputPath>
    <DefineConstants>PocketPC;PLATFORM_COMPACTFRAMEWORK</DefineConstants>
    <NoStdLib>true</NoStdLib>
    <NoConfig>true</NoConfig>
    <ErrorReport>prompt</ErrorReport>
    <FileAlignment>512</FileAlignment>
    <WarningLevel>4</WarningLevel>
    <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
    <FxCopRules>
    </FxCopRules>
    <AllowUnsafeBlocks>false</AllowUnsafeBlocks>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="mscorlib" />
    <Reference Include="System">
      <Private>False</Private>
    </Reference>







>












<
<







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
    <OutputPath>..\bin\CompactFramework\</OutputPath>
    <DefineConstants>TRACE;DEBUG;PocketPC;PLATFORM_COMPACTFRAMEWORK</DefineConstants>
    <NoStdLib>true</NoStdLib>
    <NoConfig>true</NoConfig>
    <ErrorReport>prompt</ErrorReport>
    <FileAlignment>512</FileAlignment>
    <WarningLevel>4</WarningLevel>
    <DocumentationFile>..\Doc\System.Data.SQLite.XML</DocumentationFile>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>none</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>..\bin\CompactFramework\</OutputPath>
    <DefineConstants>PocketPC;PLATFORM_COMPACTFRAMEWORK</DefineConstants>
    <NoStdLib>true</NoStdLib>
    <NoConfig>true</NoConfig>
    <ErrorReport>prompt</ErrorReport>
    <FileAlignment>512</FileAlignment>
    <WarningLevel>4</WarningLevel>
    <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>


    <AllowUnsafeBlocks>false</AllowUnsafeBlocks>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="mscorlib" />
    <Reference Include="System">
      <Private>False</Private>
    </Reference>

Changes to System.Data.SQLite/UnsafeNativeMethods.cs.

10
11
12
13
14
15
16
17
18
19
20
21
22
23




24
25
26
27
28
29
30
  using System;
  using System.Security;
  using System.Runtime.InteropServices;

#if !PLATFORM_COMPACTFRAMEWORK
  [SuppressUnmanagedCodeSecurity]
#endif
  internal class UnsafeNativeMethods
  {
#if !PLATFORM_COMPACTFRAMEWORK
    private const string SQLITE_DLL = "System.Data.SQLite.DLL";
#else
    private const string SQLITE_DLL = "SQLite.Interop.DLL";
#endif





    [DllImport("kernel32.dll")]
    internal static extern void Sleep(uint dwMilliseconds);

    [DllImport(SQLITE_DLL)]
    internal static extern IntPtr sqlite3_libversion_interop(out int len);








|

|




>
>
>
>







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
  using System;
  using System.Security;
  using System.Runtime.InteropServices;

#if !PLATFORM_COMPACTFRAMEWORK
  [SuppressUnmanagedCodeSecurity]
#endif
  internal sealed class UnsafeNativeMethods
  {
#if !PLATFORM_COMPACTFRAMEWORK && !USE_INTEROP_DLL
    private const string SQLITE_DLL = "System.Data.SQLite.DLL";
#else
    private const string SQLITE_DLL = "SQLite.Interop.DLL";
#endif

    private UnsafeNativeMethods()
    {
    }

    [DllImport("kernel32.dll")]
    internal static extern void Sleep(uint dwMilliseconds);

    [DllImport(SQLITE_DLL)]
    internal static extern IntPtr sqlite3_libversion_interop(out int len);

Changes to bin/CompactFramework/SQLite.Interop.dll.

cannot compute difference between binary files

Changes to bin/CompactFramework/System.Data.SQLite.dll.

cannot compute difference between binary files

Changes to bin/CompactFramework/testce.exe.

cannot compute difference between binary files

Changes to bin/System.Data.SQLite.dll.

cannot compute difference between binary files

Changes to bin/test.exe.

cannot compute difference between binary files