Exemplo n.º 1
0
Arquivo: DB.cs Projeto: EudesFR/HRWCMS
        /// <summary>
        /// Performs a SQL query and returns all vertical matching fields as an Integer array. Only the first supplied columname is looked for.
        /// </summary>
        /// <param name="Query">The SQL query that selects a column.</param>
        /// <param name="maxResults">Adds as LIMIT to the query. Using this, the array will never return more than xx fields in of the column. When maxResults is supplied as 0, then there is no max limit.</param>
        /// <param name="Tick">Just to differ the runReadColumn functions; supply a null if you want to use this overload.</param>
        public static int[] runReadColumn(string Query, int maxResults, object Tick)
        {
            if (maxResults > 0)
            {
                Query += " LIMIT " + maxResults;
            }
            try
            {
                ArrayList      columnBuilder = new ArrayList();
                OdbcDataReader columnReader  = new OdbcCommand(Query, dbConnection).ExecuteReader();

                while (columnReader.Read())
                {
                    try { columnBuilder.Add(columnReader.GetInt32(0)); }
                    catch { columnBuilder.Add(0); }
                }
                columnReader.Close();
                return((int[])columnBuilder.ToArray(typeof(int)));
            }

            catch (Exception ex)
            {
                Out.WriteError("Error '" + ex.Message + "' at '" + Query + "'");
                return(new int[0]);
            }
        }
