示例#1
0
 protected override async Task <DbDataReader> ExecuteDbDataReaderAsync(System.Data.CommandBehavior behavior, System.Threading.CancellationToken cancellationToken)
 {
     return(await Task <DaxDataReader> .Factory.StartNew(() =>
     {
         return this.ExecuteDbDataReader(behavior) as DaxDataReader;
     }));
 }
示例#2
0
        /// <summary>
        /// Overloaded. Sends the CommandText to the Connection and builds a VistaDBDataReader object, passing in CommandBehavior.
        /// </summary>
        public VistaDBDataReader ExecuteReader(System.Data.CommandBehavior behavior)
        {
            VistaDBSQLQuery   query;
            string            s;
            VistaDBConnection conn;
            bool fillData;

            s = commandText.TrimStart(' ');
            s = (s.Substring(0, 6)).ToUpper();

            if (s == "INSERT" || s == "UPDATE" || s == "DELETE")
            {
                int rowsAffected = ExecuteNonQuery();
                return(new VistaDBDataReader(rowsAffected));
            }

            if (connection == null || connection.State != ConnectionState.Open)
            {
                throw new VistaDBException(VistaDBErrorCodes.ConnectionInvalid);
            }

            query = connection.VistaDBSQL.NewSQLQuery();

            query.SQL = commandText;
            AddSQLParameter(query);
            query.Open();

            conn     = (int)(behavior & CommandBehavior.CloseConnection) != 0 ? this.connection: null;
            fillData = ((int)(behavior & CommandBehavior.KeyInfo) == 0) && ((int)(behavior & CommandBehavior.SchemaOnly) == 0);

            return(new VistaDBDataReader(query, fillData, conn));
        }
示例#3
0
        public FileDirDataReader(System.Data.CommandBehavior behavior, FileDirConnection conn, FileDirCommand cmd)
        {
            _fdconn           = conn;
            _fdcmd            = cmd;
            _behavior         = behavior;
            _FilePattern      = _fdcmd.FilePattern;
            _DirectoryPattern = _fdcmd.DirectoryPattern;
            _TrimEmpty        = _fdcmd.TrimEmpty;

            _Data = new object[_Names.Length];                                  // allocate enough room for data

            if (behavior == CommandBehavior.SchemaOnly)
            {
                return;
            }

            string dir = _fdcmd.Directory;

            if (dir == null)
            {
                throw new Exception("Directory parameter must be specified.");
            }

            // Populate the data array
            _RowData = new ArrayList();
            PopulateData(new DirectoryInfo(dir), -1);
            _ie = _RowData.GetEnumerator();
        }
        public IDataReader ExecuteReader(System.Data.CommandBehavior behavior)
        {
            if (!(behavior == CommandBehavior.SingleResult ||
                  behavior == CommandBehavior.SchemaOnly))
            {
                throw new ArgumentException("ExecuteReader supports SingleResult and SchemaOnly only.");
            }

            foreach (DataParameter dp in _Parameters)
            {
                OracleParameter op = _cmd.CreateParameter();
                op.ParameterName = dp.ParameterName;
                if (_cmd.CommandType == CommandType.StoredProcedure &&
                    dp.ParameterName.ToLower().Contains("cursor"))
                {
                    op.OracleDbType = OracleDbType.RefCursor;
                    op.Direction    = ParameterDirection.Output;
                }
                else
                {
                    op.Value = dp.Value;
                }
                _cmd.Parameters.Add(op);
            }

            return(_cmd.ExecuteReader(behavior));
        }
