예제 #1
0
 public void AddToParameters(SQLiteParameterCollection parameters)
 {
     parameters.Clear();
     parameters.AddWithValue("id", this.Id);
     parameters.AddWithValue("text", this.Text);
     parameters.AddWithValue("lang", this.Language);
     parameters.AddWithValue("trans_of", this.TranslationOf);
 }
예제 #2
0
 /// <summary>
 /// Clears the parameters added with <see cref="SinCraft.SQL.MySQL.AddParams(System.string, System.string)"/>
 /// <seealso cref="SinCraft.SQL.MySQL"/>
 /// </summary>
 public static void ClearParams()
 {
     parameters.Clear();
 }
예제 #3
0
 //Limpar parametros
 public static void LimparParametros()
 {
     sqlParameterCollection.Clear();
 }
예제 #4
0
 public void LimparParametros()
 {
     sQLiteParameterCollection.Clear();
 }
예제 #5
0
 static public void Set(this SQLiteParameterCollection item, IEnumerable <SQLiteParameter> to_add)
 {
     item.Clear();
     item.AddRange(to_add);
 }
예제 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sqlCommand"></param>
        /// <param name="dt"></param>
        /// <param name="queryResult"></param>
        /// <returns></returns>
        public bool Execute(SQLiteCommand sqlCommand, ref DataSet dt, out string queryResult)
        {
            bool salida;
            bool isNonQuery = false;

            try
            {
                //using (SQLiteConnection conn = new SQLiteConnection(_strConnectionString))
                //{
                using (SQLiteCommand sqLiteCommand = new SQLiteCommand())
                {
                    sqLiteCommand.CommandText = sqlCommand.CommandText;
                    sqLiteCommand.Connection  = _objCn;

                    if (sqlCommand.Parameters.Count != 0)
                    {
                        SQLiteParameterCollection sp = sqlCommand.Parameters;

                        foreach (SQLiteParameter param in sp)
                        {
                            sqLiteCommand.Parameters.Add(param);
                        }

                        sp.Clear();
                    }


                    //------------------------------------
                    string commandText    = sqLiteCommand.CommandText.ToUpper();
                    string initialCommand = commandText.Trim().Substring(0, 6);
                    if (
                        initialCommand.Contains("DELETE") ||
                        initialCommand.Contains("UPDATE") ||
                        initialCommand.Contains("INSERT")
                        )
                    {
                        isNonQuery = true;
                    }

                    if (isNonQuery)
                    {
                        //Este tipo de consulta, sólo devuelve resultados en queryResult si es un INSERT,DELETE,UPDATE.
                        queryResult = sqLiteCommand.ExecuteNonQuery().ToString();
                    }
                    else
                    {
                        //El objeto DataAdapter .NET de proveedor de datos está ajustado para leer registros en un objeto DataSet.
                        //Este tipo de consulta, sólo devuelve resultados en queryResult si es una SELECT.
                        using (SQLiteDataAdapter DataAdapter = new SQLiteDataAdapter(sqLiteCommand))
                        {
                            queryResult = DataAdapter.Fill(dt).ToString();
                        }
                    }
                    //------------------------------------

                    //Close all objects.
                    sqlCommand.Dispose();
                    sqlCommand = null;
                }
                //}

                salida = true;

                bool timeoutPatterIsFound = false;
                CheckResult(queryResult, out timeoutPatterIsFound);

                if (timeoutPatterIsFound)
                {
                    salida = Execute(sqlCommand, ref dt, out queryResult);
                }
            }
            catch (Exception ex)
            {
                salida      = false;
                queryResult = ex.Message + "-" + sqlCommand.CommandText;

                bool timeoutPatterIsFound = false;
                CheckResult(queryResult, out timeoutPatterIsFound);

                if (timeoutPatterIsFound)
                {
                    salida = Execute(sqlCommand, ref dt, out queryResult);
                }

                sqlCommand.Dispose();
            }

            _error = queryResult;


            return(salida);
        }
예제 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sqlCommand"></param>
        /// <param name="dt"></param>
        /// <param name="queryResult"></param>
        /// <returns></returns>
        public bool ExecuteStandAlone(SQLiteCommand sqlCommand, ref DataSet dt, out string queryResult)
        {
            bool salida;
            bool isNonQuery = false;

            try
            {
                using (SQLiteConnection conn = new SQLiteConnection(_strConnectionString))
                {
                    using (SQLiteCommand sqLiteCommand = new SQLiteCommand())
                    {
                        sqLiteCommand.CommandText = sqlCommand.CommandText;
                        sqLiteCommand.Connection  = conn;

                        conn.Open();

                        if (sqlCommand.Parameters.Count != 0)
                        {
                            SQLiteParameterCollection sp = sqlCommand.Parameters;

                            foreach (SQLiteParameter param in sp)
                            {
                                sqLiteCommand.Parameters.Add(param);
                            }

                            sp.Clear();
                        }

                        //------------------------------------
                        if (
                            sqLiteCommand.CommandText.ToUpper().Contains("DELETE") ||
                            sqLiteCommand.CommandText.ToUpper().Contains("UPDATE") ||
                            sqLiteCommand.CommandText.ToUpper().Contains("INSERT")
                            )
                        {
                            isNonQuery = true;
                        }

                        if (isNonQuery)
                        {
                            //Este tipo de consulta, sólo devuelve resultados en queryResult si es un INSERT,DELETE,UPDATE.
#if DEBUG
                            //queryResult = "Timeout Expired";
                            queryResult = sqLiteCommand.ExecuteNonQuery().ToString();
#else
                            queryResult = sqLiteCommand.ExecuteNonQuery().ToString();
#endif
                        }
                        else
                        {
                            //El objeto DataAdapter .NET de proveedor de datos está ajustado para leer registros en un objeto DataSet.
                            //Este tipo de consulta, sólo devuelve resultados en queryResult si es una SELECT.
                            using (SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter(sqLiteCommand))
                            {
#if DEBUG
                                //queryResult = "Timeout Expired";
                                queryResult = dataAdapter.Fill(dt).ToString();
#else
                                queryResult = dataAdapter.Fill(dt).ToString();
#endif
                            }
                        }
                        //------------------------------------

                        salida = true;

                        //Close all objects.
                        sqlCommand.Dispose();
                        sqlCommand = null;
                    }

                    //2016/10/03-GeMesoft: new
                    conn.Close();

                    bool timeoutPatterIsFound = false;
                    CheckResult(queryResult, out timeoutPatterIsFound);

                    if (timeoutPatterIsFound)
                    {
                        salida = ExecuteStandAlone(sqlCommand, ref dt, out queryResult);
                    }
                }
            }
            catch (Exception ex)
            {
                salida      = false;
                queryResult = ex.Message + "-" + sqlCommand.CommandText;

                bool timeoutPatterIsFound = false;
                CheckResult(queryResult, out timeoutPatterIsFound);

                if (timeoutPatterIsFound)
                {
                    salida = ExecuteStandAlone(sqlCommand, ref dt, out queryResult);
                }
            }

            _error = queryResult;

            return(salida);
        }
예제 #8
0
 public void LimparParametro()
 {
     liteParameterCollection.Clear();
 }