Subclass which contains all of an individual column's data and specs This is the lowest rung on the class ladder. It represents a single column in a database row, containing the column name, value, and properties.

This class it never used directly, but as a subclass of an instantiated Halide.H3DataRow class object.

Exemplo n.º 1
0
        /// <summary>
        /// Add a column to the data set in memory. This is useful when stored procedures used for
        /// saving data require optional parameters.
        /// <para>The new column will act just like a real SQL data column, and you may
        /// want to add a faux SQL data type to its properties, as well as any other
        /// properties, so that you can manipulate it properly.</para>
        /// </summary>
        /// <example>
        /// <code>
        /// using Argentini.Halide;
        /// ...
        /// H3DataRow dataRow = new H3DataRow("SELECT TOP 1 * FROM Content WHERE ID=5;", "SqlServer01");
        /// dataRow.Column.AddColumn("YourAge", "30");
        /// dataRow["YourAge"].ColumnSQLType = "bigint";
        /// </code>
        /// </example>
        /// <param name="colName">Name of the new column.</param>
        /// <param name="colValue">Value of the new column.</param>
        /// <returns>true if successful, false if not.</returns>
        public Boolean AddColumn(String colName, String colValue)
        {
            bool retVal = false;
            int oldFieldCount = _fieldCount;
            String newVal = colValue;
            String columnName = colName.ToLower();

            if (String.IsNullOrEmpty(newVal))
                newVal = "";

            if (!String.IsNullOrEmpty(columnName))
            {
                try
                {
                    #region COPY DATA INTO NEW ARRAY, ONE LARGER THAN CURRENT

                    DatabaseItem[] _dataItemsX;
                    _dataItemsX = new DatabaseItem[_fieldCount + 1];

                    for (int x = 0; x < _fieldCount; x++)
                    {
                        _dataItemsX[x] = new DatabaseItem();
                        _dataItemsX[x] = _dataItems[x];
                    }

                    #endregion

                    #region ADD NEW ENTRY TO END OF NEW ARRAY

                    _dataItemsX[_fieldCount] = new DatabaseItem();
                    _dataItemsX[_fieldCount].ColumnName = columnName;
                    _dataItemsX[_fieldCount].Value = newVal;
                    _dataItemsX[_fieldCount].ColumnSize = 0;
                    _dataItemsX[_fieldCount].ColumnSQLType = "";
                    _dataItemsX[_fieldCount].IsAutoIncrementing = false;
                    _dataItemsX[_fieldCount].IsIdentity = false;
                    _dataItemsX[_fieldCount].IsNullable = false;
                    _dataItemsX[_fieldCount].IsPrimaryKey = false;
                    _dataItemsX[_fieldCount].SystemDataType = "";

                    _dataIndex.Add(columnName, _fieldCount);
                    _fieldCount++;

                    #endregion

                    #region ENLARGE OLD ARRAY; COPY NEW ARRAY BACK INTO OLD ONE

                    _dataItems = new DatabaseItem[_fieldCount];

                    for (int x = 0; x < _fieldCount; x++)
                    {
                        _dataItems[x] = new DatabaseItem();
                        _dataItems[x] = _dataItemsX[x];
                    }

                    #endregion

                    retVal = true;
                }

                catch
                {
                    _fieldCount = oldFieldCount;
                }
            }

            return retVal;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Delete a column from the data set in memory.
        /// </summary>
        /// <example>
        /// <code>
        /// using Argentini.Halide;
        /// ...
        /// H3DataRow dataRow = new H3DataRow("SELECT TOP 1 * FROM Content WHERE ID=5;", "SqlServer01");
        /// dataRow.Column.DeleteColumn("MyAge");
        /// </code>
        /// </example>
        /// <param name="colName">Name of the column to delete.</param>
        /// <returns>true if successful, false if not.</returns>
        public Boolean DeleteColumn(String colName)
        {
            bool retVal = false;
            int oldFieldCount = _fieldCount;
            String columnName = colName.ToLower();

            if (!String.IsNullOrEmpty(columnName))
            {
                if (_dataIndex[columnName] != null)
                {
                    try
                    {
                        #region COPY DATA INTO NEW ARRAY, EXCEPT FOR DELETED COLUMN

                        DatabaseItem[] _dataItemsX;
                        _dataItemsX = new DatabaseItem[_fieldCount - 1];
                        _dataIndex.Clear();

                        int counter = 0;

                        for (int x = 0; x < _fieldCount; x++)
                        {
                            if (_dataItems[x].ColumnName != columnName)
                            {
                                _dataItemsX[counter] = new DatabaseItem();
                                _dataItemsX[counter] = _dataItems[x];
                                _dataIndex.Add(_dataItemsX[counter].ColumnName, counter);
                                counter++;
                            }
                        }

                        #endregion

                        #region RESIZE OLD ARRAY; COPY NEW ARRAY BACK INTO OLD ONE

                        _fieldCount--;

                        _dataItems = new DatabaseItem[_fieldCount];

                        for (int x = 0; x < _fieldCount; x++)
                        {
                            _dataItems[x] = new DatabaseItem();
                            _dataItems[x] = _dataItemsX[x];
                        }

                        #endregion

                        retVal = true;
                    }

                    catch
                    {
                        _fieldCount = oldFieldCount;
                    }
                }
            }

            return retVal;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initialize the DatabaseRow with a single row form a Halide.H3Reader object.
        /// </summary>
        /// <param name="reader">An open Halide.H3Reader object that can be used to read a row from a database.</param>
        public DatabaseRow(H3Reader reader)
        {
            _fieldCount = reader.FieldCount;

            try
            {
                _dataItems = new DatabaseItem[_fieldCount];

                if (_dataIndex != null) _dataIndex.Clear();

                for (int x = 0; x < _fieldCount; x++)
                {
                    _dataItems[x] = new DatabaseItem();

                    String columnName = reader.ColumnName(x).ToLower();

                    _dataIndex.Add(columnName, x);

                    _dataItems[x].IsNullable = reader.GetColumnAllowNulls(columnName);
                    _dataItems[x].ColumnName = columnName;
                    _dataItems[x].ColumnSize = reader.GetColumnSize(columnName);
                    _dataItems[x].ColumnSQLType = reader.GetDataTypeName(columnName).ToLower();
                    _dataItems[x].IsAutoIncrementing = reader.GetColumnIsAutoIncrement(columnName);
                    _dataItems[x].IsIdentity = reader.GetColumnIsIdentity(columnName);
                    _dataItems[x].IsPrimaryKey = reader.GetColumnIsKey(columnName);
                    _dataItems[x].SystemDataType = reader.GetColumnSystemDataType(columnName).ToLower();
                    _dataItems[x].Value = reader.GetString(columnName);
                }
            }
            catch
            {
            }
        }