示例#5
0
        /// <summary>
        /// Executes a non-query.
        /// </summary>
        /// <param name="command"></param>
        /// <param name="commandBehaviour"></param>
        /// <param name="manageConnection"></param>
        /// <returns></returns>
        public static int ExecuteStoredNonQuery(this DbCommand command, System.Data.CommandBehavior commandBehaviour = System.Data.CommandBehavior.Default, bool manageConnection = true)
        {
            int numberOfRecordsAffected = -1;

            using (command)
            {
                if (command.Connection.State == System.Data.ConnectionState.Closed)
                {
                    command.Connection.Open();
                }

                try
                {
                    numberOfRecordsAffected = command.ExecuteNonQuery();
                }
                finally
                {
                    if (manageConnection)
                    {
                        command.Connection.Close();
                    }
                }
            }

            return(numberOfRecordsAffected);
        }
示例#6
0
        const int BYTES_FIELD    = 9;           // the bytes field


        public LogDataReader(System.Data.CommandBehavior behavior, LogConnection conn, LogCommand cmd)
        {
            _lconn           = conn;
            _lcmd            = cmd;
            _behavior        = behavior;
            _CompressStrings = new Hashtable(10000);                            // compress strings to save memory

            string fname = _lcmd.Url;

            _Domain = _lcmd.Domain;
            if (_Domain == null)
            {
                _Domain = "";
            }
            _IndexFile = _lcmd.IndexFile;
            if (_IndexFile == null)
            {
                _IndexFile = "";
            }

            if (behavior != CommandBehavior.SchemaOnly)
            {
                _sr = new MultipleStreamReader(_lcmd.Url);                      // get the main stream
            }
            _Data = new object[_Names.Length];                                  // allocate enough room for data
        }
        /// <summary>
        /// Executes a DbDataReader asynchronously and passes the results to <paramref name="handleResults"/>
        /// </summary>
        /// <param name="command"></param>
        /// <param name="handleResults"></param>
        /// <param name="commandBehaviour"></param>
        /// <param name="ct"></param>
        /// <param name="manageConnection"></param>
        /// <returns></returns>
        public static async Task ExecuteStoredProcAsync(this DbCommand command,
                                                        DbContext context,
                                                        Action <SprocResults> handleResults,
                                                        System.Data.CommandBehavior commandBehaviour = System.Data.CommandBehavior.Default,
                                                        CancellationToken ct = default, bool manageConnection = true)
        {
            if (handleResults == null)
            {
                throw new ArgumentNullException(nameof(handleResults));
            }

            using (command)
            {
                if (manageConnection && command.Connection.State == System.Data.ConnectionState.Closed)
                {
                    await command.Connection.OpenAsync(ct).ConfigureAwait(false);
                }
                try
                {
                    using (var reader = await command.ExecuteReaderAsync(commandBehaviour, ct)
                                        .ConfigureAwait(false))
                    {
                        var sprocResults = new SprocResults(reader, context);
                        handleResults(sprocResults);
                    }
                }
                finally
                {
                    if (manageConnection)
                    {
                        command.Connection.Close();
                    }
                }
            }
        }
示例#8
0
 public IDataReader ExecuteReader(System.Data.CommandBehavior behavior)
 {
     if (!(behavior == CommandBehavior.SingleResult ||
           behavior == CommandBehavior.SchemaOnly))
     {
         throw new ArgumentException("ExecuteReader supports SingleResult and SchemaOnly only.");
     }
     return(new XmlDataReader(behavior, _xc, this));
 }
示例#9
0
 public System.Data.IDataReader ExecuteReader(DataCommandDefinition command, System.Data.CommandBehavior commandBehavior)
 {
     return(Connection.ExecuteReader(
                new CommandDefinition(command.CommandText,
                                      command.Parameters,
                                      command.Transaction,
                                      command.CommandTimeout,
                                      command.CommandType,
                                      ToCommandFlags(command.Flags)), commandBehavior));
 }
