System.Data.SQLite
Check-in [fc72de85c8]
Not logged in

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

Overview
Comment:Refactor how the SQLiteDataReader class handles the connection flags associated with its command.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: fc72de85c839077bf2c7471b725f2992b06e4a81
User & Date: mistachkin 2014-05-26 22:43:35
Context
2014-05-26
22:52
Fix stray whitespace. check-in: 48fe67dae9 user: mistachkin tags: trunk
22:51
Merge updates from trunk. check-in: ce61807139 user: mistachkin tags: tkt-3c00ec5b52
22:43
Refactor how the SQLiteDataReader class handles the connection flags associated with its command. check-in: fc72de85c8 user: mistachkin tags: trunk
21:11
Mark the setup packages with their configuration. check-in: c2d4f7a670 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

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

  2009   2009       /// The DbType of the column, or DbType.Object if it cannot be determined
  2010   2010       /// </summary>
  2011   2011       internal DbType Type;
  2012   2012       /// <summary>
  2013   2013       /// The affinity of a column, used for expressions or when Type is DbType.Object
  2014   2014       /// </summary>
  2015   2015       internal TypeAffinity Affinity;
         2016  +
         2017  +    ///////////////////////////////////////////////////////////////////////////
         2018  +
         2019  +    /// <summary>
         2020  +    /// Constructs a default instance of this type.
         2021  +    /// </summary>
         2022  +    public SQLiteType()
         2023  +    {
         2024  +      // do nothing.
         2025  +    }
         2026  +
         2027  +    ///////////////////////////////////////////////////////////////////////////
         2028  +
         2029  +    /// <summary>
         2030  +    /// Constructs an instance of this type with the specified field values.
         2031  +    /// </summary>
         2032  +    /// <param name="affinity">
         2033  +    /// The type affinity to use for the new instance.
         2034  +    /// </param>
         2035  +    /// <param name="type">
         2036  +    /// The database type to use for the new instance.
         2037  +    /// </param>
         2038  +    public SQLiteType(
         2039  +      TypeAffinity affinity,
         2040  +      DbType type
         2041  +      )
         2042  +        : this()
         2043  +    {
         2044  +      this.Affinity = affinity;
         2045  +      this.Type = type;
         2046  +    }
  2016   2047     }
  2017   2048   
  2018   2049     /////////////////////////////////////////////////////////////////////////////
  2019   2050   
  2020   2051     internal sealed class SQLiteDbTypeMap
  2021   2052         : Dictionary<string, SQLiteDbTypeMapping>
  2022   2053     {

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

   357    357       /// <param name="i">The index of the column to type-check</param>
   358    358       /// <param name="typ">The type we want to get out of the column</param>
   359    359       private TypeAffinity VerifyType(int i, DbType typ)
   360    360       {
   361    361         CheckClosed();
   362    362         CheckValidRow();
   363    363   
   364         -      TypeAffinity affinity = GetSQLiteType(i).Affinity;
          364  +      TypeAffinity affinity = GetSQLiteType(SQLiteCommand.GetFlags(_command), i).Affinity;
   365    365   
   366    366         switch (affinity)
   367    367         {
   368    368           case TypeAffinity.Int64:
   369    369             if (typ == DbType.Int16) return affinity;
   370    370             if (typ == DbType.Int32) return affinity;
   371    371             if (typ == DbType.Int64) return affinity;
................................................................................
   502    502       public override string GetDataTypeName(int i)
   503    503       {
   504    504         CheckDisposed();
   505    505   
   506    506         if (i >= VisibleFieldCount && _keyInfo != null)
   507    507           return _keyInfo.GetDataTypeName(i - VisibleFieldCount);
   508    508   
   509         -      SQLiteType typ = GetSQLiteType(i);
          509  +      SQLiteType typ = GetSQLiteType(SQLiteCommand.GetFlags(_command), i);
   510    510         if (typ.Type == DbType.Object) return SQLiteConvert.SQLiteTypeToType(typ).Name;
   511    511         return _activeStatement._sql.ColumnType(_activeStatement, i, out typ.Affinity);
   512    512       }
   513    513   
   514    514       /// <summary>
   515    515       /// Retrieve the column as a date/time value
   516    516       /// </summary>
................................................................................
   567    567       public override Type GetFieldType(int i)
   568    568       {
   569    569         CheckDisposed();
   570    570   
   571    571         if (i >= VisibleFieldCount && _keyInfo != null)
   572    572           return _keyInfo.GetFieldType(i - VisibleFieldCount);
   573    573   
   574         -      return SQLiteConvert.SQLiteTypeToType(GetSQLiteType(i));
          574  +      return SQLiteConvert.SQLiteTypeToType(GetSQLiteType(SQLiteCommand.GetFlags(_command), i));
   575    575       }
   576    576   
   577    577       /// <summary>
   578    578       /// Returns a column as a float value
   579    579       /// </summary>
   580    580       /// <param name="i">The index of the column to retrieve</param>
   581    581       /// <returns>float</returns>
................................................................................
   916    916         tbl.Columns.Add(SchemaTableOptionalColumn.IsReadOnly, typeof(Boolean));
   917    917         tbl.Columns.Add(SchemaTableOptionalColumn.ProviderSpecificDataType, typeof(Type));
   918    918         tbl.Columns.Add(SchemaTableOptionalColumn.DefaultValue, typeof(object));
   919    919         tbl.Columns.Add("DataTypeName", typeof(string));
   920    920         tbl.Columns.Add("CollationType", typeof(string));
   921    921         tbl.BeginLoadData();
   922    922   
          923  +      SQLiteConnectionFlags flags = SQLiteCommand.GetFlags(_command);
          924  +
   923    925         for (int n = 0; n < _fieldCount; n++)
   924    926         {
   925         -        SQLiteType sqlType = GetSQLiteType(n);
          927  +        SQLiteType sqlType = GetSQLiteType(flags, n);
   926    928   
   927    929           row = tbl.NewRow();
   928    930   
   929    931           DbType typ = sqlType.Type;
   930    932   
   931    933           // Default settings for the column
   932    934           row[SchemaTableColumn.ColumnName] = GetName(n);
................................................................................
  1129   1131       {
  1130   1132         CheckDisposed();
  1131   1133         CheckValidRow();
  1132   1134   
  1133   1135         if (i >= VisibleFieldCount && _keyInfo != null)
  1134   1136           return _keyInfo.GetValue(i - VisibleFieldCount);
  1135   1137   
  1136         -      SQLiteType typ = GetSQLiteType(i);
         1138  +      SQLiteConnectionFlags flags = SQLiteCommand.GetFlags(_command);
         1139  +      SQLiteType typ = GetSQLiteType(flags, i);
  1137   1140   
  1138         -      return _activeStatement._sql.GetValue(
  1139         -          _activeStatement, SQLiteCommand.GetFlags(_command), i, typ);
         1141  +      return _activeStatement._sql.GetValue(_activeStatement, flags, i, typ);
  1140   1142       }
  1141   1143   
  1142   1144       /// <summary>
  1143   1145       /// Retreives the values of multiple columns, up to the size of the supplied array
  1144   1146       /// </summary>
  1145   1147       /// <param name="values">The array to fill with values from the columns in the current resultset</param>
  1146   1148       /// <returns>The number of columns retrieved</returns>
................................................................................
  1411   1413   
  1412   1414           return SQLiteConnectionFlags.Default;
  1413   1415       }
  1414   1416   
  1415   1417       /// <summary>
  1416   1418       /// Retrieves the SQLiteType for a given column, and caches it to avoid repetetive interop calls.
  1417   1419       /// </summary>
         1420  +    /// <param name="flags">The flags associated with the parent connection object.</param>
  1418   1421       /// <param name="i">The index of the column to retrieve</param>
  1419   1422       /// <returns>A SQLiteType structure</returns>
  1420         -    private SQLiteType GetSQLiteType(int i)
         1423  +    private SQLiteType GetSQLiteType(SQLiteConnectionFlags flags, int i)
  1421   1424       {
  1422   1425         SQLiteType typ;
  1423   1426   
  1424   1427         // Initialize the field types array if not already initialized
  1425   1428         if (_fieldTypeArray == null)
  1426   1429           _fieldTypeArray = new SQLiteType[VisibleFieldCount];
  1427   1430   
................................................................................
  1429   1432         if (_fieldTypeArray[i] == null) _fieldTypeArray[i] = new SQLiteType();
  1430   1433   
  1431   1434         typ = _fieldTypeArray[i];
  1432   1435   
  1433   1436         // If not initialized, then fetch the declared column datatype and attempt to convert it
  1434   1437         // to a known DbType.
  1435   1438         if (typ.Affinity == TypeAffinity.Uninitialized)
  1436         -        typ.Type = SQLiteConvert.TypeNameToDbType(GetConnection(this), _activeStatement._sql.ColumnType(_activeStatement, i, out typ.Affinity), GetFlags(this));
         1439  +        typ.Type = SQLiteConvert.TypeNameToDbType(GetConnection(this), _activeStatement._sql.ColumnType(_activeStatement, i, out typ.Affinity), flags);
  1437   1440         else
  1438   1441           typ.Affinity = _activeStatement._sql.ColumnAffinity(_activeStatement, i);
  1439   1442   
  1440   1443         return typ;
  1441   1444       }
  1442   1445   
  1443   1446       /// <summary>