internal static object GetAs(object o, Type type) { if (o != null && o.GetType() == type) { return(o); } if (o == null) { o = null; } else if (type == typeof(int)) { o = (int)(long)o; } else if (type == typeof(uint)) { o = (uint)(long)o; } else if (type == typeof(ulong)) { o = (ulong)(long)o; } else if (type == typeof(float)) { o = (float)(double)o; } if (o != null && o.GetType() == type) { return(o); } return(SqliteUtils.FromDbFormat(type, o)); }
public T Query <T> () { Reset(); using (reader) { return(reader.Read() ? reader.Get <T> (0) : (T)SqliteUtils.FromDbFormat <T> (null)); } }
public void SetValue(object target, IDataReader reader, int column) { // FIXME should we insist on nullable types? object value = reader.IsDBNull(column) ? null : reader.GetValue(column); SetValue(target, SqliteUtils.FromDbFormat(type, value)); }
public T Query <T> (HyenaSqliteCommand command, params object [] param_values) { command.CommandType = HyenaCommandType.Scalar; QueueCommand(command, param_values); object result = command.WaitForResult(this); return((T)SqliteUtils.FromDbFormat(typeof(T), result)); }
public T Get <T> (int i) { if (!read) { Read(); } return((T)SqliteUtils.FromDbFormat(typeof(T), reader[i])); }
public IEnumerable <T> QueryEnumerable <T> (HyenaSqliteCommand command, params object [] param_values) { Type type = typeof(T); using (IDataReader reader = Query(command, param_values)) { while (reader.Read()) { yield return((T)SqliteUtils.FromDbFormat(type, reader[0])); } } }