示例#10
0
        ArrayList _Types;                               // types of the columns

        public XmlDataReader(System.Data.CommandBehavior behavior, XmlConnection conn, XmlCommand cmd)
        {
            _xconn    = conn;
            _xcmd     = cmd;
            _behavior = behavior;

            // create an iterator to the selected rows
            _xpd        = new XPathDocument(_xcmd.Url);
            _xpn        = _xpd.CreateNavigator();
            _xpni       = _xpn.Select(_xcmd.RowsXPath);         // select the rows
            _NameSpaces = new ListDictionary();
            _Names      = new ArrayList();
            _Types      = new ArrayList();

            // Now determine the actual structure of the row depending on the command
            if (_xcmd.ColumnsXPath != null)
            {
                ColumnsSpecifiedInit();                                 // xpaths to all columns specified
            }
            else
            {
                _xcmd.ColumnsXPath = new ArrayList();                                   // xpath of all columns will simply be the name

                switch (_xcmd.Type)
                {
                case "both":
                    ColumnsAttributes();
                    ColumnsElements();
                    break;

                case "attributes":
                    ColumnsAttributes();
                    break;

                case "elements":
                    ColumnsElements();
                    break;
                }
            }
            _Data = new object[_Names.Count];                                   // allocate enough room for data

            if (_NameSpaces.Count > 0)
            {
                _nsmgr = new XmlNamespaceManager(new NameTable());
                foreach (string nsprefix in _NameSpaces.Keys)
                {
                    _nsmgr.AddNamespace(nsprefix, _NameSpaces[nsprefix] as string);                     // setup namespaces
                }
            }
            else
            {
                _nsmgr = null;
            }
        }
