public static Int16?GetInt16OrNull(this READER reader, int ordinal)
 {
     if (reader.IsDBNull(ordinal))
     {
         return(null);
     }
     else
     {
         return(reader.GetInt16(ordinal));
     }
 }
 public static Int16 GetInt16OrDefault(this READER reader, int ordinal) => reader.IsDBNull(ordinal) ? default : reader.GetInt16(ordinal);
Example #3
0
        //
        //-------------------------------------------------------------------------------------------------
        //
        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);
              ++i_row;
              }
            Rdr.Close();
            rows_returned = i_row;
            }
              catch (NpgsqlException 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);
        }