Esempio n. 1
0
        public int getDataSelect_SQL3(string sqlselect, OdbcConnection conex)
        {
            int res = 0;

            if (conex.State == System.Data.ConnectionState.Open)
            {
                conex.Close();
            }
            conex.Open();
            OdbcDataReader dr = null;

            try
            {
                dr = new OdbcCommand(sqlselect, conex).ExecuteReader();
                if (dr.HasRows)
                {
                    dr.Read();
                    res = dr.GetInt32(0);
                }
            }
            catch
            {
                dr  = null;
                res = 0;
                throw new Exception("Error al momento de devolver el datareader con los datos del SELECT");
            }
            return(res);
        }
Esempio n. 2
0
File: DB.cs Progetto: 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]);
            }
        }
Esempio n. 3
0
File: DB.cs Progetto: 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]);
            }
        }
Esempio n. 4
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]);
            }
        }