Type[] _Types;				// types of the columns

		public TxtDataReader(System.Data.CommandBehavior behavior, TxtConnection conn, TxtCommand cmd)
		{
			bFirstRow=false;
			_tconn = conn;
			_tcmd = cmd;
			_behavior = behavior;
			
			string fname = _tcmd.Url;
			bool header = _tcmd.Header;
			char separator = _tcmd.Separator;

			_sr = GetStream();				// get the main stream

			Type tstring = "".GetType();

			LexTokenList ll = GetLine();
            int colcount = ll==null? 0: ll.Count - 1;		// don't count the end of line
			_Names = _tcmd.Columns;
			if (colcount == 0)
			{
				_sr.Close();
				_sr = null;
				if (_Names == null)
					return;
				_Types = new Type[_Names.Length];
				for (int ci=0; ci < _Types.Length; ci++)
					_Types[ci] = tstring;
				return;
			}
			
			if (_Names != null && _Names.Length != colcount)
				throw new Exception(string.Format("{0} column names specified but {1} columns found.", _Names.Length, colcount));

			if (header)
			{	
				if (_Names == null)
				{	// uses the first row as the names of the columns
					_Names = new string[colcount];
					int ci=0;
					foreach (LexToken lt in ll)
					{
						if (lt.Type == LexTokenTypes.EOF)
							break;
						_Names[ci++] = lt.Value;
					}
				}
				ll = GetLine();
			}
			else if (_Names == null)
			{	// just name the columns 'column1', 'column2', ...
				_Names = new string[colcount];
				for (int ci =0; ci < _Names.Length; ci++)
					_Names[ci] = "column" + (ci+1).ToString();
			}

			_Data = new object[_Names.Length];			// allocate enough room for data
			_Types = new Type[_Names.Length];
			if (ll != null)			// we have a datarow
			{
				bFirstRow = true;
				// loop thru determining the types of all data
				int ci=0;
				foreach (LexToken lt in ll)
				{
					if (ci >= _Types.Length || lt.Type == LexTokenTypes.EOF)
						break;
					_Types[ci++] = GetTypeOfString(lt.Value);					
				}
				FillData(ll);
			}
			else
			{	// no first row! assume all the column types are string
				for (int ci =0; ci < _Types.Length; ci++)
					_Types[ci] = tstring;
			}

			if (behavior == CommandBehavior.SchemaOnly)
			{
				_sr.Close();
				_sr = null;
			}

		}
Exemple #2
0
 public TxtCommand(TxtConnection conn)
 {
     _tc = conn;
 }
		public TxtCommand(TxtConnection conn)
		{
			_tc = conn;  
		}
Exemple #4
0
        Type[] _Types;                                  // types of the columns

        public TxtDataReader(System.Data.CommandBehavior behavior, TxtConnection conn, TxtCommand cmd)
        {
            bFirstRow = false;
            _tconn    = conn;
            _tcmd     = cmd;
            _behavior = behavior;

            string fname     = _tcmd.Url;
            bool   header    = _tcmd.Header;
            char   separator = _tcmd.Separator;

            _sr = GetStream();                                          // get the main stream

            Type tstring = "".GetType();

            LexTokenList ll       = GetLine();
            int          colcount = ll == null? 0: ll.Count - 1; // don't count the end of line

            _Names = _tcmd.Columns;
            if (colcount == 0)
            {
                _sr.Close();
                _sr = null;
                if (_Names == null)
                {
                    return;
                }
                _Types = new Type[_Names.Length];
                for (int ci = 0; ci < _Types.Length; ci++)
                {
                    _Types[ci] = tstring;
                }
                return;
            }

            if (_Names != null && _Names.Length != colcount)
            {
                throw new Exception(string.Format("{0} column names specified but {1} columns found.", _Names.Length, colcount));
            }

            if (header)
            {
                if (_Names == null)
                {                       // uses the first row as the names of the columns
                    _Names = new string[colcount];
                    int ci = 0;
                    foreach (LexToken lt in ll)
                    {
                        if (lt.Type == LexTokenTypes.EOF)
                        {
                            break;
                        }
                        _Names[ci++] = lt.Value;
                    }
                }
                ll = GetLine();
            }
            else if (_Names == null)
            {                   // just name the columns 'column1', 'column2', ...
                _Names = new string[colcount];
                for (int ci = 0; ci < _Names.Length; ci++)
                {
                    _Names[ci] = "column" + (ci + 1).ToString();
                }
            }

            _Data  = new object[_Names.Length];         // allocate enough room for data
            _Types = new Type[_Names.Length];
            if (ll != null)                             // we have a datarow
            {
                bFirstRow = true;
                // loop thru determining the types of all data
                int ci = 0;
                foreach (LexToken lt in ll)
                {
                    if (ci >= _Types.Length || lt.Type == LexTokenTypes.EOF)
                    {
                        break;
                    }
                    _Types[ci++] = GetTypeOfString(lt.Value);
                }
                FillData(ll);
            }
            else
            {                   // no first row! assume all the column types are string
                for (int ci = 0; ci < _Types.Length; ci++)
                {
                    _Types[ci] = tstring;
                }
            }

            if (behavior == CommandBehavior.SchemaOnly)
            {
                _sr.Close();
                _sr = null;
            }
        }