public static object Read(SQLiteType sqliteType, StatementHandle handle, int ordinal)
        {
            Debug.Assert(handle != null && !handle.IsInvalid, "handle is null.");

            if (sqliteType == SQLiteType.Null
                || NativeMethods.sqlite3_column_type(handle, ordinal) == Constants.SQLITE_NULL)
            {
                return DBNull.Value;
            }

            switch (sqliteType)
            {
                case SQLiteType.Integer:
                    return NativeMethods.sqlite3_column_int64(handle, ordinal);

                case SQLiteType.Float:
                    return NativeMethods.sqlite3_column_double(handle, ordinal);

                case SQLiteType.Text:
                    return NativeMethods.sqlite3_column_text(handle, ordinal);

                default:
                    Debug.Assert(sqliteType == SQLiteType.Blob, "_sqliteType is not Blob.");
                    return NativeMethods.sqlite3_column_blob(handle, ordinal);
            }
        }
        public static object Read(SQLiteType sqliteType, StatementHandle handle, int ordinal)
        {
            Debug.Assert(handle != null && !handle.IsInvalid, "handle is null.");

            if (sqliteType == SQLiteType.Null ||
                NativeMethods.sqlite3_column_type(handle, ordinal) == Constants.SQLITE_NULL)
            {
                return(DBNull.Value);
            }

            switch (sqliteType)
            {
            case SQLiteType.Integer:
                return(NativeMethods.sqlite3_column_int64(handle, ordinal));

            case SQLiteType.Float:
                return(NativeMethods.sqlite3_column_double(handle, ordinal));

            case SQLiteType.Text:
                return(NativeMethods.sqlite3_column_text(handle, ordinal));

            default:
                Debug.Assert(sqliteType == SQLiteType.Blob, "_sqliteType is not Blob.");
                return(NativeMethods.sqlite3_column_blob(handle, ordinal));
            }
        }
예제 #3
0
        private static ForecastInfo ParseForecast(ISQLiteStatement row)
        {
            var forecast = new ForecastInfo();

            for (int x = 0; x < row.ColumnCount; x++)
            {
                var columnLabel = row.ColumnName(x);
                if (typeof(ForecastInfo).HasProperty(columnLabel))
                {
                    SQLiteType dataType = row.DataType(x);
                    if (columnLabel == "Name")
                    {
                        forecast.Name = row[x] as string;
                    }
                    else if (columnLabel == "Id")
                    {
                        forecast.Id = int.Parse(row[x].ToString());
                    }
                    else if (columnLabel == "CategoryId")
                    {
                        forecast.CategoryId = int.Parse(row[x].ToString());
                    }
                    else if (columnLabel == "ForecastNumber")
                    {
                        forecast.ForecastNumber = int.Parse(row[x].ToString());
                    }
                }
            }
            return(forecast);
        }
        private SQLiteTypeMap(Type clrType, SQLiteType sqliteType, IEnumerable <string> declaredTypes, DbType dbType)
        {
            Debug.Assert(clrType != null, "clrType is null.");
            Debug.Assert(declaredTypes != null, "declaredTypes is null.");

            _clrType       = clrType;
            _sqliteType    = sqliteType;
            _declaredTypes = declaredTypes;
            _dbType        = dbType;
        }
        private SQLiteTypeMap(
            Type clrType,
            SQLiteType sqliteType,
            Func <object, object> toInterop,
            Func <object, object> fromInterop,
            IEnumerable <string> declaredTypes,
            DbType dbType)
            : this(clrType, sqliteType, declaredTypes, dbType)
        {
            Debug.Assert(toInterop != null, "toInterop is null.");
            Debug.Assert(fromInterop != null, "fromInterop is null.");

            _toInterop   = toInterop;
            _fromInterop = fromInterop;
        }
        public static SQLiteTypeMap FromSQLiteType(SQLiteType type)
        {
            switch (type)
            {
            case SQLiteType.Null:
                return(_null);

            case SQLiteType.Integer:
                return(_integer);

            case SQLiteType.Float:
                return(_real);

            case SQLiteType.Text:
                return(_text);

            default:
                Debug.Assert(type == SQLiteType.Blob, "type is not Blob.");
                return(_blob);
            }
        }
예제 #7
0
        private static Region ParseRegion(ISQLiteStatement row)
        {
            var region = new Region();

            for (int x = 0; x < row.ColumnCount; x++)
            {
                var columnLabel = row.ColumnName(x);
                if (typeof(Region).HasProperty(columnLabel))
                {
                    SQLiteType dataType = row.DataType(x);
                    if (dataType == SQLiteType.INTEGER)
                    {
                        region.Id = int.Parse(row[x].ToString());
                    }
                    else
                    {
                        region.Name = row[x] as string;
                    }
                }
            }
            return(region);
        }
예제 #8
0
        private static string ToSQLDeclaredType(this SQLiteType This)
        {
            switch (This)
            {
            case SQLiteType.Integer:
                return("INTEGER");

            case SQLiteType.Float:
                return("REAL");

            case SQLiteType.Text:
                return("TEXT");

            case SQLiteType.Blob:
                return("BLOB");

            case SQLiteType.Null:
                return("NULL");

            default:
                throw new ArgumentException("Invalid SQLite type.");
            }
        }
        public static SQLiteTypeMap FromDeclaredType(string declaredType, SQLiteType sqliteType)
        {
            SQLiteTypeMap map = null;

            if (declaredType != null)
            {
                // Strip length, precision & scale
                var i = declaredType.IndexOf('(');
                if (i != -1)
                {
                    declaredType = declaredType.Substring(0, i).TrimEnd();
                }

                map = _typeMaps.FirstOrDefault(
                    m => m._declaredTypes.Contains(declaredType, StringComparer.OrdinalIgnoreCase));
            }

            if (map == null)
            {
                map = FromSQLiteType(sqliteType);
            }

            return(map);
        }
예제 #10
0
 public static DbType Parse(SQLiteType dbType)
 {
     return(DbTypeMap.Reverse(dbType));
 }
예제 #11
0
		public static DbType Parse(SQLiteType dbType)
		{
			return DbTypeMap.Reverse(dbType);
		}
예제 #12
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="flags">The flags associated with the connection.</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, SQLiteConnectionFlags flags, int index, SQLiteType typ)
    {
      TypeAffinity aff = typ.Affinity;
      if (aff == TypeAffinity.Null) return DBNull.Value;
      Type t = null;

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

      if ((flags & SQLiteConnectionFlags.GetAllAsText) == SQLiteConnectionFlags.GetAllAsText)
          return GetText(stmt, index);

      switch (aff)
      {
        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:
          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);
          if (t == typeof(SByte)) return GetSByte(stmt, index);
          if (t == typeof(Byte)) return GetByte(stmt, index);
          if (t == typeof(Int16)) return GetInt16(stmt, index);
          if (t == typeof(UInt16)) return GetUInt16(stmt, index);
          if (t == typeof(Int32)) return GetInt32(stmt, index);
          if (t == typeof(UInt32)) return GetUInt32(stmt, index);
          if (t == typeof(UInt64)) return GetUInt64(stmt, index);
          return Convert.ChangeType(GetInt64(stmt, index), t, null);
        default:
          return GetText(stmt, index);
      }
    }
예제 #13
0
 internal abstract object GetValue(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, SQLiteType typ);