Struct used internally to determine the datatype of a column in a resultset
Esempio n. 1
0
        /// <summary>
        /// Execute the command and return the first column of the first row of the resultset
        /// (if present), or null if no resultset was returned.
        /// </summary>
        /// <returns>The first column of the first row of the first resultset from the query</returns>
        public override object ExecuteScalar()
        {
            InitializeForReader();

            int             x   = 0;
            object          ret = null;
            SqliteType      typ = new SqliteType();
            SqliteStatement stmt;

            // We step through every statement in the command, but only grab the first row of the first resultset.
            // We keep going even after obtaining it.
            for (;;)
            {
                stmt = GetStatement(x);
                x++;
                if (stmt == null)
                {
                    break;
                }

                if (_cnn._sql.Step(stmt) == true && ret == null)
                {
                    ret = _cnn._sql.GetValue(stmt, 0, typ);
                }
                _cnn._sql.Reset(stmt);
            }

            return(ret);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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>
        /// <returns>Returns a SqliteType struct</returns>
        internal static SqliteType ColumnToType(SqliteStatement stmt, int i)
        {
            SqliteType typ = new SqliteType();

            typ.Type = TypeNameToDbType(stmt._sql.ColumnType(stmt, i, out typ.Affinity));

            return(typ);
        }
Esempio n. 4
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(SqliteConvert.DbTypeToType(t.Type));
            }

            return(_typeaffinities[(int)t.Affinity]);
        }
Esempio n. 5
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)
        {
            CheckClosed();

#if MONO_SUPPORT_KEYREADER
            if (i >= VisibleFieldCount && _keyInfo != null)
            {
                return(_keyInfo.GetValue(i - VisibleFieldCount));
            }
#endif
            SqliteType typ = GetSqliteType(i);
            typ.Affinity = _activeStatement._sql.ColumnAffinity(_activeStatement, i);
            return(_activeStatement._sql.GetValue(_activeStatement, i, typ));
        }
Esempio n. 6
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 (typ.Affinity == 0)
            {
                typ = SqliteConvert.ColumnToType(stmt, index);
            }
            if (IsNull(stmt, index))
            {
                return(DBNull.Value);
            }

            Type t = SqliteConvert.SqliteTypeToType(typ);

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

                int    n = (int)GetBytes(stmt, index, 0, null, 0, 0);
                byte[] 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:
                return(Convert.ChangeType(GetDouble(stmt, index), t, null));

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

            default:
                return(GetText(stmt, index));
            }
        }
Esempio n. 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)
        {
            CheckClosed();

#if MONO_SUPPORT_KEYREADER
            if (i >= VisibleFieldCount && _keyInfo != null)
            {
                return(_keyInfo.GetDataTypeName(i - VisibleFieldCount));
            }
#endif

            SqliteType typ = GetSqliteType(i);
            if (typ.Type == DbType.Object)
            {
                return(SqliteConvert.SqliteTypeToType(typ).Name);
            }
            return(_activeStatement._sql.ColumnType(_activeStatement, i, out typ.Affinity));
        }
Esempio n. 8
0
 internal abstract object GetValue(SqliteStatement stmt, int index, SqliteType typ);
Esempio n. 9
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;
    }
Esempio n. 10
0
    /// <summary>
    /// Execute the command and return the first column of the first row of the resultset
    /// (if present), or null if no resultset was returned.
    /// </summary>
    /// <returns>The first column of the first row of the first resultset from the query</returns>
    public override object ExecuteScalar()
    {
      InitializeForReader();

      int x = 0;
      object ret = null;
      SqliteType typ = new SqliteType();
      SqliteStatement stmt;

      // We step through every statement in the command, but only grab the first row of the first resultset.
      // We keep going even after obtaining it.
      for (;;)
      {
        stmt = GetStatement(x);
        x++;
        if (stmt == null) break;

        if (_cnn._sql.Step(stmt) == true && ret == null)
        {
          ret = _cnn._sql.GetValue(stmt, 0, typ);
        }
        _cnn._sql.Reset(stmt);
      }

      return ret;
    }
Esempio n. 11
0
 internal abstract object GetValue(SqliteStatement stmt, int index, SqliteType typ);
Esempio n. 12
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 SqliteConvert.DbTypeToType(t.Type);

      return _typeaffinities[(int)t.Affinity];
    }
Esempio n. 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>
    /// <returns>Returns a SqliteType struct</returns>
    internal static SqliteType ColumnToType(SqliteStatement stmt, int i)
    {
      SqliteType typ = new SqliteType ();

      typ.Type = TypeNameToDbType(stmt._sql.ColumnType(stmt, i, out typ.Affinity));

      return typ;
    }