object ReadCol(IntPtr stmt, int index, Type clrType) { var type = SQLite3.ColumnType(stmt, index); if (type == SQLite3.ColType.Null) { return(null); } else { if (clrType == typeof(Byte) || clrType == typeof(UInt16) || clrType == typeof(SByte) || clrType == typeof(Int16) || clrType == typeof(Int32)) { return(Convert.ChangeType(SQLite3.ColumnInt(stmt, index), clrType)); } else if (clrType == typeof(Boolean)) { return((Byte)Convert.ChangeType(SQLite3.ColumnInt(stmt, index), typeof(Byte)) == 1); } else if (clrType == typeof(UInt32) || clrType == typeof(Int64)) { return(Convert.ChangeType(SQLite3.ColumnInt64(stmt, index), clrType)); } else if (clrType == typeof(Single) || clrType == typeof(Double) || clrType == typeof(Decimal)) { return(Convert.ChangeType(SQLite3.ColumnDouble(stmt, index), clrType)); } else if (clrType == typeof(String)) { var text = Marshal.PtrToStringUni(SQLite3.ColumnText16(stmt, index)); return(text); } else if (clrType == typeof(DateTime)) { var text = Marshal.PtrToStringUni(SQLite3.ColumnText16(stmt, index)); return(Convert.ChangeType(text, clrType)); } else if (clrType.IsEnum) { return(SQLite3.ColumnInt(stmt, index)); } else { throw new NotSupportedException("Don't know how to read " + clrType); } } }
public static string ColumnString(IntPtr stmt, int index) { return(Marshal.PtrToStringUni(SQLite3.ColumnText16(stmt, index))); }