db.Database.HasUuid C# (CSharp) Method

HasUuid() public method

public HasUuid ( string uuid ) : bool
uuid string
return bool
        public bool HasUuid(string uuid)
        {
            MySqlCommand cmd = CreateQuery();
            cmd.CommandText = "SELECT COUNT(id) FROM accounts WHERE uuid=@uuid;";
            cmd.Parameters.AddWithValue("@uuid", uuid);
            return (int)(long)cmd.ExecuteScalar() > 0;
        }

Usage Example

Example #1
0
 protected override void HandleRequest()
 {
     using (var db = new Database())
     {
         if (!IsUsername(Query["newGUID"])) WriteErrorLine("Invalid Username");
         else
         {
             if (db.HasUuid(Query["guid"]) && db.Verify(Query["guid"], "") != null)
             {
                 if (db.HasUuid(Query["newGUID"])) WriteErrorLine("Username is already taken");
                 else
                 {
                     var cmd = db.CreateQuery();
                     cmd.CommandText = "UPDATE accounts SET uuid=@newUuid, name=@newUuid, password=SHA1(@password), guest=FALSE WHERE uuid=@uuid, name=@name;";
                     cmd.Parameters.AddWithValue("@uuid", Query["guid"]);
                     cmd.Parameters.AddWithValue("@newUuid", Query["newGUID"]);
                     cmd.Parameters.AddWithValue("@password", Query["newPassword"]);
                     if (cmd.ExecuteNonQuery() > 0) Success();
                     else WriteErrorLine("Internal Error");
                 }
             }
             else
             {
                 if (db.Register(Query["newGUID"], Query["newPassword"], false) != null) Success();
                 else WriteErrorLine("Internal Error");
             }
         }
     }
 }
All Usage Examples Of db.Database::HasUuid