System.Data.SQLite
Check-in [5973dcfa17]
Not logged in

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

Overview
Comment:Integrate the new custom database type callbacks into the statement class. Add TypeName property to the SQLiteParameter class and make use of it. Add UseParameterDbTypeForTypeName connection flag. Update version history docs.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | customDataTypes
Files: files | file ages | folders
SHA1: 5973dcfa17bca38c05578bdd20d31053ebf5f564
User & Date: mistachkin 2016-06-19 03:40:40
Context
2016-06-19
03:44
Improve comments. check-in: 410f1fa7fc user: mistachkin tags: customDataTypes
03:40
Integrate the new custom database type callbacks into the statement class. Add TypeName property to the SQLiteParameter class and make use of it. Add UseParameterDbTypeForTypeName connection flag. Update version history docs. check-in: 5973dcfa17 user: mistachkin tags: customDataTypes
03:06
Minor reordering of conditionals in the InvokeReadValueCallback method. check-in: 5804b32b6d user: mistachkin tags: customDataTypes
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Doc/Extra/Provider/version.html.

44
45
46
47
48
49
50


51
52
53
54
55
56
57
    <div id="mainBody">
    <h1 class="heading">Version History</h1>
    <p><b>1.0.102.0 - June XX, 2016 <font color="red">(release scheduled)</font></b></p>
    <ul>
      <li>Updated to <a href="https://www.sqlite.org/releaselog/3_13_0.html">SQLite 3.13.0</a>.</li>
      <li>Update the SQLiteConnection.EnableExtensions method to make use of the new SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION option, when available.&nbsp;<b>** Potentially Incompatible Change **</b></li>
      <li>Prevent the SQLiteCommand.ExecuteScalar method from throwing an exception when there are no result columns.&nbsp;<b>** Potentially Incompatible Change **</b></li>


      <li>Add VerifyOnly method to the SQLiteCommand class.</li>
      <li>Add IsReadOnly method to the SQLiteConnection class.</li>
    </ul>
    <p><b>1.0.101.0 - April 19, 2016</b></p>
    <ul>
      <li>Updated to <a href="https://www.sqlite.org/releaselog/3_12_2.html">SQLite 3.12.2</a>.</li>
      <li>Add binary package release for Mono on POSIX.</li>







>
>







44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
    <div id="mainBody">
    <h1 class="heading">Version History</h1>
    <p><b>1.0.102.0 - June XX, 2016 <font color="red">(release scheduled)</font></b></p>
    <ul>
      <li>Updated to <a href="https://www.sqlite.org/releaselog/3_13_0.html">SQLite 3.13.0</a>.</li>
      <li>Update the SQLiteConnection.EnableExtensions method to make use of the new SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION option, when available.&nbsp;<b>** Potentially Incompatible Change **</b></li>
      <li>Prevent the SQLiteCommand.ExecuteScalar method from throwing an exception when there are no result columns.&nbsp;<b>** Potentially Incompatible Change **</b></li>
      <li>Support per-connection customization for binding parameters and reading values, based on the database type name.</li>
      <li>Add TypeName property to the SQLiteParameter class.</li>
      <li>Add VerifyOnly method to the SQLiteCommand class.</li>
      <li>Add IsReadOnly method to the SQLiteConnection class.</li>
    </ul>
    <p><b>1.0.101.0 - April 19, 2016</b></p>
    <ul>
      <li>Updated to <a href="https://www.sqlite.org/releaselog/3_12_2.html">SQLite 3.12.2</a>.</li>
      <li>Add binary package release for Mono on POSIX.</li>

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

1165
1166
1167
1168
1169
1170
1171







1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
      /// <see cref="SQLiteBindValueCallback" /> values.  Also see the
      /// <see cref="SQLiteConnection.ClearTypeCallbacks" />,
      /// <see cref="SQLiteConnection.TryGetTypeCallbacks" />, and
      /// <see cref="SQLiteConnection.SetTypeCallbacks" /> methods.
      /// </summary>
      UseConnectionBindValueCallbacks = 0x400000000,








      /// <summary>
      /// Enable using per-connection mappings between type names and
      /// <see cref="SQLiteReadValueCallback" /> values.  Also see the
      /// <see cref="SQLiteConnection.ClearTypeCallbacks" />,
      /// <see cref="SQLiteConnection.TryGetTypeCallbacks" />, and
      /// <see cref="SQLiteConnection.SetTypeCallbacks" /> methods.
      /// </summary>
      UseConnectionReadValueCallbacks = 0x800000000,

      /// <summary>
      /// When binding parameter values or returning column values, always
      /// treat them as though they were plain text (i.e. no numeric,
      /// date/time, or other conversions should be attempted).
      /// </summary>
      BindAndGetAllAsText = BindAllAsText | GetAllAsText,







