System.Data.SQLite
Check-in [64d7e6903e]
Not logged in

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

Overview
Comment:When creating a parameter associated with a specific command, keep track of that command.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 64d7e6903e016e4226668038cdac1f1c132985d8
User & Date: mistachkin 2015-03-26 20:38:30
Context
2015-03-26
21:55
When BinaryGUID handling is off, transform the LINQ paramter types as well. Fix for [a4d9c7ee94]. check-in: 87b4244129 user: mistachkin tags: trunk
20:38
When creating a parameter associated with a specific command, keep track of that command. check-in: 64d7e6903e user: mistachkin tags: trunk
20:20
Make the DbType value of (-1) a constant in the parameter class. check-in: 30d638f582 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

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

   502    502       /// <summary>
   503    503       /// Create a new parameter
   504    504       /// </summary>
   505    505       /// <returns></returns>
   506    506       public new SQLiteParameter CreateParameter()
   507    507       {
   508    508         CheckDisposed();
   509         -      return new SQLiteParameter();
          509  +      return new SQLiteParameter(this);
   510    510       }
   511    511   
   512    512       /// <summary>
   513    513       /// The connection associated with this command
   514    514       /// </summary>
   515    515   #if !PLATFORM_COMPACTFRAMEWORK
   516    516       [DefaultValue((string)null), Editor("Microsoft.VSDesigner.Data.Design.DbConnectionEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
................................................................................
   756    756                   {
   757    757                       command.CommandText = commandText;
   758    758   
   759    759                       if (args != null)
   760    760                       {
   761    761                           foreach (object arg in args)
   762    762                           {
   763         -                            if (arg is SQLiteParameter)
   764         -                                command.Parameters.Add((SQLiteParameter)arg);
   765         -                            else
   766         -                                command.Parameters.Add(new SQLiteParameter(DbType.Object, arg));
          763  +                            SQLiteParameter parameter = arg as SQLiteParameter;
          764  +
          765  +                            if (parameter == null)
          766  +                            {
          767  +                                parameter = command.CreateParameter();
          768  +                                parameter.DbType = DbType.Object;
          769  +                                parameter.Value = arg;
          770  +                            }
          771  +
          772  +                            command.Parameters.Add(parameter);
   767    773                           }
   768    774                       }
   769    775   
   770    776                       switch (executeType)
   771    777                       {
   772    778                           case SQLiteExecuteType.None:
   773    779                               {

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

    18     18     public sealed class SQLiteParameter : DbParameter, ICloneable
    19     19     {
    20     20       /// <summary>
    21     21       /// This value represents an "unknown" <see cref="DbType" />.
    22     22       /// </summary>
    23     23       private const DbType UnknownDbType = (DbType)(-1);
    24     24   
           25  +    /// <summary>
           26  +    /// The command associated with this parameter.
           27  +    /// </summary>
           28  +    private IDbCommand     _command;
    25     29       /// <summary>
    26     30       /// The data type of the parameter
    27     31       /// </summary>
    28     32       internal DbType        _dbType;
    29     33       /// <summary>
    30     34       /// The version information for mapping the parameter
    31     35       /// </summary>
................................................................................
    45     49       /// <summary>
    46     50       /// The data size, unused by SQLite
    47     51       /// </summary>
    48     52       private int            _dataSize;
    49     53   
    50     54       private bool           _nullable;
    51     55       private bool           _nullMapping;
           56  +
           57  +    /// <summary>
           58  +    /// Constructor used when creating for use with a specific command.
           59  +    /// </summary>
           60  +    /// <param name="command">
           61  +    /// The command associated with this parameter.
           62  +    /// </param>
           63  +    internal SQLiteParameter(
           64  +        IDbCommand command
           65  +        )
           66  +        : this()
           67  +    {
           68  +        _command = command;
           69  +    }
    52     70   
    53     71       /// <summary>
    54     72       /// Default constructor
    55     73       /// </summary>
    56     74       public SQLiteParameter() 
    57     75         : this(null, UnknownDbType, 0, null, DataRowVersion.Current)
    58     76       {
................................................................................
   190    208         _sourceColumn = sourceColumn;
   191    209         _rowVersion = rowVersion;
   192    210         _dataSize = parameterSize;
   193    211         _nullable = true;
   194    212       }
   195    213   
   196    214       private SQLiteParameter(SQLiteParameter source)
   197         -      : this(source.ParameterName, (DbType)source._dbType, 0, source.Direction, source.IsNullable, 0, 0, source.SourceColumn, source.SourceVersion, source.Value)
          215  +      : this(source.ParameterName, source._dbType, 0, source.Direction, source.IsNullable, 0, 0, source.SourceColumn, source.SourceVersion, source.Value)
   198    216       {
   199    217         _nullMapping = source._nullMapping;
   200    218       }
   201    219   
   202    220       /// <summary>
   203    221       /// Constructs a named parameter of the specified type, size, source column and row version
   204    222       /// </summary>
................................................................................
   275    293       /// <param name="parameterSize">The size of the parameter</param>
   276    294       /// <param name="sourceColumn">The source column</param>
   277    295       /// <param name="rowVersion">The row version information</param>
   278    296       public SQLiteParameter(DbType parameterType, int parameterSize, string sourceColumn, DataRowVersion rowVersion)
   279    297         : this(null, parameterType, parameterSize, sourceColumn, rowVersion)
   280    298       {
   281    299       }
          300  +
          301  +    /// <summary>
          302  +    /// The command associated with this parameter.
          303  +    /// </summary>
          304  +    public IDbCommand Command
          305  +    {
          306  +      get
          307  +      {
          308  +        return _command;
          309  +      }
          310  +      set 
          311  +      {
          312  +        _command = value;
          313  +      }
          314  +    }
   282    315   
   283    316       /// <summary>
   284    317       /// Whether or not the parameter can contain a null value
   285    318       /// </summary>
   286    319       public override bool IsNullable
   287    320       {
   288    321         get
................................................................................
   310    343           {
   311    344             if (_objValue != null && _objValue != DBNull.Value)
   312    345             {
   313    346               return SQLiteConvert.TypeToDbType(_objValue.GetType());
   314    347             }
   315    348             return DbType.String; // Unassigned default value is String
   316    349           }
   317         -        return (DbType)_dbType;
          350  +        return _dbType;
   318    351         }
   319    352         set
   320    353         {
   321    354           _dbType = value;
   322    355         }
   323    356       }
   324    357