コード例 #1
0
        /// <summary>
        /// Retrieves the SQLiteType for a given column, and caches it to avoid repetetive interop calls.
        /// </summary>
        /// <param name="i">The index of the column to retrieve</param>
        /// <returns>A SQLiteType structure</returns>
        private SQLiteType GetSQLiteType(int i)
        {
            SQLiteType typ;

            // Initialize the field types array if not already initialized
            if (_fieldTypeArray == null)
            {
                _fieldTypeArray = new SQLiteType[VisibleFieldCount];
            }

            // Initialize this column's field type instance
            if (_fieldTypeArray[i] == null)
            {
                _fieldTypeArray[i] = new SQLiteType();
            }

            typ = _fieldTypeArray[i];

            // If not initialized, then fetch the declared column datatype and attempt to convert it
            // to a known DbType.
            if (typ.Affinity == TypeAffinity.Uninitialized)
            {
                typ.Type = SqliteConvert.TypeNameToDbType(_activeStatement._sql.ColumnType(_activeStatement, i, out typ.Affinity));
            }
            else
            {
                typ.Affinity = _activeStatement._sql.ColumnAffinity(_activeStatement, i);
            }

            return(typ);
        }
コード例 #2
0
        /// <summary>
        /// Retrieves the name of the back-end datatype of the column
        /// </summary>
        /// <param name="i">The index of the column to retrieve</param>
        /// <returns>string</returns>
        public override string GetDataTypeName(int i)
        {
            SQLiteType typ = GetSQLiteType(i);

            if (typ.Type == DbType.Object)
            {
                return(SqliteConvert.SQLiteTypeToType(typ).Name);
            }
            return(_activeStatement._sql.ColumnType(_activeStatement, i, out typ.Affinity));
        }
コード例 #3
0
        /// <summary>
        /// Helper function to retrieve a column of data from an active statement.
        /// </summary>
        /// <param name="stmt">The statement being step()'d through</param>
        /// <param name="index">The column index to retrieve</param>
        /// <param name="typ">The type of data contained in the column.  If Uninitialized, this function will retrieve the datatype information.</param>
        /// <returns>Returns the data in the column</returns>
        internal override object GetValue(SqliteStatement stmt, int index, SQLiteType typ)
        {
            if (IsNull(stmt, index))
            {
                return(DBNull.Value);
            }
            TypeAffinity aff = typ.Affinity;
            Type         t   = null;

            if (typ.Type != DbType.Object)
            {
                t   = SQLiteTypeToType(typ);
                aff = TypeToAffinity(t);
            }

            switch (aff)
            {
            case TypeAffinity.Blob:
                if (typ.Type == DbType.Guid && typ.Affinity == TypeAffinity.Text)
                {
                    return(new Guid(GetText(stmt, index)));
                }

                var n = (int)GetBytes(stmt, index, 0, null, 0, 0);
                var b = new byte[n];
                GetBytes(stmt, index, 0, b, 0, n);

                if (typ.Type == DbType.Guid && n == 16)
                {
                    return(new Guid(b));
                }

                return(b);

            case TypeAffinity.DateTime:
                return(GetDateTime(stmt, index));

            case TypeAffinity.Double:
                if (t == null)
                {
                    return(GetDouble(stmt, index));
                }
                return(Convert.ChangeType(GetDouble(stmt, index), t, null));

            case TypeAffinity.Int64:
                if (t == null)
                {
                    return(GetInt64(stmt, index));
                }
                return(Convert.ChangeType(GetInt64(stmt, index), t, null));

            default:
                return(GetText(stmt, index));
            }
        }
コード例 #4
0
        /// <summary>
        /// Retrieves the column as an object corresponding to the underlying datatype of the column
        /// </summary>
        /// <param name="i">The index of the column to retrieve</param>
        /// <returns>object</returns>
        public override object GetValue(int i)
        {
            if (i >= VisibleFieldCount && _keyInfo != null)
            {
                return(_keyInfo.GetValue(i - VisibleFieldCount));
            }

            SQLiteType typ = GetSQLiteType(i);

            return(_activeStatement._sql.GetValue(_activeStatement, i, typ));
        }
コード例 #5
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));
     }
 }
コード例 #6
0
        /// <summary>
        /// Retrieves the name of the back-end datatype of the column
        /// </summary>
        /// <param name="i">The index of the column to retrieve</param>
        /// <returns>string</returns>
        public override string GetDataTypeName(int i)
        {
            if (i >= VisibleFieldCount && _keyInfo != null)
            {
                return(_keyInfo.GetDataTypeName(i - VisibleFieldCount));
            }

            SQLiteType typ = GetSQLiteType(i);

            return(_activeStatement._sql.ColumnType(_activeStatement, i, out typ.Affinity));
        }
コード例 #7
0
        /// <summary>
        /// Retrieves the name of the back-end datatype of the column
        /// </summary>
        /// <param name="i">The index of the column to retrieve</param>
        /// <returns>string</returns>
        public override string GetDataTypeName(int i)
        {
            if (i >= VisibleFieldCount && _keyInfo != null)
            {
                return(_keyInfo.GetDataTypeName(i - VisibleFieldCount));
            }

            SQLiteType typ = GetSQLiteType(i);

            if (typ.Type == DbType.Object)
            {
                return(SqliteConvert.SQLiteTypeToType(typ).Name);
            }
            return(_activeStatement._sql.ColumnType(_activeStatement, i, out typ.Affinity));
        }
