Пример #1
0
Файл: Field.cs Проект: mnisl/OD
		// Handle parsing of function in final pass
		override internal void FinalPass()
		{
			if (_Value != null)
				_Value.FinalPass();

			// Resolve the field if specified
			if (_DataField != null)
			{
				Fields f = (Fields) this.Parent;
				DataSetDefn ds = (DataSetDefn) f.Parent;
				Query q = ds.Query;
				if (q != null && q.Columns != null)
				{
					qc = (QueryColumn) q.Columns[_DataField];
					if (qc == null)
					{	// couldn't find the data field
						OwnerReport.rl.LogError(8, "DataField '" + _DataField + "' not part of query.");
					}
				}
			}

			return;
		}
Пример #2
0
		// Handle parsing of function in final pass
		override internal void FinalPass()
		{
			if (_CommandText != null)
				_CommandText.FinalPass();
			if (_QueryParameters != null)
				_QueryParameters.FinalPass();

			// verify the data source
			DataSourceDefn ds=null;
			if (OwnerReport.DataSourcesDefn != null &&
				OwnerReport.DataSourcesDefn.Items != null)
			{
				ds = OwnerReport.DataSourcesDefn[_DataSourceName];
			}
			if (ds == null)
			{
				OwnerReport.rl.LogError(8, "Query references unknown data source '" + _DataSourceName + "'");
				return;
			}
			_DataSourceDefn = ds;

			IDbConnection cnSQL = ds.SqlConnect(null);
			if (cnSQL == null || _CommandText == null)
				return;

			// Treat this as a SQL statement
			String sql = _CommandText.EvaluateString(null, null);
			IDbCommand cmSQL=null;
			IDataReader dr=null;
			try 
			{
				cmSQL = cnSQL.CreateCommand();		
				cmSQL.CommandText = AddParametersAsLiterals(null, cnSQL, sql, false);
                if (this._QueryCommandType == QueryCommandTypeEnum.StoredProcedure)
                    cmSQL.CommandType = CommandType.StoredProcedure;

				AddParameters(null, cnSQL, cmSQL, false);
				dr = cmSQL.ExecuteReader(CommandBehavior.SchemaOnly);
				if (dr.FieldCount < 10)
					_Columns = new ListDictionary();	// Hashtable is overkill for small lists
				else
					_Columns = new Hashtable(dr.FieldCount);

				for (int i=0; i < dr.FieldCount; i++)
				{ 
					QueryColumn qc = new QueryColumn(i, dr.GetName(i), Type.GetTypeCode(dr.GetFieldType(i)) );

					try { _Columns.Add(qc.colName, qc); }
					catch	// name has already been added to list: 
					{	// According to the RDL spec SQL names are matched by Name not by relative
						//   position: this seems wrong to me and causes this problem; but 
						//   user can fix by using "as" keyword to name columns in Select 
						//    e.g.  Select col as "col1", col as "col2" from tableA
						OwnerReport.rl.LogError(8, String.Format("Column '{0}' is not uniquely defined within the SQL Select columns.", qc.colName));
					}
				}
			}
			catch (Exception e)
			{
				OwnerReport.rl.LogError(4, "SQL Exception during report compilation: " + e.Message + "\r\nSQL: " + sql);
			}
			finally
			{
				if (cmSQL != null)
				{
					cmSQL.Dispose();
					if (dr != null)
						dr.Close();
				}
			}

			return;
		}
Пример #3
0
        // Handle parsing of function in final pass
        override internal void FinalPass()
        {
            if (_CommandText != null)
            {
                _CommandText.FinalPass();
            }
            if (_QueryParameters != null)
            {
                _QueryParameters.FinalPass();
            }

            // verify the data source
            DataSourceDefn ds = null;

            if (OwnerReport.DataSourcesDefn != null &&
                OwnerReport.DataSourcesDefn.Items != null)
            {
                ds = OwnerReport.DataSourcesDefn[_DataSourceName];
            }
            if (ds == null)
            {
                OwnerReport.rl.LogError(8, "Query references unknown data source '" + _DataSourceName + "'");
                return;
            }
            _DataSourceDefn = ds;

            IDbConnection cnSQL = ds.SqlConnect(null);

            if (cnSQL == null || _CommandText == null)
            {
                return;
            }

            // Treat this as a SQL statement
            String      sql   = _CommandText.EvaluateString(null, null);
            IDbCommand  cmSQL = null;
            IDataReader dr    = null;

            try
            {
                cmSQL             = cnSQL.CreateCommand();
                cmSQL.CommandText = AddParametersAsLiterals(null, cnSQL, sql, false);
                if (this._QueryCommandType == QueryCommandTypeEnum.StoredProcedure)
                {
                    cmSQL.CommandType = CommandType.StoredProcedure;
                }

                AddParameters(null, cnSQL, cmSQL, false);
                dr = cmSQL.ExecuteReader(CommandBehavior.SchemaOnly);
                if (dr.FieldCount < 10)
                {
                    _Columns = new ListDictionary();                            // Hashtable is overkill for small lists
                }
                else
                {
                    _Columns = new Hashtable(dr.FieldCount);
                }

                for (int i = 0; i < dr.FieldCount; i++)
                {
                    QueryColumn qc = new QueryColumn(i, dr.GetName(i), Type.GetTypeCode(dr.GetFieldType(i)));

                    try { _Columns.Add(qc.colName, qc); }
                    catch                       // name has already been added to list:
                    {                           // According to the RDL spec SQL names are matched by Name not by relative
                                                //   position: this seems wrong to me and causes this problem; but
                                                //   user can fix by using "as" keyword to name columns in Select
                                                //    e.g.  Select col as "col1", col as "col2" from tableA
                        OwnerReport.rl.LogError(8, String.Format("Column '{0}' is not uniquely defined within the SQL Select columns.", qc.colName));
                    }
                }
            }
            catch (Exception e)
            {
                OwnerReport.rl.LogError(4, "SQL Exception during report compilation: " + e.Message + "\r\nSQL: " + sql);
            }
            finally
            {
                if (cmSQL != null)
                {
                    cmSQL.Dispose();
                    if (dr != null)
                    {
                        dr.Close();
                    }
                }
            }

            return;
        }