/// <summary> /// Get all of the rows from the Settings table. /// </summary> /// <returns>All rows from the table.</returns> public static List <KeyValueRow <string> > GetAll() { List <KeyValueRow <string> > Rows = new List <KeyValueRow <string> >(); Provider.ProviderResult result = Server.Database.ExecuteQuery( "SELECT Name, Value FROM Settings", new Dictionary <string, object>() ); if (result.Data != null && result.Data.HasRows) { while (result.Data.Read()) { // Handle NULL Value if (result.Data.IsDBNull(1)) { Rows.Add(new KeyValueRow <string>(result.Data.GetString(0), string.Empty)); } else { Rows.Add(new KeyValueRow <string>(result.Data.GetString(0), result.Data.GetString(1))); } result.Data.NextResult(); } } return(Rows); }
/// <summary> /// Get the specified counter from the KeyValueBytes table. /// </summary> /// <returns>The specified row.</returns> /// <param name="name">The key.</param> public static KeyValueRow <byte[]> Get(string name) { // Max length name = Shared.Strings.Truncate(name, 128); Provider.ProviderResult result = Server.Database.ExecuteQuery( "SELECT Size, Value FROM KeyValueBytes WHERE Name = @Name LIMIT 1", new Dictionary <string, object>() { { "@Name", name } }, System.Data.CommandBehavior.SingleResult); if (result.Data != null && result.Data.HasRows) { result.Data.Read(); // Get our datas int sizeOfData = result.Data.GetInt32(0); if (sizeOfData > 0) { byte[] readData = new byte[sizeOfData]; result.Data.GetBytes(1, 0, readData, 0, sizeOfData); return(new KeyValueRow <byte[]>(name, readData)); } return(new KeyValueRow <byte[]>(name, null)); } return(new KeyValueRow <byte[]>()); }
/// <summary> /// Get the specified row from the Settings table. /// </summary> /// <returns>The specified row.</returns> /// <param name="key">The settings key.</param> public static KeyValueRow <string> Get(string key) { key = Shared.Strings.Truncate(key, 128); Provider.ProviderResult result = Server.Database.ExecuteQuery( "SELECT Value FROM Settings WHERE Name = @Name LIMIT 1", new Dictionary <string, object>() { { "@Name", key } }, System.Data.CommandBehavior.SingleResult); if (result.Data != null && result.Data.HasRows) { result.Data.Read(); return(new KeyValueRow <string>(key, result.Data.GetString(0))); } return(new KeyValueRow <string>()); }
public static UsersRow Login(string username, string password) { UsersRow returnUser = new UsersRow(); // Hash Password password = (password + Server.Config.Salt).SHA512(); Provider.ProviderResult result = Server.Database.ExecuteQuery( "SELECT ID, Username, Scope, LastLogin FROM Users WHERE Username = @Username AND Password = @Password LIMIT 1", new Dictionary <string, object>() { { "@Username", username }, { "@Password", password } }, System.Data.CommandBehavior.SingleResult); if (result.Data != null && result.Data.HasRows) { result.Data.Read(); // Apply Data returnUser.ID = result.Data.GetInt32(0); returnUser.Username = result.Data.GetString(1); returnUser.Scope.AddRange(result.Data.GetString(2).Split(' ')); // Create if the last login is null if (!result.Data.IsDBNull(result.Data.GetOrdinal("LastLogin"))) { returnUser.LastLogin = DateTime.Parse(result.Data.GetString(3)); } // Update last login time Server.Database.ExecuteNonQuery( "UPDATE Users SET LastLogin = @LastLogin WHERE Username = @Username", new Dictionary <string, object>() { { "@LastLogin", DateTime.Now.ToLongDateString() }, { "@Username", username }, } ); } return(returnUser); }
/// <summary> /// Get the specified counter from the KeyValueInt table. /// </summary> /// <returns>The specified row.</returns> /// <param name="name">The key.</param> public static KeyValueRow <int> Get(string name) { // Max length name = Shared.Strings.Truncate(name, 128); Provider.ProviderResult result = Server.Database.ExecuteQuery( "SELECT Value FROM KeyValueInt WHERE Name = @Name LIMIT 1", new Dictionary <string, object>() { { "@Name", name } }, System.Data.CommandBehavior.SingleResult); if (result.Data != null && result.Data.HasRows) { result.Data.Read(); return(new KeyValueRow <int>(name, result.Data.GetInt32(0))); } return(new KeyValueRow <int>()); }