示例#11
0
 /// <summary>
 /// Executes a Transact-SQL statement against the connection and generate SQLExecutionEvent Event
 /// </summary>
 /// <param name="ExecuteString">Executes the Transact-SQL statement or stored procedure against the connection.</param>
 /// <param name="behavior">One of the CommandBehavior values.</param>
 public void ExecuteforEvent(string ExecuteString, System.Data.CommandBehavior behavior)
 {
     PrepareExecution(ExecuteString);
     if (SQLExecutionEvent != null)
     {
         using (System.Data.SqlClient.SqlDataReader SqlRea = SqlCmd.ExecuteReader(behavior))
         {
             SQLExecutionEvent(SqlRea);
         }
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="commandBehavior"></param>
        /// <returns></returns>
        public bool ExecuteReader(System.Data.CommandBehavior commandBehavior)
        {
            dataReader = command.ExecuteReader(commandBehavior);
            result     = new SqlCommand();
            if (System.Data.CommandBehavior.SingleRow == commandBehavior)
            {
                return(dataReader.Read());
            }

            return(null != dataReader);
        }
 public void OpenReader(System.Data.CommandBehavior br)
 {
     if (cmd.Connection.State == ConnectionState.Closed)
     {
         cmd.Connection.Open();
     }
     else
     {
     }
     _dr = cmd.ExecuteReader(br);
 }
示例#14
0
 protected override DbDataReader ExecuteDbDataReader(System.Data.CommandBehavior behavior)
 {
     CheckCancel();
     if (Fail)
     {
         throw new InvalidOperationException("Failure requested");
     }
     LastCommand = "ExecuteReader";
     return(new MockDataReader()
     {
         Results = Results.GetEnumerator()
     });
 }
		const int BYTES_FIELD=9;	// the bytes field


		public GedcomDataReader(System.Data.CommandBehavior behavior, GedcomConnection conn, GedcomCommand cmd)
		{
			_lconn = conn;
			_lcmd = cmd;
			_behavior = behavior;
			
			string fname = _lcmd.Url;

			if (behavior != CommandBehavior.SchemaOnly)
				_sr = new MultipleStreamReader(_lcmd.Url);	// get the main stream

			_Data = new object[_Names.Length];			// allocate enough room for data
		}
示例#16
0
        const int BYTES_FIELD    = 9;           // the bytes field


        public GedcomDataReader(System.Data.CommandBehavior behavior, GedcomConnection conn, GedcomCommand cmd)
        {
            _lconn    = conn;
            _lcmd     = cmd;
            _behavior = behavior;

            string fname = _lcmd.Url;

            if (behavior != CommandBehavior.SchemaOnly)
            {
                _sr = new MultipleStreamReader(_lcmd.Url);                      // get the main stream
            }
            _Data = new object[_Names.Length];                                  // allocate enough room for data
        }
示例#17
0
        public DbDataReader ExecReader(string sql, List <ParamInfo> paramInfos, System.Data.CommandBehavior cmdBehavior)
        {
            SQLiteDataReader reader = null;

            if (string.IsNullOrEmpty(sql))
            {
                return(reader);
            }

            using (SQLiteCommand cmd = new SQLiteCommand())
            {
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.CommandText = sql;
                if (paramInfos != null)
                {
                    foreach (ParamInfo paramInfo in paramInfos)
                    {
                        SQLiteParameter param = new SQLiteParameter();
                        param.ParameterName = ParamPreffix + paramInfo.Name;
                        param.Value         = paramInfo.Value;
                        if (paramInfo.DBType.HasValue)
                        {
                            param.DbType = paramInfo.DBType.Value;
                        }
                        cmd.Parameters.Add(param);
                    }
                }
                cmd.Connection = m_Conn;
                if (m_Conn.State != ConnectionState.Open)
                {
                    m_Conn.Open();
                }

                try
                {
                    reader = cmd.ExecuteReader(cmdBehavior);
                }
                catch (Exception ex)
                {
                    Logger.WriteEx2LogFile(ex);
                    if (reader != null && !reader.IsClosed)
                    {
                        reader.Close();
                        reader = null;
                    }
                }

                return(reader);
            }
        }
        public static SQLiteDataReader DoQuery_Read(string sql, System.Data.CommandBehavior behaviour = System.Data.CommandBehavior.Default)
        {
            SQLiteDataReader dataReader = null;
            //try
            //{
            SQLiteCommand command = new SQLiteCommand(sql, databaseConection);

            dataReader = command.ExecuteReader(behaviour);
            //}
            //catch (Exception e)
            //{
            //    throw e;
            //}
            return(dataReader);
        }
示例#19
0
        XPathNodeIterator _xpni; // the main iterator

        #endregion Fields

        #region Constructors

        public XmlDataReader(System.Data.CommandBehavior behavior, XmlConnection conn, XmlCommand cmd)
        {
            _xconn = conn;
            _xcmd = cmd;
            _behavior = behavior;

            // create an iterator to the selected rows
            _xpd = new XPathDocument (_xcmd.Url);
            _xpn =  _xpd.CreateNavigator();
            _xpni =  _xpn.Select(_xcmd.RowsXPath);	// select the rows
            _NameSpaces = new ListDictionary();
            _Names = new ArrayList();
            _Types = new ArrayList();

            // Now determine the actual structure of the row depending on the command
            if (_xcmd.ColumnsXPath != null)
                ColumnsSpecifiedInit();			// xpaths to all columns specified
            else
            {
                _xcmd.ColumnsXPath = new ArrayList();			// xpath of all columns will simply be the name

                switch (_xcmd.Type)
                {
                    case "both":
                        ColumnsAttributes();
                        ColumnsElements();
                        break;
                    case "attributes":
                        ColumnsAttributes();
                        break;
                    case "elements":
                        ColumnsElements();
                        break;
                }
            }
            _Data = new object[_Names.Count];			// allocate enough room for data

            if (_NameSpaces.Count > 0)
            {
                _nsmgr = new XmlNamespaceManager(new NameTable());
                foreach (string nsprefix in _NameSpaces.Keys)
                {
                    _nsmgr.AddNamespace(nsprefix, _NameSpaces[nsprefix] as string); // setup namespaces
                }
            }
            else
                _nsmgr = null;
        }
示例#20
0
        protected virtual CommandBehavior SQLCommandBehaviorToCommandBehavior(SQLCommandBehavior commandBehavior)
        {
            System.Data.CommandBehavior behavior = System.Data.CommandBehavior.Default | System.Data.CommandBehavior.SingleResult;

            if ((commandBehavior & SQLCommandBehavior.KeyInfo) != 0)
            {
                behavior |= System.Data.CommandBehavior.KeyInfo;
            }

            if ((commandBehavior & SQLCommandBehavior.SchemaOnly) != 0)
            {
                behavior |= System.Data.CommandBehavior.SchemaOnly;
            }

            return(behavior);
        }
        protected override DbDataReader ExecuteDbDataReader(System.Data.CommandBehavior behavior)
        {
            List <DbCommand> statements = splitStatements();

            if (statements.Count == 0)
            {
                throw new NuoDbSqlException("No statement specified");
            }
            for (int i = 0; i < statements.Count - 1; i++)
            {
                statements[i].ExecuteNonQuery();
            }
            if (ExpectedColumnTypes != null)
            {
                return(new TypedDbReader(statements[statements.Count - 1].ExecuteReader(), ExpectedColumnTypes));
            }
            return(statements[statements.Count - 1].ExecuteReader());
        }
        public WebServiceDataReader(System.Data.CommandBehavior behavior, WebServiceConnection conn, WebServiceCommand cmd)
        {
            _wsconn = conn;
            _wscmd = cmd;
            _behavior = behavior;

            WebServiceWsdl wsw = WebServiceWsdl.GetWebServiceWsdl(_wscmd.Url);

            // build the structure of the result
            BuildMetaData(wsw);

            if (_behavior == CommandBehavior.SchemaOnly)
                return;

            // build the array that will hold the data
            BuildData(wsw);
            return;
        }
示例#23
0
		const int BYTES_FIELD=9;	// the bytes field


		public LogDataReader(System.Data.CommandBehavior behavior, LogConnection conn, LogCommand cmd)
		{
			_lconn = conn;
			_lcmd = cmd;
			_behavior = behavior;
			_CompressStrings = new Hashtable(10000);		// compress strings to save memory
			
			string fname = _lcmd.Url;
			_Domain = _lcmd.Domain;
			if (_Domain == null)
				_Domain = "";
			_IndexFile = _lcmd.IndexFile;
			if (_IndexFile == null)
				_IndexFile = "";

			if (behavior != CommandBehavior.SchemaOnly)
				_sr = new MultipleStreamReader(_lcmd.Url);	// get the main stream

			_Data = new object[_Names.Length];			// allocate enough room for data
		}
        protected override DbDataReader ExecuteDbDataReader(System.Data.CommandBehavior behavior)
        {
            try
            {
                if (this.Connection.State == ConnectionState.Open)
                {
                    Prepare();

                    return(_exec.ExecuteDataReader(this));
                }
                else
                {
                    throw new InvalidOperationException(MockDBErrors.ConnectionStateNotOpen);
                }
            }
            catch (Exception ex)
            {
                throw new MockDBException(ex.Message, ex);
            }
        }
        ArrayList _Types;                               // types of the columns

        public WebServiceDataReader(System.Data.CommandBehavior behavior, WebServiceConnection conn, WebServiceCommand cmd)
        {
            _wsconn   = conn;
            _wscmd    = cmd;
            _behavior = behavior;

            WebServiceWsdl wsw = WebServiceWsdl.GetWebServiceWsdl(_wscmd.Url);

            // build the structure of the result
            BuildMetaData(wsw);

            if (_behavior == CommandBehavior.SchemaOnly)
            {
                return;
            }

            // build the array that will hold the data
            BuildData(wsw);
            return;
        }
示例#26
0
        public iTunesDataReader(System.Data.CommandBehavior behavior, iTunesConnection conn, iTunesCommand cmd)
        {
            _xconn    = conn;
            _xcmd     = cmd;
            _behavior = behavior;

            _Data = new object[_Names.Length];                  // allocate enough room for data

            if (behavior == CommandBehavior.SchemaOnly)
            {
                return;
            }

            // create an iterator to the selected rows
            _xpd        = new XPathDocument(_xconn.File);
            _xpn        = _xpd.CreateNavigator();
            _xpni       = _xpn.Select("/plist/dict"); // select the rows
            _NameSpaces = new ListDictionary();

            // Now determine the actual structure of the row depending on the command
            switch (_xcmd.Table)
            {
            case "Tracks":
            default:
                _xpni = GetTracksColumns();
                break;
            }

            if (_NameSpaces.Count > 0)
            {
                _nsmgr = new XmlNamespaceManager(new NameTable());
                foreach (string nsprefix in _NameSpaces.Keys)
                {
                    _nsmgr.AddNamespace(nsprefix, _NameSpaces[nsprefix] as string);                     // setup namespaces
                }
            }
            else
            {
                _nsmgr = null;
            }
        }
示例#27
0
        /*
         * Because the user should not be able to directly create a
         * DataReader object, the constructors are
         * marked as internal.
         */
        internal VirtuosoDataReader(
            VirtuosoConnection connection,
            IInnerCommand innerCommand,
            VirtuosoCommand command,
            CommandBehavior commandBehavior,
            bool schemaOnly)
        {
            Debug.WriteLineIf(CLI.FnTrace.Enabled, "VirtuosoDataReader.ctor()");
            Debug.Assert(connection != null);
            Debug.Assert(innerCommand != null);

            this.connection      = connection;
            this.command         = command;
            this.innerCommand    = innerCommand;
            this.commandBehavior = commandBehavior;

            InitializeResultInfo(schemaOnly);
            if (schemaOnly)
            {
                over = true;
                last = true;
            }
        }
		public FileDirDataReader(System.Data.CommandBehavior behavior, FileDirConnection conn, FileDirCommand cmd)
		{
			_fdconn = conn;
			_fdcmd = cmd;
			_behavior = behavior;
			_FilePattern = _fdcmd.FilePattern;
			_DirectoryPattern = _fdcmd.DirectoryPattern;
			_TrimEmpty = _fdcmd.TrimEmpty;

			_Data = new object[_Names.Length];			// allocate enough room for data

			if (behavior == CommandBehavior.SchemaOnly)
				return;

			string dir = _fdcmd.Directory;
			if (dir == null)
				throw new Exception("Directory parameter must be specified.");

			// Populate the data array
			_RowData = new ArrayList();
			PopulateData(new DirectoryInfo(dir), -1);
			_ie = _RowData.GetEnumerator();
		}
示例#29
0
 /// <summary>
 /// Executes a Transact-SQL statement against the connection and returns a stream of (reading & forward-only) rows from a SQL Server database.
 /// </summary>
 /// <param name="ExecuteString">Executes the Transact-SQL statement or stored procedure against the connection.</param>
 /// <param name="behavior">One of the CommandBehavior values.</param>
 /// <returns>A SqlDataReader object.</returns>
 public System.Data.SqlClient.SqlDataReader ExecuteReader(string ExecuteString, System.Data.CommandBehavior behavior)
 {
     try
     {
         PrepareExecution(ExecuteString);
         return(SqlCmd.ExecuteReader(behavior));
     }
     catch (Exception ex)
     {
         //StreamWriter sw = new StreamWriter(HttpContext.Current.Server.MapPath("") + @"/Log/Log.txt", true);
         //sw.WriteLine(DateTime.Now.ToString() + "/" + SqlCmd.CommandText + "/" + SqlCmd.Connection.ConnectionString + "/" + ex + " => Error Occured");
         //sw.Flush();
         //sw.Close();
         return(null);
     }
 }
示例#30
0
 /// <summary>
 /// Executes a Transact-SQL statement against the connection and returns a stream of (reading & forward-only) rows from a SQL Server database.
 /// </summary>
 /// <param name="ExecuteString">Executes the Transact-SQL statement or stored procedure against the connection.</param>
 /// <param name="behavior">One of the CommandBehavior values.</param>
 /// <returns>A SqlDataReader object.</returns>
 public System.Data.SqlClient.SqlDataReader ExecuteReader(string ExecuteString, System.Data.CommandBehavior behavior)
 {
     PrepareExecution(ExecuteString);
     return(SqlCmd.ExecuteReader(behavior));
 }
		/*
		 * Because the user should not be able to directly create a 
		 * DataReader object, the constructors are
		 * marked as internal.
		 */
		internal VirtuosoDataReader (
			VirtuosoConnection connection,
			IInnerCommand innerCommand,
			VirtuosoCommand command,
			CommandBehavior commandBehavior,
			bool schemaOnly)
		{
			Debug.WriteLineIf (CLI.FnTrace.Enabled, "VirtuosoDataReader.ctor()");
			Debug.Assert (connection != null);
			Debug.Assert (innerCommand != null);

			this.connection = connection;
			this.command = command;
			this.innerCommand = innerCommand;
			this.commandBehavior = commandBehavior;

			InitializeResultInfo (schemaOnly);
			if (schemaOnly)
			{
				over = true;
				last = true;
			}
		}
示例#32
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;
            }
        }
