System.Data.SQLite

Login
This project makes use of Eagle, provided by Mistachkin Systems.
Eagle: Secure Software Automation

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

Changes In Branch tkt-3c00ec5b52 Excluding Merge-Ins

This is equivalent to a diff from 32f6c0410c to b48e7cb883

2014-05-30
23:25
Add DetectTextAffinity and DetectStringType connection flags to enable automatic detection of column types, when necessary. Pursuant to [3c00ec5b52]. check-in: 58e932f761 user: mistachkin tags: trunk
2014-05-27
18:43
Expose the 'Uri' and 'FullUri' properties in the design-time dialogs. check-in: 96e1f973fa user: mistachkin tags: trunk
18:35
Merge updates from trunk. Closed-Leaf check-in: b48e7cb883 user: mistachkin tags: tkt-3c00ec5b52
18:34
Rename the script used for testing builds for Windows CE 200x. check-in: 32f6c0410c user: mistachkin tags: trunk
05:56
Add DetectStringType connection flag. check-in: 229927cfce user: mistachkin tags: tkt-3c00ec5b52
05:33
Revise how the SQLiteLog class is used in the default debug builds (i.e. when INTEROP_LOG is enabled). check-in: 1affdac144 user: mistachkin tags: trunk

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

44
45
46
47
48
49
50

51
52
53
54
55
56
57
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58







+







    <div id="mainBody">
    <h1 class="heading">Version History</h1>
    <p><b>1.0.93.0 - June XX, 2014 <font color="red">(release scheduled)</font></b></p>
    <ul>
      <li>Updated to <a href="http://www.sqlite.org/releaselog/3_8_4_3.html">SQLite 3.8.4.3</a>.</li>
      <li>Add support for mapping transaction isolation levels to their legacy default values. Pursuant to <a href="http://system.data.sqlite.org/index.html/info/56b42d99c1">[56b42d99c1]</a>.</li>
      <li>Add support for setting the default DbType and type name used for mappings on a per-connection basis. Pursuant to <a href="http://system.data.sqlite.org/index.html/info/3c00ec5b52">[3c00ec5b52]</a>.</li>
      <li>Add DetectTextAffinity and DetectStringType connection flags to enable automatic detection of column types, when necessary. Pursuant to <a href="http://system.data.sqlite.org/index.html/info/3c00ec5b52">[3c00ec5b52]</a>.</li>
      <li>Add SetChunkSize method to the SQLiteConnection class. Pursuant to [d1c008fa0a].</li>
      <li>Make the ISQLiteSchemaExtensions interface public.&nbsp;<b>** Potentially Incompatible Change **</b></li>
      <li>Have the SQLiteProviderFactory class (in the System.Data.SQLite.Linq assembly) implement the IServiceProvider interface.</li>
      <li>Fix bug in documentation generator automation that prevented some internal documentation links from working.</li>
    </ul>
    <p><b>1.0.92.0 - March 19, 2014</p>
    <ul>

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

1061
1062
1063
1064
1065
1066
1067




















1068
1069
1070
1071
1072
1073
1074
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








      /// <summary>
      /// Enable mapping of unsupported transaction isolation levels to the
      /// closest supported transaction isolation level.
      /// </summary>
      MapIsolationLevels = 0x1000000,

      /// <summary>
      /// When returning column values, attempt to detect the affinity of
      /// textual values by checking if they fully conform to those of the
      /// <see cref="TypeAffinity.Null" />,
      /// <see cref="TypeAffinity.Int64" />,
      /// <see cref="TypeAffinity.Double" />,
      /// or <see cref="TypeAffinity.DateTime" /> types.
      /// </summary>
      DetectTextAffinity = 0x2000000,

      /// <summary>
      /// When returning column values, attempt to detect the type of
      /// string values by checking if they fully conform to those of
      /// the <see cref="TypeAffinity.Null" />,
      /// <see cref="TypeAffinity.Int64" />,
      /// <see cref="TypeAffinity.Double" />,
      /// or <see cref="TypeAffinity.DateTime" /> types.
      /// </summary>
      DetectStringType = 0x4000000,

      /// <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/SQLiteConvert.cs.

1313
1314
1315
1316
1317
1318
1319


























1320
1321
1322
1323
1324
1325
1326
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







            new SQLiteDbTypeMapping("UNSIGNEDINTEGER64", DbType.UInt64, false),
            new SQLiteDbTypeMapping("VARBINARY", DbType.Binary, false),
            new SQLiteDbTypeMapping("VARCHAR", DbType.AnsiString, true),
            new SQLiteDbTypeMapping("VARCHAR2", DbType.AnsiString, false),
            new SQLiteDbTypeMapping("YESNO", DbType.Boolean, false)
        });
    }

    /// <summary>
    /// Determines if a database type is considered to be a string.
    /// </summary>
    /// <param name="type">
    /// The database type to check.
    /// </param>
    /// <returns>
    /// Non-zero if the database type is considered to be a string, zero
    /// otherwise.
    /// </returns>
    internal static bool IsStringDbType(
        DbType type
        )
    {
        switch (type)
        {
            case DbType.AnsiString:
            case DbType.String:
            case DbType.AnsiStringFixedLength:
            case DbType.StringFixedLength:
                return true;
            default:
                return false;
        }
    }

    /// <summary>
    /// Determines the default <see cref="DbType" /> value to be used when a
    /// per-connection value is not available.
    /// </summary>
    /// <returns>
    /// The default <see cref="DbType" /> value to use.
1337
1338
1339
1340
1341
1342
1343













































































































































1344
1345
1346
1347
1348
1349
1350
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







            typeof(DbType), value, true);

        if (!(enumValue is DbType))
            return FallbackDefaultDbType;

        return (DbType)enumValue;
    }

    /// <summary>
    /// Determines if the specified textual value appears to be a
    /// <see cref="DBNull" /> value.
    /// </summary>
    /// <param name="text">
    /// The textual value to inspect.
    /// </param>
    /// <returns>
    /// Non-zero if the text looks like a <see cref="DBNull" /> value,
    /// zero otherwise.
    /// </returns>
    internal static bool LooksLikeNull(
        string text
        )
    {
        return (text == null);
    }

    /// <summary>
    /// Determines if the specified textual value appears to be an
    /// <see cref="Int64" /> value.
    /// </summary>
    /// <param name="text">
    /// The textual value to inspect.
    /// </param>
    /// <returns>
    /// Non-zero if the text looks like an <see cref="Int64" /> value,
    /// zero otherwise.
    /// </returns>
    internal static bool LooksLikeInt64(
        string text
        )
    {
        long longValue;

#if !PLATFORM_COMPACTFRAMEWORK
        if (!long.TryParse(
                text, NumberStyles.Integer, CultureInfo.InvariantCulture,
                out longValue))
        {
            return false;
        }
#else
        try
        {
            longValue = long.Parse(
                text, NumberStyles.Integer, CultureInfo.InvariantCulture);
        }
        catch
        {
            return false;
        }
#endif

        return String.Equals(
            longValue.ToString(CultureInfo.InvariantCulture), text,
            StringComparison.Ordinal);
    }

    /// <summary>
    /// Determines if the specified textual value appears to be a
    /// <see cref="Double" /> value.
    /// </summary>
    /// <param name="text">
    /// The textual value to inspect.
    /// </param>
    /// <returns>
    /// Non-zero if the text looks like a <see cref="Double" /> value,
    /// zero otherwise.
    /// </returns>
    internal static bool LooksLikeDouble(
        string text
        )
    {
        double doubleValue;

#if !PLATFORM_COMPACTFRAMEWORK
        if (!double.TryParse(
                text, NumberStyles.Float | NumberStyles.AllowThousands,
                CultureInfo.InvariantCulture, out doubleValue))
        {
            return false;
        }
#else
        try
        {
            doubleValue = double.Parse(text, CultureInfo.InvariantCulture);
        }
        catch
        {
            return false;
        }
#endif

        return String.Equals(
            doubleValue.ToString(CultureInfo.InvariantCulture), text,
            StringComparison.Ordinal);
    }

    /// <summary>
    /// Determines if the specified textual value appears to be a
    /// <see cref="DateTime" /> value.
    /// </summary>
    /// <param name="convert">
    /// The <see cref="SQLiteConvert" /> object instance configured with
    /// the chosen <see cref="DateTime" /> format.
    /// </param>
    /// <param name="text">
    /// The textual value to inspect.
    /// </param>
    /// <returns>
    /// Non-zero if the text looks like a <see cref="DateTime" /> in the
    /// configured format, zero otherwise.
    /// </returns>
    internal static bool LooksLikeDateTime(
        SQLiteConvert convert,
        string text
        )
    {
        if (convert == null)
            return false;

        try
        {
            DateTime dateTimeValue = convert.ToDateTime(text);

            if (String.Equals(
                    convert.ToString(dateTimeValue),
                    text, StringComparison.Ordinal))
            {
                return true;
            }
        }
        catch
        {
            // do nothing.
        }

        return false;
    }

    /// <summary>
    /// For a given type name, return a closest-match .NET type
    /// </summary>
    /// <param name="connection">The connection context for custom type mappings, if any.</param>
    /// <param name="name">The name of the type to match</param>
    /// <param name="flags">The flags associated with the parent connection object.</param>

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

