예제 #1
0
 /// <summary>
 /// Converts a SQLiteType to a .NET Type object
 /// </summary>
 /// <param name="t">The SQLiteType to convert</param>
 /// <returns>Returns a .NET Type object</returns>
 internal static Type SqliteTypeToType(SqliteType t)
 {
     if (t.Type == DbType.Object)
     {
         return(_affinitytotype[(int)t.Affinity]);
     }
     else
     {
         return(SqliteConvert.DbTypeToType(t.Type));
     }
 }
        /// <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;
            }
        }