Advertisement
Guest User

Untitled

a guest
Jun 20th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.33 KB | None | 0 0
  1. using System;
  2.  
  3. namespace DatabaseTestings
  4. {
  5.     internal class Program
  6.     {
  7.         private static void Main()
  8.         {
  9.             var testdb = new DataBase();
  10.  
  11.             testdb.Add("GameName", "Accounts", new Accounts {Username = "KiraNL", Password = "TestPass"});
  12.             testdb.Add("GameName", "Accounts", new Accounts {Username = "MysteryPerson", Password = "MysteryPass"});
  13.  
  14.             Console.WriteLine("Tables ({0}):", testdb.Tables().Count);
  15.             foreach (string table in testdb.Tables())
  16.             {
  17.                 Console.WriteLine(table);
  18.             }
  19.  
  20.             Console.WriteLine("Rows ({0}):", testdb.Rows().Count);
  21.             foreach (string row in testdb.Rows())
  22.             {
  23.                 Console.WriteLine(row);
  24.             }
  25.  
  26.             Console.WriteLine("Test query for KiraNL:");
  27.             foreach (object row in testdb.GetRow("Accounts"))
  28.             {
  29.                 var current = (Accounts) row;
  30.  
  31.                 if (current.Username == "KiraNL")
  32.                 {
  33.                     Console.WriteLine(current.Username);
  34.                     Console.WriteLine(current.Password);
  35.                     break;
  36.                 }
  37.             }
  38.  
  39.             Console.WriteLine("Users {0}:", testdb.GetRow("Accounts").Count);
  40.             foreach (object row in testdb.GetRow("Accounts"))
  41.             {
  42.                 var current = (Accounts) row;
  43.                 Console.WriteLine(current.Username);
  44.             }
  45.  
  46.             Console.WriteLine("Test remove of KiraNL");
  47.             foreach (object row in testdb.GetRow("Accounts"))
  48.             {
  49.                 var current = (Accounts) row;
  50.  
  51.                 if (current.Username == "KiraNL")
  52.                 {
  53.                     testdb.Remove(current);
  54.                     break;
  55.                 }
  56.             }
  57.  
  58.             Console.WriteLine("Users {0}:", testdb.GetRow("Accounts").Count);
  59.             foreach (object row in testdb.GetRow("Accounts"))
  60.             {
  61.                 var current = (Accounts) row;
  62.                 Console.WriteLine(current.Username);
  63.             }
  64.             Console.ReadKey();
  65.         }
  66.  
  67.         #region Nested type: Accounts
  68.  
  69.         public struct Accounts
  70.         {
  71.             public string Password;
  72.             public string Username;
  73.         }
  74.  
  75.         #endregion
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement