Ejemplo n.º 1
0
        /// <summary>
        /// Run this Database query.
        /// If FReportingQueryCancelFlag is set, this returns immediately with an empty table.
        /// The query can be cancelled WHILE IT IS RUNNING. In this case the returned table may be partially filled.
        /// </summary>
        /// <remarks>For details on the Arguments that can be passed with <paramref name="AOptionalColumnNameMapping"/>,
        /// <paramref name="ASelectCommandTimeout"/>, <paramref name="AParameterDefinitions"/>,
        /// <paramref name="AParameterValues"/>, <paramref name="APrepareSelectCommand"/>,
        /// <paramref name="AProgressUpdateEveryNRecs"/> and
        /// <paramref name="AMultipleParamQueryProgressUpdateCallback"/> please see their respective XML Comments on
        /// Method <see cref="TDataBase.SelectUsingDataAdapterMulti"/>!/</remarks>
        /// <returns>DataTable. May be empty (even with no fields defined!) if cancellation happens or has happened.</returns>
        public DataTable RunQueryMultiParams(String Query, String TableName, TDBTransaction Trans,
                                             TDataBase.TOptionalColumnMappingDelegate AOptionalColumnNameMapping = null,
                                             int ASelectCommandTimeout  = -1, DbParameter[] AParameterDefinitions = null, List <object[]> AParameterValues = null,
                                             bool APrepareSelectCommand = false, Int16 AProgressUpdateEveryNRecs  = 0,
                                             TDataBase.MultipleParamQueryProgressUpdateDelegate AMultipleParamQueryProgressUpdateCallback = null)
        {
            var ResultDT = new DataTable(TableName);

            try
            {
                FPrivateDatabaseObj.SelectUsingDataAdapterMulti(Query, Trans, ref ResultDT,
                                                                AOptionalColumnNameMapping, ASelectCommandTimeout, AParameterDefinitions, AParameterValues,
                                                                APrepareSelectCommand, AProgressUpdateEveryNRecs, AMultipleParamQueryProgressUpdateCallback);
            }
            catch (PostgresException Exp)
            {
                if (Exp.SqlState == "57014")  // Exception with Code 57014 is what Npgsql raises as a response to a Cancel request of a Command
                {
                    TLogging.LogAtLevel(7, this.GetType().FullName + ".RunQuery: Query got cancelled; proper reply from Npgsql!");
                }
                else if (Exp.SqlState == "25P02") // Exception with Code 25P02 is what Npgsql raises as a response to a cancellation of a request of a Command when that happens in another code path (eg. on a different Thread [e.g. Partner Find
                {                                 // screen: Cancel got pressed while Report Query ran, for instance])
                    TLogging.LogAtLevel(1, this.GetType().FullName +
                                        ".RunQuery: Query got cancelled (likely trought another code path [likely on another Thread]); proper reply from Npgsql!");
                }
                else
                {
                    TLogging.Log(this.GetType().FullName + ".RunQuery: Query got cancelled; general PostgresException occured: " + Exp.ToString());
                }

                return(null);
            }
            catch (Exception Exc)
            {
                TLogging.Log("ReportingQueryWithCancelOption: Query Raised exception: " + Exc.ToString() +
                             "\nQuery: " + Query);

                FRunQueryException = Exc;

                /*
                 *     WE MUST 'SWALLOW' ANY EXCEPTION HERE, OTHERWISE THE WHOLE
                 *     PETRASERVER WILL GO DOWN!!! (THIS BEHAVIOUR IS NEW WITH .NET 2.0.)
                 *
                 * --> ANY EXCEPTION THAT WOULD LEAVE THIS METHOD WOULD BE SEEN AS AN   <--
                 * --> UNHANDLED EXCEPTION IN A THREAD, AND THE .NET/MONO RUNTIME       <--
                 * --> WOULD BRING DOWN THE WHOLE PETRASERVER PROCESS AS A CONSEQUENCE. <--
                 *
                 */
            }

            return(ResultDT);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Run this Database query.
        /// If FReportingQueryCancelFlag is set, this returns immediately with an empty table.
        /// The query can be cancelled WHILE IT IS RUNNING. In this case the returned table may be partially filled.
        /// </summary>
        /// <returns>DataTable. May be empty (even with no fields defined!) if cancellation happens or has happened.</returns>
        public DataTable RunQuery(String Query, String TableName, TDBTransaction Trans,
                                  TDataBase.TOptionalColumnMappingDelegate AOptionalColumnNameMapping = null,
                                  int ASelectCommandTimeout = -1, DbParameter[] AParametersArray = null)
        {
            List <object[]> ParameterValues = null;
            List <object>   ObjectValues    = null;

            if (AParametersArray != null)
            {
                ParameterValues = new List <object[]>(1);
                ObjectValues    = new List <object>();

                for (int Counter = 0; Counter < AParametersArray.Length; Counter++)
                {
                    ObjectValues.Add(AParametersArray[Counter].Value);
                }

                ParameterValues.Add(ObjectValues.ToArray());
            }

            return(RunQueryMultiParams(Query, TableName, Trans, AOptionalColumnNameMapping,
                                       ASelectCommandTimeout, AParametersArray, ParameterValues, false));
        }