コード例 #1
0
        /// <summary>
        /// 在【主库】执行
        /// </summary>
        /// <param name="cmdType"></param>
        /// <param name="cmdText"></param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        async public Task <object> ExecuteScalarAsync(CommandType cmdType, string cmdText, params MySqlParameter[] cmdParms)
        {
            DateTime dt     = DateTime.Now;
            string   logtxt = "";
            Object <MySqlConnection> conn = null;
            MySqlCommand             cmd  = PrepareCommandAsync(cmdType, cmdText, cmdParms, ref logtxt);
            DateTime  logtxt_dt           = DateTime.Now;
            object    val = null;
            Exception ex  = null;

            try {
                if (cmd.Connection == null)
                {
                    cmd.Connection = (conn = await this.MasterPool.GetAsync()).Value;
                }
                val = await cmd.ExecuteScalarAsync();
            } catch (Exception ex2) {
                ex = ex2;
            }

            if (conn != null)
            {
                if (IsTracePerformance)
                {
                    logtxt_dt = DateTime.Now;
                }
                this.MasterPool.Return(conn, ex);
                if (IsTracePerformance)
                {
                    logtxt += $"ReleaseConnection: {DateTime.Now.Subtract(logtxt_dt).TotalMilliseconds}ms Total: {DateTime.Now.Subtract(dt).TotalMilliseconds}ms";
                }
            }
            LoggerException(this.MasterPool, cmd, ex, dt, logtxt);
            cmd.Parameters.Clear();
            return(val);
        }
コード例 #2
0
ファイル: CrudUsuario.cs プロジェクト: oscarito9410/wpHotel
        public override async Task<bool> exists(object table)
        {
            var usuario = this.getCastUsuario(table);
            using (MySqlConnection MidbConexion = new MySqlConnection(this.dbPath))
            {
                MidbConexion.Open();//Abrimos la conexion para realizar los siguientes pasos
                // 'Declaro comando para poder realizar mis instrucciones sql
                MySqlCommand micomando = new MySqlCommand { Connection = MidbConexion, CommandText = "SELECT*FROM usuario WHERE nombre=?Nom AND Password=?Pass" };
                micomando.Parameters.AddWithValue("?Nom", usuario.nombre);
                micomando.Parameters.AddWithValue("?Pass", usuario.password);
                Console.WriteLine("NOMBRE {0}", usuario.nombre);
                Console.WriteLine("Passwor {0}", usuario.password);
                int numEncontrado = Convert.ToInt32(await micomando.ExecuteScalarAsync());
                if (numEncontrado == 0)
                {
                    return false;
                }
                else
                {
                    return true;
                }

            }
        }
コード例 #3
0
 private async void GetInCalls()
 {
     using (MySqlConnection dbConn = new MySqlConnection("Server=" + ICResponse.Properties.Settings.Default.DBServer +
                                                 ";Database=" + ICResponse.Properties.Settings.Default.DBName +
                                                 ";Uid=" + ICResponse.Properties.Settings.Default.DBUser +
                                                 ";Pwd=" + ICResponse.Properties.Settings.Default.DBPass + ";"))
     {
         dbConn.Open();
         using (MySqlCommand cmd = new MySqlCommand(ICResponse.Properties.Settings.Default.GetInCallCounts, dbConn))
         {
             incallcount = Convert.ToInt32(await cmd.ExecuteScalarAsync());
             InCallSector.Count = incallcount;
         }
         dbConn.Close();
     }
 }
コード例 #4
0
ファイル: Database.cs プロジェクト: Hotallday/iXat-Server
 public static async Task<object> query(string query) {
     using (var command = new MySqlCommand(query, Connection)) {
         return await command.ExecuteScalarAsync();
     }
 }
コード例 #5
0
ファイル: ICrudHelper.cs プロジェクト: oscarito9410/wpHotel
        public async Task<bool> isUpdate(String tableName, String idColumn, int idValue)
        {
            using (MySqlConnection MidbConexion = new MySqlConnection(this.dbPath))
            {
                MidbConexion.Open();
                MySqlCommand miComando = new MySqlCommand()
                {
                    Connection = MidbConexion,
                    CommandText = String.Format("SELECT COUNT(*) FROM {0} WHERE {1}=?id", tableName, idColumn)
                };
                miComando.Parameters.AddWithValue("?id", idValue);
                return Convert.ToInt32(await miComando.ExecuteScalarAsync()) == 0 ? false : true;

            }
        }
コード例 #6
0
 public async Task<object> ExecuteScalar(MySqlCommand stmt)
 {
     object result = null;
     if (connState == ConnectionState.Open)
     {
         try
         {
             result = await stmt.ExecuteScalarAsync();
         }
         catch (MySqlException e)
         {
             Logger.LOG_DATABASE.Error("Could not execute prepared statement " + stmt.ToString() + " as scalar. " + e.Message);
         }
     }
     return result;
 }