>
>
>
>
>
>
>







|







1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
      /// <see cref="SQLiteBindValueCallback" /> values.  Also see the
      /// <see cref="SQLiteConnection.ClearTypeCallbacks" />,
      /// <see cref="SQLiteConnection.TryGetTypeCallbacks" />, and
      /// <see cref="SQLiteConnection.SetTypeCallbacks" /> methods.
      /// </summary>
      UseConnectionBindValueCallbacks = 0x400000000,

      /// <summary>
      /// If the database type name has not been explicitly set for the
      /// parameter specified, fallback to using the database type name
      /// associated with the <see cref="DbType" /> value.
      /// </summary>
      UseParameterDbTypeForTypeName = 0x800000000,

      /// <summary>
      /// Enable using per-connection mappings between type names and
      /// <see cref="SQLiteReadValueCallback" /> values.  Also see the
      /// <see cref="SQLiteConnection.ClearTypeCallbacks" />,
      /// <see cref="SQLiteConnection.TryGetTypeCallbacks" />, and
      /// <see cref="SQLiteConnection.SetTypeCallbacks" /> methods.
      /// </summary>
      UseConnectionReadValueCallbacks = 0x1000000000,

      /// <summary>
      /// When binding parameter values or returning column values, always
      /// treat them as though they were plain text (i.e. no numeric,
      /// date/time, or other conversions should be attempted).
      /// </summary>
      BindAndGetAllAsText = BindAllAsText | GetAllAsText,

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

539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
...
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
      /// <see cref="ReadValueUserData" /> property.
      /// </summary>
      private object readValueUserData;
      #endregion

      /////////////////////////////////////////////////////////////////////////

      #region Private Constructors
      /// <summary>
      /// Constructs an instance of this class.
      /// </summary>
      /// <param name="typeName">
      /// The database type name that the callbacks contained in this class
      /// will apply to.  This parameter may not be null.
      /// </param>
................................................................................
      /// The extra data to pass into the parameter binding callback.  This
      /// parameter may be null.
      /// </param>
      /// <param name="readValueUserData">
      /// The extra data to pass into the data reader value callback.  This
      /// parameter may be null.
      /// </param>
      internal SQLiteTypeCallbacks(
          string typeName,
          SQLiteBindValueCallback bindValueCallback,
          SQLiteReadValueCallback readValueCallback,
          object bindValueUserData,
          object readValueUserData
          )
      {







|







 







|







539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
...
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
      /// <see cref="ReadValueUserData" /> property.
      /// </summary>
      private object readValueUserData;
      #endregion

      /////////////////////////////////////////////////////////////////////////

      #region Public Constructors
      /// <summary>
      /// Constructs an instance of this class.
      /// </summary>
      /// <param name="typeName">
      /// The database type name that the callbacks contained in this class
      /// will apply to.  This parameter may not be null.
      /// </param>
................................................................................
      /// The extra data to pass into the parameter binding callback.  This
      /// parameter may be null.
      /// </param>
      /// <param name="readValueUserData">
      /// The extra data to pass into the data reader value callback.  This
      /// parameter may be null.
      /// </param>
      public SQLiteTypeCallbacks(
          string typeName,
          SQLiteBindValueCallback bindValueCallback,
          SQLiteReadValueCallback readValueCallback,
          object bindValueUserData,
          object readValueUserData
          )
      {

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

50
51
52
53
54
55
56





57
58
59
60
61
62
63
...
472
473
474
475
476
477
478















479
480
481
482
483
484
485
486
487
488
489
490
491
    /// The data size, unused by SQLite
    /// </summary>
    private int            _dataSize;

    private bool           _nullable;
    private bool           _nullMapping;






    /// <summary>
    /// Constructor used when creating for use with a specific command.
    /// </summary>
    /// <param name="command">
    /// The command associated with this parameter.
    /// </param>
    internal SQLiteParameter(
................................................................................
      set
      {
        _objValue = value;
        if (_dbType == UnknownDbType && _objValue != null && _objValue != DBNull.Value) // If the DbType has never been assigned, try to glean one from the value's datatype
          _dbType = SQLiteConvert.TypeToDbType(_objValue.GetType());
      }
    }
















    /// <summary>
    /// Clones a parameter
    /// </summary>
    /// <returns>A new, unassociated SQLiteParameter</returns>
    public object Clone()
    {
      SQLiteParameter newparam = new SQLiteParameter(this);

      return newparam;
    }
  }
}







>
>
>
>
>







 







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