コード例 #8
0
ファイル: SQLiteDataReader.cs プロジェクト: narutopatel/mono
    /// <summary>
    /// Retrieves the SQLiteType for a given column, and caches it to avoid repetetive interop calls.
    /// </summary>
    /// <param name="i">The index of the column to retrieve</param>
    /// <returns>A SQLiteType structure</returns>
    private SQLiteType GetSQLiteType(int i)
    {
      SQLiteType typ;

      // Initialize the field types array if not already initialized
      if (_fieldTypeArray == null)
        _fieldTypeArray = new SQLiteType[VisibleFieldCount];

      // Initialize this column's field type instance
      if (_fieldTypeArray[i] == null) _fieldTypeArray[i] = new SQLiteType();

      typ = _fieldTypeArray[i];

      // If not initialized, then fetch the declared column datatype and attempt to convert it 
      // to a known DbType.
      if (typ.Affinity == TypeAffinity.Uninitialized)
        typ.Type = SqliteConvert.TypeNameToDbType(_activeStatement._sql.ColumnType(_activeStatement, i, out typ.Affinity));
      else
        typ.Affinity = _activeStatement._sql.ColumnAffinity(_activeStatement, i);

      return typ;
    }
コード例 #9
0
 internal abstract object GetValue(SqliteStatement stmt, int index, SQLiteType typ);
コード例 #10
0
ファイル: SQLite3.cs プロジェクト: tohosnet/Mono.Data.Sqlite
        /// <summary>
        /// Helper function to retrieve a column of data from an active statement.
        /// </summary>
        /// <param name="stmt">The statement being step()'d through</param>
        /// <param name="index">The column index to retrieve</param>
        /// <param name="typ">The type of data contained in the column.  If Uninitialized, this function will retrieve the datatype information.</param>
        /// <returns>Returns the data in the column</returns>
        internal override object GetValue(SqliteStatement stmt, int index, SQLiteType typ)
        {
            if (IsNull(stmt, index)) return DBNull.Value;
            TypeAffinity aff = typ.Affinity;
            Type t = null;

            if (typ.Type != DbType.Object)
            {
                t = SQLiteTypeToType(typ);
                aff = TypeToAffinity(t);
            }

            switch (aff)
            {
                case TypeAffinity.Blob:
                    if (typ.Type == DbType.Guid && typ.Affinity == TypeAffinity.Text)
                    {
                        return new Guid(GetText(stmt, index));
                    }

                    var n = (int) GetBytes(stmt, index, 0, null, 0, 0);
                    var b = new byte[n];
                    GetBytes(stmt, index, 0, b, 0, n);

                    if (typ.Type == DbType.Guid && n == 16)
                    {
                        return new Guid(b);
                    }

                    return b;
                case TypeAffinity.DateTime:
                    return GetDateTime(stmt, index);
                case TypeAffinity.Double:
                    if (t == null)
                    {
                        return GetDouble(stmt, index);
                    }
                    return Convert.ChangeType(GetDouble(stmt, index), t, null);
                case TypeAffinity.Int64:
                    if (t == null)
                    {
                        return GetInt64(stmt, index);
                    }
                    return Convert.ChangeType(GetInt64(stmt, index), t, null);
                default:
                    return GetText(stmt, index);
            }
        }
コード例 #11
0
ファイル: SQLiteConvert.cs プロジェクト: nlhepler/mono
 /// <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);
 }
コード例 #12
0
ファイル: SQLiteConvert.cs プロジェクト: nlhepler/mono
 /// <summary>
 /// Determines the data type of a column in a statement
 /// </summary>
 /// <param name="stmt">The statement to retrieve information for</param>
 /// <param name="i">The column to retrieve type information on</param>
 /// <param name="typ">The SQLiteType to receive the affinity for the given column</param>
 internal static void ColumnToType(SqliteStatement stmt, int i, SQLiteType typ)
 {
   typ.Type = TypeNameToDbType(stmt._sql.ColumnType(stmt, i, out typ.Affinity));
 }
コード例 #13
0
 /// <summary>
 /// Determines the data type of a column in a statement
 /// </summary>
 /// <param name="stmt">The statement to retrieve information for</param>
 /// <param name="i">The column to retrieve type information on</param>
 /// <param name="typ">The SQLiteType to receive the affinity for the given column</param>
 internal static void ColumnToType(SqliteStatement stmt, int i, SQLiteType typ)
 {
     typ.Type = TypeNameToDbType(stmt._sql.ColumnType(stmt, i, out typ.Affinity));
 }
コード例 #14
0
ファイル: SQLiteBase.cs プロジェクト: robert-j/mono-fork
 internal abstract object GetValue(SqliteStatement stmt, int index, SQLiteType typ);
コード例 #15
0
        /// <summary>
        /// Retrieves the column as an object corresponding to the underlying datatype of the column
        /// </summary>
        /// <param name="i">The index of the column to retrieve</param>
        /// <returns>object</returns>
        public override object GetValue(int i)
        {
            SQLiteType typ = GetSQLiteType(i);

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