Example #1
0
 /// <summary>
 /// Gets the logged in GM name from the database.
 /// </summary>
 /// <returns>String containing currently logged in GM name.</returns>
 internal static string GMSELF()
 {
     using (SQLiteConnection db = OPENDB())
     {
         string queryString = "SELECT `Name` FROM `gm` WHERE `Name` = (SELECT `Data` FROM `Data` WHERE `Name` = 'Login' LIMIT 1) COLLATE NOCASE LIMIT 1";
         object result = new SQLiteCommand(queryString, db).ExecuteScalar();
         if (result == null)
             return "";
         else
             return result.ToString();
     }
 }
Example #2
0
        /// <summary>
        /// Generates a uniquely incremented ID based off of the currently logged in GM's ID and the table in question.
        /// </summary>
        /// <param name="table">The table that will require the unique ID.</param>
        /// <returns>A long integer containing a unique ID.</returns>
        internal static long GenerateUID(string table)
        {
            var db = OPENDB();
            string GM = GMSELF();
            string queryString = "SELECT MAX(ID) FROM `" + table + "` WHERE GM = '" + GM + "'  COLLATE NOCASE;";
            object result = new SQLiteCommand(queryString, db).ExecuteScalar();
            if(result != null && result.ToString() != "")
            {
                long maxID = Int64.Parse(result.ToString());

                //Create a deca-shift
                int GMID = IDFromGM(GM);
                int digitCount = (int)Math.Log10((double)GMID);
                digitCount++; //Now have the number of digits in the ID

                //Divide by the number of digits in the GMID to get rid of it.
                maxID /= (int)Math.Pow(10, digitCount);

                //Now we're left with just the increment portion. Increment it.
                maxID++;

                //Reassemble unique ID. It's out new max ID.
                maxID = long.Parse(maxID + "" + GMID);

                return maxID;
            }
            else
            {
                return long.Parse("1" + IDFromGM(GM));
            }
        }
Example #3
0
        /// <summary>
        /// Retrieve single items from the DB.
        /// </summary>
        /// <param name="sql">The query to run.</param>
        /// <returns>A string.</returns>
        public string ExecuteScalar(string sql)
        {
            SQLiteConnection connection = new SQLiteConnection(connectionString);
              try
              {
            connection.Open();

            var value = new SQLiteCommand(connection)
            {
              CommandText = sql
            }.ExecuteScalar();

            if (value != null)
            {
              return (value.ToString());
            }

            return (string.Empty);
              }
              catch
              {
            return (string.Empty);
              }
              finally
              {
            connection.Close();
              }
        }