/// <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, ref typ); } _cnn._sql.Reset(stmt); } return(ret); }
/// <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); }
internal static Type SQLiteTypeToType(SQLiteType t) { if (t.Type == DbType.Object) { return(_affinitytotype[(int)t.Affinity]); } return(DbTypeToType(t.Type)); }
/// <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(); SQLiteType typ = GetSQLiteType(i); return(_activeStatement._sql.GetValue(_activeStatement, i, ref typ)); }
/// <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]); }
public override object GetValue(int i) { if ((i >= this.VisibleFieldCount) && (this._keyInfo != null)) { return(this._keyInfo.GetValue(i - this.VisibleFieldCount)); } SQLiteType sQLiteType = this.GetSQLiteType(i); return(this._activeStatement._sql.GetValue(this._activeStatement, i, sQLiteType)); }
/// <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) { if (i >= VisibleFieldCount && _keyInfo != null) { return(_keyInfo.GetValue(i - VisibleFieldCount)); } SQLiteType typ = GetSQLiteType(i); return(_activeStatement._sql.GetValue(_activeStatement, i, typ)); }
/// <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(); SQLiteType typ = GetSQLiteType(i); if (typ.Type == DbType.Object) { return(SQLiteConvert.SQLiteTypeToType(typ).Name); } return(_activeStatement._sql.ColumnType(_activeStatement, i, out typ.Affinity)); }
public override string GetDataTypeName(int i) { if ((i >= this.VisibleFieldCount) && (this._keyInfo != null)) { return(this._keyInfo.GetDataTypeName(i - this.VisibleFieldCount)); } SQLiteType sQLiteType = this.GetSQLiteType(i); if (sQLiteType.Type == DbType.Object) { return(SQLiteConvert.SQLiteTypeToType(sQLiteType).Name); } return(this._activeStatement._sql.ColumnType(this._activeStatement, i, out sQLiteType.Affinity)); }
internal override object GetValue(SQLiteStatement stmt, int index, SQLiteType typ) { if (this.IsNull(stmt, index)) { return(DBNull.Value); } TypeAffinity affinity = typ.Affinity; Type type = null; if (typ.Type != DbType.Object) { type = SQLiteConvert.SQLiteTypeToType(typ); affinity = SQLiteConvert.TypeToAffinity(type); } switch (affinity) { case TypeAffinity.Int64: if (type != null) { return(Convert.ChangeType(this.GetInt64(stmt, index), type, null)); } return(this.GetInt64(stmt, index)); case TypeAffinity.Double: if (type != null) { return(Convert.ChangeType(this.GetDouble(stmt, index), type, null)); } return(this.GetDouble(stmt, index)); case TypeAffinity.Blob: if ((typ.Type != DbType.Guid) || (typ.Affinity != TypeAffinity.Text)) { int nLength = (int)this.GetBytes(stmt, index, 0, null, 0, 0); byte[] bDest = new byte[nLength]; this.GetBytes(stmt, index, 0, bDest, 0, nLength); if ((typ.Type == DbType.Guid) && (nLength == 0x10)) { return(new Guid(bDest)); } return(bDest); } return(new Guid(this.GetText(stmt, index))); case TypeAffinity.DateTime: return(this.GetDateTime(stmt, index)); } return(this.GetText(stmt, index)); }
/// <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) { if (i >= VisibleFieldCount && _keyInfo != null) { return(_keyInfo.GetDataTypeName(i - VisibleFieldCount)); } SQLiteType typ = GetSQLiteType(i); if (typ.Type == DbType.Object) { return(SQLiteConvert.SQLiteTypeToType(typ).Name); } return(_activeStatement._sql.ColumnType(_activeStatement, i, out typ.Affinity)); }
/// <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 virtual object GetValue(SQLiteStatement stmt, int index, ref 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)); } }
private SQLiteType GetSQLiteType(int i) { if (this._fieldTypeArray == null) { this._fieldTypeArray = new SQLiteType[this.VisibleFieldCount]; } if (this._fieldTypeArray[i] == null) { this._fieldTypeArray[i] = new SQLiteType(); } SQLiteType type = this._fieldTypeArray[i]; if (type.Affinity == TypeAffinity.Uninitialized) { type.Type = SQLiteConvert.TypeNameToDbType(this._activeStatement._sql.ColumnType(this._activeStatement, i, out type.Affinity)); return(type); } type.Affinity = this._activeStatement._sql.ColumnAffinity(this._activeStatement, i); return(type); }
/// <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, ref typ); } _cnn._sql.Reset(stmt); } return ret; }
/// <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); } }
/// <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]; }
internal abstract object GetValue(SQLiteStatement stmt, int index, SQLiteType typ);
/// <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 virtual object GetValue(SQLiteStatement stmt, int index, ref 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); } }
internal abstract object GetValue(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, SQLiteType typ);
/// <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; }
/// <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 _affinitytotype[(int)t.Affinity]; else return SQLiteConvert.DbTypeToType(t.Type); }
/// <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 (IsNull(stmt, index)) { return(DBNull.Value); } TypeAffinity aff = typ.Affinity; Type t = null; if (typ.Type != DbType.Object) { t = SQLiteConvert.SQLiteTypeToType(typ); aff = TypeToAffinity(t); } 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)); } else { return(Convert.ChangeType(GetDouble(stmt, index), t, null)); } case TypeAffinity.Int64: if (t == null) { return(GetInt64(stmt, index)); } else { return(Convert.ChangeType(GetInt64(stmt, index), t, null)); } default: return(GetText(stmt, index)); } }
internal static void ColumnToType(SQLiteStatement stmt, int i, SQLiteType typ) { typ.Type = TypeNameToDbType(stmt._sql.ColumnType(stmt, i, out typ.Affinity)); }
/// <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> /// <param name="typ">The SQLiteType to receive the affinity for the given column</param> internal static void ColumnToType(SQLiteStatement stmt, int i, SQLiteType typ) { typ.Type = TypeNameToDbType(stmt._sql.ColumnType(stmt, i, out typ.Affinity)); }
/// <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 (IsNull(stmt, index)) return DBNull.Value; TypeAffinity aff = typ.Affinity; Type t = null; if (typ.Type != DbType.Object) { t = SQLiteConvert.SQLiteTypeToType(typ); aff = TypeToAffinity(t); } 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); else return Convert.ChangeType(GetDouble(stmt, index), t, null); case TypeAffinity.Int64: if (t == null) return GetInt64(stmt, index); else return Convert.ChangeType(GetInt64(stmt, index), t, null); default: return GetText(stmt, index); } }