public object GetValue(int columnIndex, Type propertyType) { object value = null; if (propertyType == typeof(String) || propertyType == typeof(string)) { value = SQLite3.ColumnString(statement, columnIndex); } else if (propertyType == typeof(long)) { value = SQLite3.ColumnInt64(statement, columnIndex); } else if (propertyType == typeof(Single) || propertyType == typeof(Double) || propertyType == typeof(Decimal)) { value = SQLite3.ColumnDouble(statement, columnIndex); } else if (propertyType == typeof(int)) { value = SQLite3.ColumnInt(statement, columnIndex); } else if (propertyType == typeof(bool) || propertyType == typeof(Boolean)) { value = (SQLite3.ColumnInt(statement, columnIndex) != 0); } else if (propertyType == typeof(byte[])) { value = SQLite3.ColumnByteArray(statement, columnIndex); } /* else if (column.isSingleRelationship) { * value = (V)(object)SQLite3.ColumnString(statement, columnIndex); * }*/ return(value); }
private object ReadCol(SQLitePCL.sqlite3_stmt stmt, int index, SQLite3.ColType type) { switch (type) { case SQLite3.ColType.Blob: return(SQLite3.ColumnByteArray(stmt, index)); case SQLite3.ColType.Float: return(SQLite3.ColumnDouble(stmt, index)); case SQLite3.ColType.Integer: return(SQLite3.ColumnInt64(stmt, index)); case SQLite3.ColType.Null: return(null); case SQLite3.ColType.Text: return(SQLite3.ColumnString(stmt, index)); } return(null); }
public object ReadCol(IntPtr stmt, int index, Type clrType) { var type = SQLite3.ColumnType(stmt, index); if (type == SQLite3.ColType.Null) { return(null); } if (clrType == typeof(Byte) || clrType == typeof(UInt16) || clrType == typeof(SByte) || clrType == typeof(Int16) || clrType == typeof(Int32)) { return(Convert.ChangeType(SQLite3.ColumnInt(stmt, index), clrType)); } if (clrType == typeof(UInt32) || clrType == typeof(Int64)) { return(Convert.ChangeType(SQLite3.ColumnInt64(stmt, index), clrType)); } if (clrType == typeof(Single) || clrType == typeof(Double) || clrType == typeof(Decimal)) { return(Convert.ChangeType(SQLite3.ColumnDouble(stmt, index), clrType)); } if (clrType == typeof(String)) { return(Convert.ChangeType(SQLite3.ColumnString(stmt, index), clrType)); } if (clrType == typeof(byte[])) { return(SQLite3.ColumnByteArray(stmt, index)); } if (clrType == typeof(DateTime)) { return(ToDateTime(SQLite3.ColumnString(stmt, index))); } if (clrType == typeof(Boolean)) { return(ToBoolean(SQLite3.ColumnString(stmt, index))); } throw new NotSupportedException("Don't know how to read " + clrType); }
public Object ExecuteScalar() { Object retObj = null; var stmt = Prepare(); var cols = new System.Reflection.PropertyInfo[SQLite3.ColumnCount(stmt)]; if (SQLite3.Step(stmt) == SQLite3.Result.Row) { if (cols.Length > 0) { var type = SQLite3.ColumnType(stmt, 0); switch (type) { case SQLite3.ColType.Integer: retObj = SQLite3.ColumnInt64(stmt, 0); break; case SQLite3.ColType.Float: retObj = SQLite3.ColumnDouble(stmt, 0); break; case SQLite3.ColType.Blob: retObj = SQLite3.ColumnByteArray(stmt, 0); break; case SQLite3.ColType.Text: retObj = SQLite3.ColumnString(stmt, 0); break; case SQLite3.ColType.Null: break; } } } SQLite3.Finalize(stmt); return(retObj); }
private object ReadCol(Sqlite3Statement stmt, int index, SQLite3.ColType type, Type clrType) { if (type == SQLite3.ColType.Null) { return(null); } if (clrType == typeof(string)) { return(SQLite3.ColumnString(stmt, index)); } if (clrType == typeof(int)) { return(SQLite3.ColumnInt(stmt, index)); } if (clrType == typeof(bool)) { return(SQLite3.ColumnInt(stmt, index) == 1); } if (clrType == typeof(double)) { return(SQLite3.ColumnDouble(stmt, index)); } if (clrType == typeof(float)) { return((float)SQLite3.ColumnDouble(stmt, index)); } if (clrType == typeof(TimeSpan)) { return(new TimeSpan(SQLite3.ColumnInt64(stmt, index))); } if (clrType == typeof(DateTime)) { if (_conn.StoreDateTimeAsTicks) { return(new DateTime(SQLite3.ColumnInt64(stmt, index))); } string text = SQLite3.ColumnString(stmt, index); return(DateTime.Parse(text)); } if (clrType == typeof(DateTimeOffset)) { return(new DateTimeOffset(SQLite3.ColumnInt64(stmt, index), TimeSpan.Zero)); } if (clrType.IsEnum) { return(SQLite3.ColumnInt(stmt, index)); } if (clrType == typeof(long)) { return(SQLite3.ColumnInt64(stmt, index)); } if (clrType == typeof(uint)) { return((uint)SQLite3.ColumnInt64(stmt, index)); } if (clrType == typeof(decimal)) { return((decimal)SQLite3.ColumnDouble(stmt, index)); } if (clrType == typeof(byte)) { return((byte)SQLite3.ColumnInt(stmt, index)); } if (clrType == typeof(ushort)) { return((ushort)SQLite3.ColumnInt(stmt, index)); } if (clrType == typeof(short)) { return((short)SQLite3.ColumnInt(stmt, index)); } if (clrType == typeof(sbyte)) { return((sbyte)SQLite3.ColumnInt(stmt, index)); } if (clrType == typeof(byte[])) { return(SQLite3.ColumnByteArray(stmt, index)); } if (clrType == typeof(Guid)) { string text = SQLite3.ColumnString(stmt, index); return(new Guid(text)); } throw new NotSupportedException("Don't know how to read " + clrType); }
private static object ReadCol(SQLiteConnection connection, sqlite3_stmt stmt, int index, SQLite3.ColType type, Type clrType) { if (type == SQLite3.ColType.Null) { return(null); } else { if (clrType == typeof(String)) { return(SQLite3.ColumnString(stmt, index)); } else if (clrType == typeof(Int32)) { return((int)SQLite3.ColumnInt(stmt, index)); } else if (clrType == typeof(Boolean)) { return(SQLite3.ColumnInt(stmt, index) == 1); } else if (clrType == typeof(double)) { return(SQLite3.ColumnDouble(stmt, index)); } else if (clrType == typeof(float)) { return((float)SQLite3.ColumnDouble(stmt, index)); } else if (clrType == typeof(TimeSpan)) { return(new TimeSpan(SQLite3.ColumnInt64(stmt, index))); } else if (clrType == typeof(DateTime)) { if (connection.StoreDateTimeAsTicks) { return(new DateTime(SQLite3.ColumnInt64(stmt, index))); } else { string text = SQLite3.ColumnString(stmt, index); DateTime resultDate; if (!DateTime.TryParseExact(text, DateTimeExactStoreFormat, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out resultDate)) { resultDate = DateTime.Parse(text); } return(resultDate); } } // else if (clrType == typeof(DateTimeOffset)) // { // return new DateTimeOffset(SQLite3.ColumnInt64(stmt, index), TimeSpan.Zero); //#if !USE_NEW_REFLECTION_API // } // else if (clrType.IsEnum) // { //#else // } else if (clrType.GetTypeInfo().IsEnum) { //#endif // if (type == SQLite3.ColType.Text) // { // var value = SQLite3.ColumnString(stmt, index); // return Enum.Parse(clrType, value.ToString(), true); // } // else // return SQLite3.ColumnInt(stmt, index); // } else if (clrType == typeof(Int64)) { return(SQLite3.ColumnInt64(stmt, index)); } else if (clrType == typeof(UInt32)) { return((uint)SQLite3.ColumnInt64(stmt, index)); } else if (clrType == typeof(decimal)) { return((decimal)SQLite3.ColumnDouble(stmt, index)); } else if (clrType == typeof(Byte)) { return((byte)SQLite3.ColumnInt(stmt, index)); } else if (clrType == typeof(UInt16)) { return((ushort)SQLite3.ColumnInt(stmt, index)); } else if (clrType == typeof(Int16)) { return((short)SQLite3.ColumnInt(stmt, index)); } else if (clrType == typeof(sbyte)) { return((sbyte)SQLite3.ColumnInt(stmt, index)); } else if (clrType == typeof(byte[])) { return(SQLite3.ColumnByteArray(stmt, index)); } else if (clrType == typeof(Guid)) { string text = SQLite3.ColumnString(stmt, index); return(new Guid(text)); } else { throw new NotSupportedException("Don't know how to read " + clrType); } } }