private static int?GetMessageTypeByName(MessageType type, int times = 1)
        {
            while (true)
            {
                if (times < 0)
                {
                    return(null);
                }

                const string q1            = "SELECT id FROM MessageTypes WHERE name = @name";
                var          keyValuePairs = new Dictionary <string, object> {
                    { "@name", type.ToString() }
                };
                var r1 = SqLite.ExecuteSelect(q1, keyValuePairs);
                var r2 = SqLite.GetFirstValueFromDataTable(r1);
                if (r1 == null || r1.Rows.Count == 0 || r2 == null)
                {
                    AddMessageType(type);
                    times--;
                    continue;
                }

                try
                {
                    return(Convert.ToInt32(r2));
                }
                catch
                {
                    return(null);
                }
            }
        }
Example #2
0
        internal static int GetMaxId(string tableName, string columnIdName)
        {
            var q  = "SELECT MAX(" + columnIdName + ") FROM " + tableName;
            var r  = SqLite.ExecuteSelect(q);
            var r2 = SqLite.GetFirstValueFromDataTable(r);

            if (r2 == null)
            {
                return(0);
            }

            try
            {
                return(Convert.ToInt32(r2));
            }
            catch
            {
                return(0);
            }
        }