示例#33
0
        /// <summary>
        /// Executes a DbDataReader and returns a list of mapped column values to the properties of <typeparamref name="T"/>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="command"></param>
        /// <returns></returns>
        public static void ExecuteStoredProc(this DbCommand command, Action <SprocResults> handleResults, System.Data.CommandBehavior commandBehaviour = System.Data.CommandBehavior.Default)
        {
            if (handleResults == null)
            {
                throw new ArgumentNullException(nameof(handleResults));
            }

            using (command)
            {
                if (command.Connection.State == ConnectionState.Closed)
                {
                    command.Connection.Open();
                }
                try
                {
                    using (var reader = command.ExecuteReader(commandBehaviour))
                    {
                        var sprocResults = new SprocResults(reader);
                        // return new SprocResults();
                        handleResults(sprocResults);
                    }
                }
                finally
                {
                    command.Connection.Close();
                }
            }
        }
示例#34
0
 protected override DbDataReader ExecuteDbDataReader(System.Data.CommandBehavior behavior)
 {
     return(new OracleDataReader(cmd.ExecuteReader(behavior)));
 }
示例#35
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;
			}

		}
示例#36
0
 protected override DbDataReader ExecuteDbDataReader(System.Data.CommandBehavior behavior)
 {
     return(new DaxDataReader(this._command.ExecuteReader(behavior)));
 }
        public iTunesDataReader(System.Data.CommandBehavior behavior, iTunesConnection conn, iTunesCommand cmd)
		{
			_xconn = conn;
			_xcmd = cmd;
			_behavior = behavior;

            _Data = new object[_Names.Length];			// allocate enough room for data

            if (behavior == CommandBehavior.SchemaOnly)
                return;

            // create an iterator to the selected rows
            _xpd = new XPathDocument(_xconn.File);
            _xpn = _xpd.CreateNavigator();
            _xpni = _xpn.Select("/plist/dict");	// select the rows
            _NameSpaces = new ListDictionary();

			// Now determine the actual structure of the row depending on the command
			switch (_xcmd.Table)
			{
				case "Tracks":
                default:
                    _xpni = GetTracksColumns();
					break;
			}

			if (_NameSpaces.Count > 0)
			{
				_nsmgr = new XmlNamespaceManager(new NameTable()); 
				foreach (string nsprefix in _NameSpaces.Keys)
				{
					_nsmgr.AddNamespace(nsprefix, _NameSpaces[nsprefix] as string); // setup namespaces
				}
			}
			else
				_nsmgr = null;
		}
示例#38
0
 protected override DbDataReader ExecuteDbDataReader(System.Data.CommandBehavior behavior)
 {
     throw new NotImplementedException();
 }