/// <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((int)SqliteErrorCode.Error, "Insufficient parameters supplied to the command");
            }

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

            if (obj == DBNull.Value || obj == null)
            {
                _sql.Bind_Null(this, index);
                return;
            }

            if (objType == DbType.Object)
            {
                objType = SqliteConvert.TypeToDbType(obj.GetType());
            }

            switch (objType)
            {
            case DbType.Date:
            case DbType.Time:
            case DbType.DateTime:
                _sql.Bind_DateTime(this, index, Convert.ToDateTime(obj, CultureInfo.CurrentCulture));
                break;

            case DbType.Int64:
            case DbType.UInt64:
            case DbType.UInt32:
                _sql.Bind_Int64(this, index, Convert.ToInt64(obj, CultureInfo.CurrentCulture));
                break;

            case DbType.Boolean:
            case DbType.Int16:
            case DbType.Int32:
            case DbType.UInt16:
            case DbType.SByte:
            case DbType.Byte:
                _sql.Bind_Int32(this, index, Convert.ToInt32(obj, CultureInfo.CurrentCulture));
                break;

            case DbType.Single:
            case DbType.Double:
            case DbType.Currency:
                //case DbType.Decimal: // Dont store decimal as double ... loses precision
                _sql.Bind_Double(this, index, Convert.ToDouble(obj, CultureInfo.CurrentCulture));
                break;

            case DbType.Binary:
                _sql.Bind_Blob(this, index, (byte[])obj);
                break;

            case DbType.Guid:
                if (_command.Connection._binaryGuid == true)
                {
                    _sql.Bind_Blob(this, index, ((Guid)obj).ToByteArray());
                }
                else
                {
                    _sql.Bind_Text(this, index, obj.ToString());
                }

                break;

            case DbType.Decimal:     // Dont store decimal as double ... loses precision
                _sql.Bind_Text(this, index, Convert.ToDecimal(obj, CultureInfo.CurrentCulture).ToString(CultureInfo.InvariantCulture));
                break;

            default:
                _sql.Bind_Text(this, index, obj.ToString());
                break;
            }
        }
 /// <summary>
 /// Adds an array of parameters to the collection
 /// </summary>
 /// <param name="values">The array of parameters to add</param>
 public void AddRange(SqliteParameter[] values) {
     int x = values.Length;
     for (int n = 0; n < x; n++)
         Add(values[n]);
 }
        /// <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="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 (String.IsNullOrEmpty(parameter.ParameterName) == false) {
                n = IndexOf(parameter.ParameterName);
            }

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

            SetParameter(n, parameter);

            return n;
        }
        /// <summary>
        /// Adds a named/unnamed parameter and its value to the parameter collection.
        /// </summary>
        /// <param name="parameterName">Name of the parameter, or null to indicate an unnamed parameter</param>
        /// <param name="value">The initial value of the parameter</param>
        /// <returns>Returns the SqliteParameter object created during the call.</returns>
        public SqliteParameter AddWithValue(string parameterName, object value) {
            SqliteParameter param = new SqliteParameter(parameterName, value);
            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>
        /// Clones a parameter
        /// </summary>
        /// <returns>A new, unassociated SqliteParameter</returns>
        public object Clone() {
            SqliteParameter newparam = new SqliteParameter(this);

            return newparam;
        }
 private SqliteParameter(SqliteParameter source)
     : this(source.ParameterName, (DbType)source._dbType, 0, source.Direction, source.IsNullable, 0, 0, source.SourceColumn, source.SourceVersion, source.Value) {
     _nullMapping = source._nullMapping;
 }
        /// <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((int)SqliteErrorCode.Error, "Insufficient parameters supplied to the command");

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

            if (obj == DBNull.Value || obj == null) {
                _sql.Bind_Null(this, index);
                return;
            }

            if (objType == DbType.Object)
                objType = SqliteConvert.TypeToDbType(obj.GetType());

            switch (objType) {
                case DbType.Date:
                case DbType.Time:
                case DbType.DateTime:
                    _sql.Bind_DateTime(this, index, Convert.ToDateTime(obj, CultureInfo.CurrentCulture));
                    break;
                case DbType.Int64:
                case DbType.UInt64:
                case DbType.UInt32:
                    _sql.Bind_Int64(this, index, Convert.ToInt64(obj, CultureInfo.CurrentCulture));
                    break;
                case DbType.Boolean:
                case DbType.Int16:
                case DbType.Int32:
                case DbType.UInt16:
                case DbType.SByte:
                case DbType.Byte:
                    _sql.Bind_Int32(this, index, Convert.ToInt32(obj, CultureInfo.CurrentCulture));
                    break;
                case DbType.Single:
                case DbType.Double:
                case DbType.Currency:
                    //case DbType.Decimal: // Dont store decimal as double ... loses precision
                    _sql.Bind_Double(this, index, Convert.ToDouble(obj, CultureInfo.CurrentCulture));
                    break;
                case DbType.Binary:
                    _sql.Bind_Blob(this, index, (byte[])obj);
                    break;
                case DbType.Guid:
                    if (_command.Connection._binaryGuid == true)
                        _sql.Bind_Blob(this, index, ((Guid)obj).ToByteArray());
                    else
                        _sql.Bind_Text(this, index, obj.ToString());

                    break;
                case DbType.Decimal: // Dont store decimal as double ... loses precision
                    _sql.Bind_Text(this, index, Convert.ToDecimal(obj, CultureInfo.CurrentCulture).ToString(CultureInfo.InvariantCulture));
                    break;
                default:
                    _sql.Bind_Text(this, index, obj.ToString());
                    break;
            }
        }
        /// <summary>
        /// Called by SqliteParameterCollection, this function determines if the specified parameter name belongs to
        /// this statement, and if so, keeps a reference to the parameter so it can be bound later.
        /// </summary>
        /// <param name="s">The parameter name to map</param>
        /// <param name="p">The parameter to assign it</param>
        internal bool MapParameter(string s, SqliteParameter p) {
            if (_paramNames == null) return false;

            int startAt = 0;
            if (s.Length > 0) {
                if (":$@;".IndexOf(s[0]) == -1)
                    startAt = 1;
            }

            int x = _paramNames.Length;
            for (int n = 0; n < x; n++) {
                if (String.Compare(_paramNames[n], startAt, s, 0, Math.Max(_paramNames[n].Length - startAt, s.Length), StringComparison.OrdinalIgnoreCase) == 0) {
                    _paramValues[n] = p;
                    return true;
                }
            }
            return false;
        }