988
989
990
991
992
993
994
995

996
997
998
999
1000
1001
1002
1003
1004
988
989
990
991
992
993
994

995


996
997
998
999
1000
1001
1002







-
+
-
-







          if (arSize.Length > 1)
          {
            dataType = arSize[0];
            arSize = arSize[1].Split(')');
            if (arSize.Length > 1)
            {
              arSize = arSize[0].Split(',', '.');
              if (sqlType.Type == DbType.AnsiString || sqlType.Type == DbType.Binary ||
              if (sqlType.Type == DbType.Binary || SQLiteConvert.IsStringDbType(sqlType.Type))
                  sqlType.Type == DbType.String || sqlType.Type == DbType.AnsiStringFixedLength ||
                  sqlType.Type == DbType.StringFixedLength)
              {
                row[SchemaTableColumn.ColumnSize] = Convert.ToInt32(arSize[0], CultureInfo.InvariantCulture);
              }
              else
              {
                row[SchemaTableColumn.NumericPrecision] = Convert.ToInt32(arSize[0], CultureInfo.InvariantCulture);
                if (arSize.Length > 1)
1133
1134
1135
1136
1137
1138
1139













1140
1141
1142
1143
1144
1145
1146
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157







+
+
+
+
+
+
+
+
+
+
+
+
+







      CheckValidRow();

      if (i >= VisibleFieldCount && _keyInfo != null)
        return _keyInfo.GetValue(i - VisibleFieldCount);

      SQLiteConnectionFlags flags = SQLiteCommand.GetFlags(_command);
      SQLiteType typ = GetSQLiteType(flags, i);

      if (((flags & SQLiteConnectionFlags.DetectTextAffinity) == SQLiteConnectionFlags.DetectTextAffinity) &&
          ((typ == null) || (typ.Affinity == TypeAffinity.Text)))
      {
          typ = GetSQLiteType(
              typ, _activeStatement._sql.GetText(_activeStatement, i));
      }
      else if (((flags & SQLiteConnectionFlags.DetectStringType) == SQLiteConnectionFlags.DetectStringType) &&
          ((typ == null) || SQLiteConvert.IsStringDbType(typ.Type)))
      {
          typ = GetSQLiteType(
              typ, _activeStatement._sql.GetText(_activeStatement, i));
      }

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

    /// <summary>
    /// Retreives the values of multiple columns, up to the size of the supplied array
    /// </summary>
1409
1410
1411
1412
1413
1414
1415



































1416
1417
1418
1419
1420
1421
1422
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







        catch (ObjectDisposedException)
        {
            // do nothing.
        }

        return SQLiteConnectionFlags.Default;
    }

    /// <summary>
    /// Retrieves the SQLiteType for a given column and row value.
    /// </summary>
    /// <param name="oldType">
    /// The original SQLiteType structure, based only on the column.
    /// </param>
    /// <param name="text">
    /// The textual value of the column for a given row.
    /// </param>
    /// <returns>
    /// The SQLiteType structure.
    /// </returns>
    private SQLiteType GetSQLiteType(
        SQLiteType oldType, /* PASS-THROUGH */
        string text
        )
    {
        if (SQLiteConvert.LooksLikeNull(text))
            return new SQLiteType(TypeAffinity.Null, DbType.Object);

        if (SQLiteConvert.LooksLikeInt64(text))
            return new SQLiteType(TypeAffinity.Int64, DbType.Int64);

        if (SQLiteConvert.LooksLikeDouble(text))
            return new SQLiteType(TypeAffinity.Double, DbType.Double);

        if ((_activeStatement != null) &&
            SQLiteConvert.LooksLikeDateTime(_activeStatement._sql, text))
        {
            return new SQLiteType(TypeAffinity.DateTime, DbType.DateTime);
        }

        return oldType;
    }

    /// <summary>
    /// Retrieves the SQLiteType for a given column, and caches it to avoid repetetive interop calls.
    /// </summary>
    /// <param name="flags">The flags associated with the parent connection object.</param>
    /// <param name="i">The index of the column to retrieve</param>
    /// <returns>A SQLiteType structure</returns>

Changes to readme.htm.

211
212
213
214
215
216
217

218
219
220
221
222
223
224
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225







+







<p>
    <b>1.0.93.0 - June XX, 2014 <font color="red">(release scheduled)</font></b>
</p>
<ul>
    <li>Updated to <a href="http://www.sqlite.org/releaselog/3_8_4_3.html">SQLite 3.8.4.3</a>.</li>
    <li>Add support for mapping transaction isolation levels to their legacy default values. Pursuant to [56b42d99c1].</li>
    <li>Add support for setting the default DbType and type name used for mappings on a per-connection basis. Pursuant to [3c00ec5b52].</li>
    <li>Add DetectTextAffinity and DetectStringType connection flags to enable automatic detection of column types, when necessary. Pursuant to [3c00ec5b52].</li>
    <li>Add SetChunkSize method to the SQLiteConnection class. Pursuant to [d1c008fa0a].</li>
    <li>Make the ISQLiteSchemaExtensions interface public.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Have the SQLiteProviderFactory class (in the System.Data.SQLite.Linq assembly) implement the IServiceProvider interface.</li>
    <li>Fix bug in documentation generator automation that prevented some internal documentation links from working.</li>
</ul>
<p>
    <b>1.0.92.0 - March 19, 2014</b>

Changes to www/news.wiki.

1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19











+







<title>News</title>

<b>Version History</b>

<p>
    <b>1.0.93.0 - June XX, 2014 <font color="red">(release scheduled)</font></b>
</p>
<ul>
    <li>Updated to <a href="http://www.sqlite.org/releaselog/3_8_4_3.html">SQLite 3.8.4.3</a>.</li>
    <li>Add support for mapping transaction isolation levels to their legacy default values. Pursuant to [56b42d99c1].</li>
    <li>Add support for setting the default DbType and type name used for mappings on a per-connection basis. Pursuant to [3c00ec5b52].</li>
    <li>Add DetectTextAffinity and DetectStringType connection flags to enable automatic detection of column types, when necessary. Pursuant to [3c00ec5b52].</li>
    <li>Add SetChunkSize method to the SQLiteConnection class. Pursuant to [d1c008fa0a].</li>
    <li>Make the ISQLiteSchemaExtensions interface public.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Have the SQLiteProviderFactory class (in the System.Data.SQLite.Linq assembly) implement the IServiceProvider interface.</li>
    <li>Fix bug in documentation generator automation that prevented some internal documentation links from working.</li>
</ul>
<p>
    <b>1.0.92.0 - March 19, 2014</b>