Пример #1
0
        } // end ds2newmember()

//
//-------------------------------------------------------------------------------------------------
//
        public bool ds2browse(string browse_type_in, string browse_category_in, string browse_actor_in,
                              string browse_title_in, int batch_size_in, int customerid_out, ref int rows_returned,
                              ref int[] prod_id_out, ref string[] title_out, ref string[] actor_out, ref decimal[] price_out,
                              ref int[] special_out, ref int[] common_prod_id_out, ref double rt)
        {
            // Products table: PROD_ID INT, CATEGORY TINYINT, TITLE VARCHAR(50), ACTOR VARCHAR(50),
            //   PRICE DECIMAL(12,2), SPECIAL TINYINT, COMMON_PROD_ID INT
            int    i_row;
            string data_in = null;

            int[] category_out = new int[GlobalConstants.MAX_ROWS];

#if (USE_WIN32_TIMER)
            long ctr0 = 0, ctr = 0, freq = 0;
#else
            TimeSpan TS = new TimeSpan();
            DateTime DT0;
#endif
            switch (browse_type_in)
            {
            case "category":
                Browse_By_Category.Parameters["batch_size_in"].Value = batch_size_in;
                Browse_By_Category.Parameters["category_in"].Value   = Convert.ToInt32(browse_category_in);
                data_in = browse_category_in;
                break;

            case "actor":
                Browse_By_Actor.Parameters["batch_size_in"].Value = batch_size_in;
                Browse_By_Actor.Parameters["actor_in"].Value      = "\"" + browse_actor_in + "\"";
                data_in = "\"" + browse_actor_in + "\"";
                break;

            case "title":
                Browse_By_Title.Parameters["batch_size_in"].Value = batch_size_in;
                Browse_By_Title.Parameters["title_in"].Value      = "\"" + browse_title_in + "\"";
                data_in = "\"" + browse_title_in + "\"";
                break;
            }

//    Console.WriteLine("Thread {0}: Calling Browse w/ browse_type= {1} batch_size_in= {2}  data_in= {3}",
//      Thread.CurrentThread.Name, browse_type_in, batch_size_in, data_in);

#if (USE_WIN32_TIMER)
            QueryPerformanceFrequency(ref freq); // obtain system freq (ticks/sec)
            QueryPerformanceCounter(ref ctr0);   // Start response time clock
#else
            DT0 = DateTime.Now;
#endif

            try
            {
                switch (browse_type_in)
                {
                case "category":
                    Rdr = Browse_By_Category.ExecuteReader();
                    break;

                case "actor":
                    Rdr = Browse_By_Actor.ExecuteReader();
                    break;

                case "title":
                    Rdr = Browse_By_Title.ExecuteReader();
                    break;
                }

                i_row = 0;
                while (Rdr.Read())
                {
                    prod_id_out[i_row]        = Rdr.GetInt32(0);
                    category_out[i_row]       = Rdr.GetInt16(1);
                    title_out[i_row]          = Rdr.GetString(2);
                    actor_out[i_row]          = Rdr.GetString(3);
                    price_out[i_row]          = Rdr.GetDecimal(4);
                    special_out[i_row]        = Rdr.GetInt16(5);
                    common_prod_id_out[i_row] = Rdr.GetInt32(6);
                    //Console.Write("{0} ,{1} ,{2}\n", prod_id_out[i_row], title_out[i_row], actor_out[i_row]);
                    ++i_row;
                }
                Rdr.Close();
                rows_returned = i_row;
            }
            catch (PostgresException e)
            {
                Console.WriteLine("Thread {0}: Error in Browse: {1}", Thread.CurrentThread.Name, e.Message);
                return(false);
            }

#if (USE_WIN32_TIMER)
            QueryPerformanceCounter(ref ctr); // Stop response time clock
            rt = (ctr - ctr0) / (double)freq; // Calculate response time
#else
            TS = DateTime.Now - DT0;
            rt = TS.TotalSeconds; // Calculate response time
#endif

            return(true);
        } // end ds2browse()
Пример #2
0
        } // end ds2newcustomer()

