예제 #1
0
        /// <summary>
        /// Return the value of the specified field.
        /// </summary>
        /// <returns>
        /// The <see cref="T:System.Object"/> which will contain the field value upon return.
        /// </returns>
        /// <param name="i">The index of the field to find. </param><exception cref="T:System.IndexOutOfRangeException">The index passed was outside the range of 0 through <see cref="P:System.Data.IDataRecord.FieldCount"/>. </exception>
        public object GetValue(int i)
        {
            var value = MapiLib.MapiFetchField(_queryHandle, i);

            DieQueryError();

            return(value);
        }
예제 #2
0
        /// <summary>
        /// Advances the <see cref="T:System.Data.IDataReader"/> to the next record.
        /// </summary>
        /// <returns>
        /// true if there are more rows; otherwise, false.
        /// </returns>
        public bool Read()
        {
            if (MapiLib.MapiFetchRow(_queryHandle) > 0)
            {
                DieQueryError();

                return(true);
            }

            return(false);
        }
예제 #3
0
        /// <summary>
        ///     Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number
        ///     of rows affected.
        /// </summary>
        /// <returns>
        ///     The number of rows affected.
        /// </returns>
        /// <exception cref="T:System.InvalidOperationException">The connection does not exist.-or- The connection is not open. </exception>
        public int ExecuteNonQuery()
        {
            var connHandle  = _connection.GetConnectionHandle();
            var queryHandle = MapiFactory.GetQueryHandle(connHandle, CommandText);

            var rowsAffected = MapiLib.MapiRowsAffected(queryHandle).To <int>();

            MapiFactory.DieQueryError(connHandle, queryHandle);

            MapiFactory.CloseQueryHandle(queryHandle);

            return(rowsAffected);
        }
예제 #4
0
        /// <summary>
        /// Advances the data reader to the next result, when reading the results of batch SQL statements.
        /// </summary>
        /// <returns>
        /// true if there are more rows; otherwise, false.
        /// </returns>
        public bool NextResult()
        {
            if (MapiLib.MapiNextResult(_queryHandle).Ptr != IntPtr.Zero)
            {
                DieQueryError();

                _resultIndex++;

                Init();

                return(true);
            }

            return(false);
        }
예제 #5
0
        /// <summary>
        ///     Executes the query, and returns the first column of the first row in the resultset returned by the query. Extra
        ///     columns or rows are ignored.
        /// </summary>
        /// <returns>
        ///     The first column of the first row in the resultset.
        /// </returns>
        public object ExecuteScalar()
        {
            var connHandle  = _connection.GetConnectionHandle();
            var queryHandle = MapiFactory.GetQueryHandle(connHandle, CommandText);

            object result = null;

            if (MapiLib.MapiFetchRow(queryHandle) > 0)
            {
                MapiFactory.DieQueryError(connHandle, queryHandle);

                result = MapiLib.MapiFetchField(queryHandle, 0);
                MapiFactory.DieQueryError(connHandle, queryHandle);
            }

            MapiFactory.CloseQueryHandle(queryHandle);

            return(result);
        }
예제 #6
0
        private void Init()
        {
            //field count
            FieldCount = MapiLib.MapiGetFieldCount(_queryHandle);
            DieQueryError();

            //record affected
            RecordsAffected = MapiLib.MapiRowsAffected(_queryHandle).To <int>();
            DieQueryError();

            //schema table
            var tableName = MapiLib.MapiGetTable(_queryHandle, _resultIndex);

            if (tableName.IsNull())
            {
                _schemaTable = new DataTable();
            }
            else
            {
                _schemaTable = new DataTable(tableName);
                DieQueryError();
            }

            //table columns
            _schemaTable.Columns.Add(SchemaColumnName, typeof(string));
            _schemaTable.Columns.Add(SchemaDataType, typeof(string));
            _schemaTable.Columns.Add(SchemaSystemType, typeof(Type));
            for (var fieldIndex = 0; fieldIndex < FieldCount; fieldIndex++)
            {
                var name = MapiLib.MapiGetName(_queryHandle, fieldIndex);
                DieQueryError();

                var dbType = MapiLib.MapiGetType(_queryHandle, fieldIndex);
                DieQueryError();

                var systemType = dbType.GetSystemType();

                _schemaTable.Rows.Add(name, dbType, systemType);
            }
        }