Beispiel #1
0
            /// <summary>
            /// Select top.
            /// </summary>
            /// <param name="limit">Limit query. 0 as limit default</param>
            /// <param name="dbase">Default database</param>
            /// <param name="sql">query</param>
            /// <param name="values">parameters of query</param>
            /// <returns></returns>
            public static ResultSet3 Top(int limit, string dbase, string sql, params dynamic[] values)
            {
                var auto = String.IsNullOrEmpty(dbase);

                limit = limit < 1 ? 1000 : limit;

                using (var client = (IBaseClient)Activator.CreateInstance(_client, new object[] { auto }))
                {
                    if (!auto && client.ClientType != KCore.C.Database.ClientType.SAPClient)
                    {
                        client.Connect(dbase);
                    }

                    try
                    {
                        var rs = new ResultSet3();
                        Factory_v2.Scripts.Prepare(client.DataInfo.DBaseType, false, ref sql, values);

                        Scripts.Top(limit, ref sql);

                        if (client.DoQuery(sql, values))
                        {
                            for (int i = 0; i < client.FieldCount; i++)
                            {
                                rs.AddColumn(client.Field(i).Text);
                            }

                            while (client.Next(limit))
                            {
                                for (int i = 0; i < client.FieldCount; i++)
                                {
                                    rs.AddData(client.Field(i).Value);
                                }
                            }

                            return(rs);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    catch (Exception ex)
                    {
                        var id = Diagnostic.Track(LOG, client.LastCommand, ex.StackTrace);
                        Diagnostic.Error(R.ID, LOG, id, ex.Message);
                        throw new KDBException(LOG, C.MessageEx.ErrorExecuteQuery4_1, id);
                    }
                }
            }
Beispiel #2
0
        /// <summary>
        /// Select top.
        /// </summary>
        /// <param name="limit">Limit query. 0 as limit default</param>
        /// <param name="dbase">Default database</param>
        /// <param name="sql">query</param>
        /// <param name="values">parameters of query</param>
        /// <returns></returns>
        public static ResultSet3 Top(int limit, string dbase, string sql, params dynamic[] values)
        {
            limit = limit < 1 ? 1000 : limit;

            using (var client = Connection.GetClient(dbase))
            {
                try
                {
                    var rs = new ResultSet3();
                    Scripts.Prepare(false, ref sql, values);

                    Scripts.Top(limit, ref sql);

                    if (client.DoQuery(sql, values))
                    {
                        for (int i = 0; i < client.FieldCount; i++)
                        {
                            rs.AddColumn(client.Field(i).Text);
                        }

                        while (client.Next(limit))
                        {
                            for (int i = 0; i < client.FieldCount; i++)
                            {
                                rs.AddData(client.Field(i).Value);
                            }
                        }

                        return(rs);
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    var id = Diagnostic.Track(LOG, client.LastCommand, ex.StackTrace);
                    Diagnostic.Error(R.ID, LOG, id, ex.Message);
                    throw new KDBException(LOG, C.MessageEx.ErrorExecuteQuery4_1, id);
                }
            }
        }