//
//-------------------------------------------------------------------------------------------------
//
        public bool ds2browse(string browse_type_in, string browse_category_in, string browse_actor_in,
                              string browse_title_in, int batch_size_in, int customerid_out, ref int rows_returned,
                              ref int[] prod_id_out, ref string[] title_out, ref string[] actor_out, ref decimal[] price_out,
                              ref int[] special_out, ref int[] common_prod_id_out, ref double rt)
        {
            // Products table: PROD_ID INT, CATEGORY TINYINT, TITLE VARCHAR(50), ACTOR VARCHAR(50),
            //   PRICE DECIMAL(12,2), SPECIAL TINYINT, COMMON_PROD_ID INT
            string data_in = null;

            int[] category_out = new int[GlobalConstants.MAX_ROWS];

#if (USE_WIN32_TIMER)
            long ctr0 = 0, ctr = 0, freq = 0;
#else
            TimeSpan TS = new TimeSpan();
            DateTime DT0;
#endif
            switch (browse_type_in)
            {
            case "category":
                Browse_By_Category_prm[0].Value = batch_size_in;
                Browse_By_Category_prm[2].Value = Convert.ToInt32(browse_category_in);
                data_in = browse_category_in;
                break;

            case "actor":
                Browse_By_Actor_prm[0].Value = batch_size_in;
                Browse_By_Actor_prm[2].Value = browse_actor_in;
                data_in = browse_actor_in;
                break;

            case "title":
                Browse_By_Title_prm[0].Value = batch_size_in;
                Browse_By_Title_prm[2].Value = browse_title_in;
                data_in = browse_title_in;
                break;
            }

//    Console.WriteLine("Thread {0}: Calling Browse w/ browse_type= {1}  batch_size_in= {2}  data_in= {3}",
//      Thread.CurrentThread.Name, browse_type_in, batch_size_in, data_in);

#if (USE_WIN32_TIMER)
            QueryPerformanceFrequency(ref freq); // obtain system freq (ticks/sec)
            QueryPerformanceCounter(ref ctr0);   // Start response time clock
#else
            DT0 = DateTime.Now;
#endif

            try
            {
                switch (browse_type_in)
                {
                case "category":
                    Browse_By_Category.ExecuteNonQuery();
                    rows_returned        = (int)Browse_By_Category_prm[1].Value;
                    o_prod_id_out        = (int[])Browse_By_Category_prod_id_out.Value;
                    o_category_out       = (byte[])Browse_By_Category_category_out.Value;
                    o_title_out          = (OracleString[])Browse_By_Category_title_out.Value;
                    o_actor_out          = (OracleString[])Browse_By_Category_actor_out.Value;
                    o_price_out          = (double[])Browse_By_Category_price_out.Value;
                    o_special_out        = (int[])Browse_By_Category_special_out.Value;
                    o_common_prod_id_out = (int[])Browse_By_Category_common_prod_id_out.Value;
                    break;

                case "actor":
                    Browse_By_Actor.ExecuteNonQuery();
                    rows_returned        = (int)Browse_By_Actor_prm[1].Value;
                    o_prod_id_out        = (int[])Browse_By_Actor_prod_id_out.Value;
                    o_category_out       = (byte[])Browse_By_Actor_category_out.Value;
                    o_title_out          = (OracleString[])Browse_By_Actor_title_out.Value;
                    o_actor_out          = (OracleString[])Browse_By_Actor_actor_out.Value;
                    o_price_out          = (double[])Browse_By_Actor_price_out.Value;
                    o_special_out        = (int[])Browse_By_Actor_special_out.Value;
                    o_common_prod_id_out = (int[])Browse_By_Actor_common_prod_id_out.Value;
                    break;

                case "title":
                    Browse_By_Title.ExecuteNonQuery();
                    rows_returned        = (int)Browse_By_Title_prm[1].Value;
                    o_prod_id_out        = (int[])Browse_By_Title_prod_id_out.Value;
                    o_category_out       = (byte[])Browse_By_Title_category_out.Value;
                    o_title_out          = (OracleString[])Browse_By_Title_title_out.Value;
                    o_actor_out          = (OracleString[])Browse_By_Title_actor_out.Value;
                    o_price_out          = (double[])Browse_By_Title_price_out.Value;
                    o_special_out        = (int[])Browse_By_Title_special_out.Value;
                    o_common_prod_id_out = (int[])Browse_By_Title_common_prod_id_out.Value;
                    break;
                }
            }
            catch (OracleException e)
            {
                Console.WriteLine("Thread {0}: Error in Browse: {1}", Thread.CurrentThread.Name, e.Message);
                return(false);
            }

#if (USE_WIN32_TIMER)
            QueryPerformanceCounter(ref ctr); // Stop response time clock
            rt = (ctr - ctr0) / (double)freq; // Calculate response time
#else
            TS = DateTime.Now - DT0;
            rt = TS.TotalSeconds; // Calculate response time
#endif

//    Console.WriteLine("Thread {0}: Browse successful: type= {1}  rows_returned={2}",
//       Thread.CurrentThread.Name, browse_type_in, rows_returned);
            for (int i_row = 0; i_row < rows_returned; i_row++)
            {
                prod_id_out[i_row]        = o_prod_id_out[i_row];
                category_out[i_row]       = o_category_out[i_row];
                title_out[i_row]          = o_title_out[i_row].ToString();
                actor_out[i_row]          = o_actor_out[i_row].ToString();
                price_out[i_row]          = (decimal)o_price_out[i_row];
                special_out[i_row]        = o_special_out[i_row];
                common_prod_id_out[i_row] = o_common_prod_id_out[i_row];

//      Console.WriteLine("  prod_id= {0} category= {1} title= {2} actor= {3} price= {4} special= {5} common_prod_id= {6}",
//        prod_id_out[i_row], category_out[i_row], title_out[i_row], actor_out[i_row], price_out[i_row],
//        special_out[i_row], common_prod_id_out[i_row]);
            }

            return(true);
        } // end ds2browse()