50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
...
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
    /// The data size, unused by SQLite
    /// </summary>
    private int            _dataSize;

    private bool           _nullable;
    private bool           _nullMapping;

    /// <summary>
    /// The database type name associated with this parameter, if any.
    /// </summary>
    private string         _typeName;

    /// <summary>
    /// Constructor used when creating for use with a specific command.
    /// </summary>
    /// <param name="command">
    /// The command associated with this parameter.
    /// </param>
    internal SQLiteParameter(
................................................................................
      set
      {
        _objValue = value;
        if (_dbType == UnknownDbType && _objValue != null && _objValue != DBNull.Value) // If the DbType has never been assigned, try to glean one from the value's datatype
          _dbType = SQLiteConvert.TypeToDbType(_objValue.GetType());
      }
    }

    /// <summary>
    /// The database type name associated with this parameter, if any.
    /// </summary>
    public string TypeName
    {
        get
        {
            return _typeName;
        }
        set
        {
            _typeName = value;
        }
    }

    /// <summary>
    /// Clones a parameter
    /// </summary>
    /// <returns>A new, unassociated SQLiteParameter</returns>
    public object Clone()
    {
      SQLiteParameter newparam = new SQLiteParameter(this);

      return newparam;
    }
  }
}

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

233
234
235
236
237
238
239
240
241






















































































































242
243
244
245
246
247
248
249










250
251
252
253
254
255
256

      int x = _paramNames.Length;
      for (int n = 0; n < x; n++)
      {
        BindParameter(n + 1, _paramValues[n]);
      }
    }

    /// <summary>






















































































































    /// Perform the bind operation for an individual parameter
    /// </summary>
    /// <param name="index">The index of the parameter to bind</param>
    /// <param name="param">The parameter we're binding</param>
    private void BindParameter(int index, SQLiteParameter param)
    {
      if (param == null)
        throw new SQLiteException("Insufficient parameters supplied to the command");











      object obj = param.Value;
      DbType objType = param.DbType;

      if ((obj != null) && (objType == DbType.Object))
          objType = SQLiteConvert.TypeToDbType(obj.GetType());










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








>
>
>
>
>
>
>
>
>
>







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

      int x = _paramNames.Length;
      for (int n = 0; n < x; n++)
      {
        BindParameter(n + 1, _paramValues[n]);
      }
    }

    /// <summary>
    /// This method attempts to query the database connection associated with
    /// the statement in use.  If the underlying command or connection is
    /// unavailable, a null value will be returned.
    /// </summary>
    /// <returns>
    /// The connection object -OR- null if it is unavailable.
    /// </returns>
    private static SQLiteConnection GetConnection(
        SQLiteStatement statement
        )
    {
        try
        {
            if (statement != null)
            {
                SQLiteCommand command = statement._command;

                if (command != null)
                {
                    SQLiteConnection connection = command.Connection;

                    if (connection != null)
                        return connection;
                }
            }
        }
        catch (ObjectDisposedException)
        {
            // do nothing.
        }

        return null;
    }

    /// <summary>
    /// Invokes the parameter binding callback configured for the database
    /// type name associated with the specified column.  If no parameter
    /// binding callback is available for the database type name, do
    /// nothing.
    /// </summary>
    /// <param name="index">
    /// The index of the column being read.
    /// </param>
    /// <param name="parameter">
    /// The <see cref="SQLiteParameter" /> instance being bound to the
    /// command.
    /// </param>
    /// <param name="complete">
    /// Non-zero if the default handling for the parameter binding call
    /// should be skipped.
    /// </param>
    private void InvokeBindValueCallback(
        int index,
        SQLiteParameter parameter,
        out bool complete
        )
    {
        complete = false;
        _flags &= ~SQLiteConnectionFlags.UseConnectionBindValueCallbacks;

        try
        {
            if (parameter == null)
                return;

            SQLiteConnection connection = GetConnection(this);

            if (connection == null)
                return;

            string typeName = parameter.TypeName;

            if (typeName == null)
            {
                //
                // NOTE: Are we allowed to fallback to using the database type
                //       name translated from the DbType?  If not, there is
                //       nothing else we can do.
                //
                if ((_flags & SQLiteConnectionFlags.UseParameterDbTypeForTypeName)
                        != SQLiteConnectionFlags.UseParameterDbTypeForTypeName)
                {
                    return;
                }

                typeName = SQLiteConvert.DbTypeToTypeName(
                    connection, parameter.DbType, _flags);
            }

            if (typeName == null)
                return;

            SQLiteTypeCallbacks callbacks;

            if (!connection.TryGetTypeCallbacks(typeName, out callbacks) ||
                (callbacks == null))
            {
                return;
            }

            SQLiteBindValueCallback callback = callbacks.BindValueCallback;

            if (callback == null)
                return;

            object userData = callbacks.BindValueUserData;

            callback(
                _sql, _command, _flags, parameter, index, userData,
                out complete); /* throw */
        }
        finally
        {
            _flags |= SQLiteConnectionFlags.UseConnectionBindValueCallbacks;
        }
    }

    /// <summary>
    /// Perform the bind operation for an individual parameter
    /// </summary>
    /// <param name="index">The index of the parameter to bind</param>
    /// <param name="param">The parameter we're binding</param>
    private void BindParameter(int index, SQLiteParameter param)
    {
      if (param == null)
        throw new SQLiteException("Insufficient parameters supplied to the command");

      if ((_flags & SQLiteConnectionFlags.UseConnectionBindValueCallbacks) == SQLiteConnectionFlags.UseConnectionBindValueCallbacks)
      {
          bool complete;

          InvokeBindValueCallback(index, param, out complete);

          if (complete)
              return;
      }

      object obj = param.Value;
      DbType objType = param.DbType;

      if ((obj != null) && (objType == DbType.Object))
          objType = SQLiteConvert.TypeToDbType(obj.GetType());

Changes to readme.htm.

211
212
213
214
215
216
217


218
219
220
221
222
223
224
<p>
    <b>1.0.102.0 - June XX, 2016 <font color="red">(release scheduled)</font></b>
</p>
<ul>
    <li>Updated to <a href="https://www.sqlite.org/releaselog/3_13_0.html">SQLite 3.13.0</a>.</li>
    <li>Update the SQLiteConnection.EnableExtensions method to make use of the new SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION option, when available.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Prevent the SQLiteCommand.ExecuteScalar method from throwing an exception when there are no result columns.&nbsp;<b>** Potentially Incompatible Change **</b></li>


    <li>Add VerifyOnly method to the SQLiteCommand class.</li>
    <li>Add IsReadOnly method to the SQLiteConnection class.</li>
</ul>
<p>
    <b>1.0.101.0 - April 19, 2016</b>
</p>
<ul>







>
>







211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<p>
    <b>1.0.102.0 - June XX, 2016 <font color="red">(release scheduled)</font></b>
</p>
<ul>
    <li>Updated to <a href="https://www.sqlite.org/releaselog/3_13_0.html">SQLite 3.13.0</a>.</li>
    <li>Update the SQLiteConnection.EnableExtensions method to make use of the new SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION option, when available.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Prevent the SQLiteCommand.ExecuteScalar method from throwing an exception when there are no result columns.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Support per-connection customization for binding parameters and reading values, based on the database type name.</li>
    <li>Add TypeName property to the SQLiteParameter class.</li>
    <li>Add VerifyOnly method to the SQLiteCommand class.</li>
    <li>Add IsReadOnly method to the SQLiteConnection class.</li>
</ul>
<p>
    <b>1.0.101.0 - April 19, 2016</b>
</p>
<ul>

Changes to www/news.wiki.

5
6
7
8
9
10
11


12
13
14
15
16
17
18
<p>
    <b>1.0.102.0 - June XX, 2016 <font color="red">(release scheduled)</font></b>
</p>
<ul>
    <li>Updated to [https://www.sqlite.org/releaselog/3_13_0.html|SQLite 3.13.0].</li>
    <li>Update the SQLiteConnection.EnableExtensions method to make use of the new SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION option, when available.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Prevent the SQLiteCommand.ExecuteScalar method from throwing an exception when there are no result columns.&nbsp;<b>** Potentially Incompatible Change **</b></li>


    <li>Add VerifyOnly method to the SQLiteCommand class.</li>
    <li>Add IsReadOnly method to the SQLiteConnection class.</li>
</ul>
<p>
    <b>1.0.101.0 - April 19, 2016</b>
</p>
<ul>







>
>







5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<p>
    <b>1.0.102.0 - June XX, 2016 <font color="red">(release scheduled)</font></b>
</p>
<ul>
    <li>Updated to [https://www.sqlite.org/releaselog/3_13_0.html|SQLite 3.13.0].</li>
    <li>Update the SQLiteConnection.EnableExtensions method to make use of the new SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION option, when available.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Prevent the SQLiteCommand.ExecuteScalar method from throwing an exception when there are no result columns.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Support per-connection customization for binding parameters and reading values, based on the database type name.</li>
    <li>Add TypeName property to the SQLiteParameter class.</li>
    <li>Add VerifyOnly method to the SQLiteCommand class.</li>
    <li>Add IsReadOnly method to the SQLiteConnection class.</li>
</ul>
<p>
    <b>1.0.101.0 - April 19, 2016</b>
</p>
<ul>