Exemplo n.º 2
0
Arquivo: DB.cs Projeto: EudesFR/HRWCMS
        /// <summary>
        /// Performs a SQL query and returns the selected in the first found row as an Integer array. Useable for only one row.
        /// </summary>
        /// <param name="Query">The SQL query that selects a row and the fields to get. LIMIT 1 is added.</param>
        /// <param name="Tick">Just to differ the runReadRow functions; supply a null if you want to use this overload.</param>
        public static int[] runReadRow(string Query, object Tick)
        {
            try
            {
                ArrayList      rowBuilder = new ArrayList();
                OdbcDataReader rowReader  = new OdbcCommand(Query + " LIMIT 1", dbConnection).ExecuteReader();

                while (rowReader.Read())
                {
                    for (int i = 0; i < rowReader.FieldCount; i++)
                    {
                        try { rowBuilder.Add(rowReader.GetInt32(i)); }
                        catch { rowBuilder.Add(0); }
                    }
                }
                rowReader.Close();
                return((int[])rowBuilder.ToArray(typeof(int)));
            }

            catch (Exception ex)
            {
                Out.WriteError("Error '" + ex.Message + "' at '" + Query + "'");
                return(new int[0]);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Performs a SQL query and returns all vertical matching fields as a String array. Only the first supplied columname is looked for.
        /// </summary>
        /// <param name="Query">The SQL query that selects a column.</param>
        /// <param name="maxResults">Adds as LIMIT to the query. Using this, the array will never return more than xx fields in of the column. When maxResults is supplied as 0, then there is no max limit.</param>
        public static string[] runReadColumn(string Query, int maxResults)
        {
            if (maxResults > 0)
            {
                Query += " LIMIT " + maxResults;
            }

            try
            {
                ArrayList      columnBuilder = new ArrayList();
                OdbcDataReader columnReader  = new OdbcCommand(Query, dbConnection).ExecuteReader();

                while (columnReader.Read())
                {
                    try { columnBuilder.Add(columnReader[0].ToString()); }
                    catch { columnBuilder.Add(""); }
                }
                columnReader.Close();

                return((string[])columnBuilder.ToArray(typeof(string)));
            }

            catch (Exception ex)
            {
                Log.AppendText("Error '" + ex.Message + "' at '" + Query + "'");
                return(new string[0]);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Performs a SQL query and returns the selected in the first found row as a String array. Useable for only one row.
        /// </summary>
        /// <param name="Query">The SQL query that selects a row and the fields to get. LIMIT 1 is added.</param>
        public static string[] runReadRow(string Query)
        {
            try
            {
                ArrayList      rowBuilder = new ArrayList();
                OdbcDataReader rowReader  = new OdbcCommand(Query + " LIMIT 1", dbConnection).ExecuteReader();

                while (rowReader.Read())
                {
                    for (int i = 0; i < rowReader.FieldCount; i++)
                    {
                        try { rowBuilder.Add(rowReader[i].ToString()); }
                        catch { rowBuilder.Add(""); }
                    }
                }
                rowReader.Close();
                return((string[])rowBuilder.ToArray(typeof(string)));
            }

            catch (Exception ex)
            {
                Log.AppendText("Error '" + ex.Message + "' at '" + Query + "'");
                return(new string[0]);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Performs a SQL query and returns all vertical matching fields as an integer array. Only the first supplied columname is looked for.
        /// </summary>
        /// <param name="Query">The SQL query that selects a column.</param>
        /// <param name="maxResults">Adds as LIMIT to the query. Using this, the array will never return more than xx fields in of the column. When maxResults is supplied as 0, then there is no max limit.</param>
        public static int[] runReadColumnIntegers(string Query, int maxResults)
        {
            if (maxResults > 0)
            {
                Query += " LIMIT " + maxResults;
            }

            try
            {
                ArrayList      columnBuilder = new ArrayList();
                OdbcDataReader columnReader  = new OdbcCommand(Query, dbConnection).ExecuteReader();

                while (columnReader.Read())
                {
                    try { columnBuilder.Add((int)columnReader[0]); }
                    catch { columnBuilder.Add(0); }
                }
                columnReader.Close();

                return((int[])columnBuilder.ToArray(typeof(int)));
            }
            catch (Exception ex)
            {
                Logging.logError(ex.Message + ", query = " + Query);
                return(new int[0]);
            }
        }
Exemplo n.º 6
0
        public string retrievePatchDB()
        {
            OdbcDataReader odbcDataReader = new OdbcCommand("select i_unique from i_patch", this.MyConnection).ExecuteReader();
            int            num            = 0;

            while (odbcDataReader.Read())
            {
                ++num;
            }
            odbcDataReader.Close();
            return(num.ToString());
        }
Exemplo n.º 7
0
        public double Sumar_Valores_de_Campos(string sqlsum)
        {
            double         res = 0;
            OdbcDataReader dr  = null;

            if (conexion.State == ConnectionState.Open)
            {
                conexion.Close();
            }
            conexion.Open();
            try
            {
                dr = new OdbcCommand(sqlsum, conexion).ExecuteReader();
                if (dr.HasRows)
                {
                    dr.Read();
                    if (dr.IsDBNull(0))
                    {
                        res = 0;
                    }
                    else
                    {
                        res = Convert.ToDouble(dr.GetValue(0));
                    }
                }
                //if (Convert.ToDouble(new OdbcCommand(sqlsum, conexion).ExecuteScalar()) >= 0)
                //{
                //    res = Convert.ToDouble(new OdbcCommand(sqlsum, conexion).ExecuteScalar());
                //}
                //else
                //{
                //    res = 0;
                //}
            }
            catch (Exception ex)
            {
                res = 0;
                MessageBox.Show("Error al momento de realizar la suma de valores de la Data Base: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                dr.Close();
            }
            return(res);
        }
Exemplo n.º 8
0
        private int AddRESBTN(String sql_t0, Form_Search_Res s_res_frm)
        {
            Font btnfont = new Font("新細明體", 12.0f);

            System.Drawing.Size btnsize = new System.Drawing.Size(300, 60);
            int            res_count    = 0;
            OdbcDataReader dr           = new OdbcCommand(sql_t0, conn).ExecuteReader();

            while (dr.Read())
            {
                string btntxt = format_btntext(dr);
                Button btn    = new Button();
                btn.Text   = btntxt;
                btn.Size   = btnsize;
                btn.Font   = btnfont;
                btn.Click += btn_Click;
                s_res_frm.flowLayoutPanel1.Controls.Add(btn);
                res_count++;
            }
            dr.Close();
            dr.Dispose();
            return(res_count++);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Performs a SQL query and returns the selected in the first found row as a Integer array. Usable for only one row.
        /// </summary>
        /// <param name="Query">The SQL query that selectes a row and the fields to get. LIMIT 1 is added.</param>
        public static int[] runReadRowIntegers(string Query)
        {
            try
            {
                ArrayList      rowBuilder = new ArrayList();
                OdbcDataReader rowReader  = new OdbcCommand(Query + " LIMIT 1", dbConnection).ExecuteReader();

                while (rowReader.Read())
                {
                    for (int i = 0; i < rowReader.FieldCount; i++)
                    {
                        try { rowBuilder.Add(rowReader.GetInt32(i)); }
                        catch { rowBuilder.Add(0); }
                    }
                }
                rowReader.Close();
                return((int[])rowBuilder.ToArray(typeof(int)));
            }
            catch (Exception ex)
            {
                Logging.logError(ex.Message + ", query = " + Query);
                return(new int[0]);
            }
        }
Exemplo n.º 10
0
        public bool SelectCommand(string sql_command, ref ArrayList ret_objection, ref DB_Statement db_st, ref DB_Result db_res)
        {
            if (!this.IsBackup)
            {
                this.i_monCpu.start_SQL();
            }
            ArrayList ret_list = new ArrayList();

            db_st.ExportLabels(ref ret_list);
            try
            {
                OdbcDataReader odbcDataReader = new OdbcCommand(sql_command, this.MyConnection).ExecuteReader();
                if (db_st.IsCount)
                {
                    if (odbcDataReader.Read())
                    {
                        db_st.count_Value = odbcDataReader.GetInt64(0);
                    }
                }
                else if (db_st.IsDistinct)
                {
                    while (odbcDataReader.Read())
                    {
                        string data = db_st.processExceptions(odbcDataReader[db_st.m_Distinct].ToString());
                        if (!db_st.var_distinct.Contains((object)data))
                        {
                            db_st.var_distinct.Add((object)data);
                            DB_Row new_row = new DB_Row();
                            new_row.allocField(data, db_st.m_Distinct);
                            db_res.AddRow(ref new_row);
                        }
                    }
                    db_st.var_distinct.Clear();
                }
                else if (db_st.IsSum)
                {
                    while (odbcDataReader.Read())
                    {
                        db_st.nu_sum += odbcDataReader.GetInt64(0);
                    }
                }
                else
                {
                    int  varMaxRowsRead = db_st.var_maxRowsRead;
                    bool flag           = false;
                    if (varMaxRowsRead > 0)
                    {
                        flag = true;
                    }
                    while (odbcDataReader.Read())
                    {
                        DB_Row new_row = new DB_Row();
                        for (int index = 0; index < ret_list.Count; ++index)
                        {
                            string label = ret_list[index] as string;
                            new_row.allocField(db_st.processExceptions(odbcDataReader[label].ToString()), label);
                        }
                        db_res.AddRow(ref new_row);
                        if (flag && --varMaxRowsRead == 0)
                        {
                            break;
                        }
                    }
                }
                odbcDataReader.Close();
            }
            catch (Exception ex)
            {
                ret_objection.Add((object)("##### SQL Failure: " + sql_command));
                ret_objection.Add((object)("##### Error: " + ex.Message));
                if (!this.IsBackup)
                {
                    this.i_monCpu.end_SQL();
                }
                return(false);
            }
            if (!this.IsBackup)
            {
                this.i_monCpu.end_SQL();
            }
            return(true);
        }