Example #1
0
        public static bool SetOptions(string property, DBValue value)
        {
            try
            {
                lock (thisLock)
                {
                    if (!optionsCache.ContainsKey(property) || optionsCache[property] != value)
                    {
                        // ensure our sql query will be using a valid string
                        string sqlQuery;
                        string convertedProperty = property;
                        string convertedValue    = value.ToString().Replace("'", "''");

                        if (GetOptions(property) == null)
                        {
                            sqlQuery = "INSERT INTO options (option_id, property, value) VALUES(NULL, '" + convertedProperty + "', '" + convertedValue + "')";
                        }
                        else
                        {
                            sqlQuery = "UPDATE options SET value = '" + convertedValue + "' WHERE property = '" + convertedProperty + "'";
                        }

                        optionsCache[property] = value;
                        DBTVSeries.Execute(sqlQuery);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                MPTVSeriesLog.Write("An error occurred (" + ex.Message + ").");
                return(false);
            }
        }
Example #2
0
        public void Add(DBTable table, String sField, DBValue value, SQLConditionType type)
        {
            if (table.m_fields.ContainsKey(sField))
            {
                String sValue = String.Empty;
                switch (table.m_fields[sField].Type)
                {
                case DBField.cTypeInt:
                    sValue = value;
                    break;

                case DBField.cTypeString:
                    if (type == SQLConditionType.Like || type == SQLConditionType.NotLike)
                    {
                        sValue = "'%" + ((String)value).Replace("'", "''") + "%'";
                    }
                    else
                    {
                        sValue = "'" + ((String)value).Replace("'", "''") + "'";
                    }
                    break;
                }
                AddCustom(table.m_tableName + "." + sField, sValue, type);
            }
        }
Example #3
0
        public override DBValue this[string fieldName]
        {
            get
            {
                switch (fieldName)
                {
                case cEpisodeSummary:
                    DBValue summary = base[cEpisodeSummary];
                    if (string.IsNullOrEmpty(summary))
                    {
                        summary = Translation.SummaryNotAvailable;
                    }
                    return(summary);

                case cEpisodeName:
                    DBValue title = base[cEpisodeName];
                    if (string.IsNullOrEmpty(title) && DBOption.GetOptions(DBOption.cAutoGenerateEpisodeTitles))
                    {
                        title = string.Format("{0} {1}", Translation.Episode, base[cEpisodeIndex]);
                    }
                    return(title);

                default:
                    return(base[fieldName]);
                }
            }
            set
            {
                base[fieldName] = value;
            }
        }
Example #4
0
 public DBOnlineEpisode(DBValue nSeriesID, DBValue nSeasonIndex, DBValue nEpisodeIndex)
     : base(cTableName)
 {
     InitColumns();
     if (!ReadPrimary(nSeriesID + "_" + nSeasonIndex + "x" + nEpisodeIndex))
     {
         InitValues();
     }
     this[cSeriesID]     = nSeriesID;
     this[cSeasonIndex]  = nSeasonIndex;
     this[cEpisodeIndex] = nEpisodeIndex;
 }
Example #5
0
 public bool ReadPrimary(DBValue Value)
 {
     try
     {
         m_fields[PrimaryKey()].Value = Value;
         SQLCondition condition = new SQLCondition();
         condition.Add(this, PrimaryKey(), m_fields[PrimaryKey()].Value, SQLConditionType.Equal);
         String          sqlQuery = "select * from " + m_tableName + condition;
         SQLiteResultSet records  = DBTVSeries.Execute(sqlQuery);
         return(Read(ref records, 0));
     }
     catch (Exception ex)
     {
         MPTVSeriesLog.Write("An Error Occurred (" + ex.Message + ").");
     }
     return(false);
 }
Example #6
0
        public static void GlobalSet(DBTable obj, String sKey, DBValue Value, SQLCondition conditions)
        {
            if (obj.m_fields.ContainsKey(sKey))
            {
                String sqlQuery = "update " + obj.m_tableName + " SET " + sKey + "=";
                switch (obj.m_fields[sKey].Type)
                {
                case DBField.cTypeInt:
                    sqlQuery += Value;
                    break;

                case DBField.cTypeString:
                    sqlQuery += "'" + Value + "'";
                    break;
                }

                sqlQuery += conditions;
                SQLiteResultSet results = DBTVSeries.Execute(sqlQuery);
                if (dbUpdateOccured != null)
                {
                    dbUpdateOccured(obj.m_tableName);
                }
            }
        }
Example #7
0
        public override DBValue this[String fieldName]
        {
            get
            {
                switch (fieldName)
                {
                // if the user chooses a different language for the import, we don't have this as the prettyname
                case DBOnlineSeries.cOriginalName:
                    string  origLanguage = "en";    // English (original)
                    DBValue currentTitle = base[DBOnlineSeries.cPrettyName];

                    if (DBOption.GetOptions(DBOption.cOnlineLanguage) == "en" && !DBOption.GetOptions(DBOption.cOverrideLanguage))
                    {
                        return(base[DBOnlineSeries.cPrettyName]);
                    }
                    else
                    {
                        if (base[DBOnlineSeries.cOriginalName].ToString().Length > 0)
                        {
                            return(base[DBOnlineSeries.cOriginalName]);
                        }
                        else
                        {
                            // we need to get it
                            MPTVSeriesLog.Write("Retrieving Original Series Name for '{0}'", currentTitle);
                            UpdateSeries origParser = new UpdateSeries(base[DBOnlineSeries.cID], origLanguage, true);
                            if (origParser != null && origParser.Results.Count == 1)
                            {
                                DBValue origTitle = origParser.Results[0][DBOnlineSeries.cPrettyName];

                                // there may not be an english title, so localized title is the original name
                                origTitle = string.IsNullOrEmpty(origTitle) ? base[DBOnlineSeries.cPrettyName] : origTitle;

                                // save for next time
                                base[DBOnlineSeries.cOriginalName] = origTitle;
                                Commit();

                                MPTVSeriesLog.Write("Original Series Name retrieved: '{0}'", origTitle);
                                return(origTitle);
                            }
                            else
                            {
                                // something wrong
                                MPTVSeriesLog.Write("Original Series Name could not be retrieved");
                                return(base[DBOnlineSeries.cPrettyName]);
                            }
                        }
                    }

                case cSummary:
                    DBValue summary = base[cSummary];
                    if (string.IsNullOrEmpty(summary))
                    {
                        summary = Translation.SummaryNotAvailable;
                    }
                    return(summary);

                default:
                    return(base[fieldName]);
                }
            }
            set
            {
                base[fieldName] = value;
            }
        }
Example #8
0
        public static bool SetOptions(string property, DBValue value)
        {
            try
            {
                lock (thisLock)
                {
                    if (!optionsCache.ContainsKey(property) || optionsCache[property] != value)
                    {
                        // ensure our sql query will be using a valid string
                        string sqlQuery;
                        string convertedProperty = property;
                        string convertedValue = value.ToString().Replace("'", "''");

                        if (GetOptions(property) == null)
                            sqlQuery = "INSERT INTO options (option_id, property, value) VALUES(NULL, '" + convertedProperty + "', '" + convertedValue + "')";
                        else
                            sqlQuery = "UPDATE options SET value = '" + convertedValue + "' WHERE property = '" + convertedProperty + "'";

                        optionsCache[property] = value;
                        DBTVSeries.Execute(sqlQuery);
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                MPTVSeriesLog.Write("An error occurred (" + ex.Message + ").");
                return false;
            }
        }
Example #9
0
 public static void GlobalSet(String sKey, DBValue Value, SQLCondition condition)
 {
     GlobalSet(new DBSeason(), sKey, Value, condition);
 }
Example #10
0
 public static void GlobalSet(String sKey, DBValue Value)
 {
     GlobalSet(sKey, Value, new SQLCondition());
 }
Example #11
0
 public static void GlobalSet(String sKey, DBValue Value)
 {
     GlobalSet(sKey, Value, new SQLCondition());
 }
Example #12
0
        public void AddSubQuery(string field, DBTable table, SQLCondition innerConditions, DBValue value, SQLConditionType type)
        {
            string sValue;
            if (type == SQLConditionType.Like || type == SQLConditionType.NotLike)
                sValue = "'%" + ((String)value).Replace("'", "''") + "%'";
            else
                sValue = ((String)value).Replace("'", "''");

            AddCustom("( select " + field + " from " + table.m_tableName + innerConditions + innerConditions.orderString + innerConditions.limitString +  " ) ", sValue, type);
        }
Example #13
0
 public SQLCondition(DBTable table, String sField, DBValue value, SQLConditionType type)
 {
     Add(table, sField, value, type);
 }
Example #14
0
        public void Add(DBTable table, String sField, DBValue value, SQLConditionType type)
        {
            if (table.m_fields.ContainsKey(sField))
            {
                String sValue = String.Empty;
                switch (table.m_fields[sField].Type)
                {
                    case DBField.cTypeInt:
                        sValue = value;
                        break;

                    case DBField.cTypeString:
                        if (type == SQLConditionType.Like || type == SQLConditionType.NotLike)
                            sValue = "'%" + ((String)value).Replace("'", "''") + "%'";
                        else
                            sValue = "'" + ((String)value).Replace("'", "''") + "'";
                        break;
                }
                AddCustom(table.m_tableName + "." + sField, sValue, type);
            }
        }
Example #15
0
        public static bool SetOptions(String property, DBValue value)
        {
            try
            {
                // UpdateTable();
                if (!optionsCache.ContainsKey(property) || optionsCache[property] != value)
                {
                    String convertedProperty = property;
                    String convertedvalue = value.ToString().Replace("'", "''");

                    String sqlQuery;
                    if (GetOptions(convertedProperty) == null)
                        sqlQuery = "insert into options (option_id, property, value) values(NULL, '" + convertedProperty + "', '" + convertedvalue + "')";
                    else
                        sqlQuery = "update options set value = '" + convertedvalue + "' where property = '" + convertedProperty + "'";
                    optionsCache[property] = value;
                    DBTVSeries.Execute(sqlQuery);
                }
                return true;
            }
            catch (Exception ex)
            {
                MPTVSeriesLog.Write("An Error Occurred (" + ex.Message + ").");
                return false;
            }
        }
Example #16
0
        // function override to search on both this & the onlineSeries
        public override DBValue this[String fieldName]
        {
            get
            {
                switch (fieldName)
                {
                case DBOnlineSeries.cPrettyName:
                case DBOnlineSeries.cSortName:
                    DBValue retVal = null;
                    if (m_onlineSeries != null)
                    {
                        retVal = m_onlineSeries[fieldName];
                    }

                    if (String.IsNullOrEmpty(retVal))
                    {
                        retVal = base[cParsedName];
                    }
                    return(retVal);

                case cParsedName:
                case cScanIgnore:
                case cDuplicateLocalName:
                case cHidden:
                    return(base[fieldName]);

                default:
                    if (m_onlineSeries != null)
                    {
                        return(m_onlineSeries[fieldName]);
                    }
                    else
                    {
                        return(base[fieldName]);
                    }
                }
            }

            set
            {
                switch (fieldName)
                {
                case cScanIgnore:
                case cDuplicateLocalName:
                case cHidden:
                    base[fieldName] = value;
                    break;

                case cID:
                    base[fieldName] = value;
                    if (m_onlineSeries != null)
                    {
                        m_onlineSeries[fieldName] = value;
                    }
                    break;

                case DBOnlineSeries.cSortName:
                    // Online Field is no longer populated, create it manually
                    m_onlineSeries[DBOnlineSeries.cSortName] = Helper.GetSortByName(m_onlineSeries[DBOnlineSeries.cPrettyName]);
                    break;

                case DBOnlineSeries.cPrettyName:
                    if (m_onlineSeries != null)
                    {
                        // Set sort name again just incase Pretty Name wasn't populated
                        m_onlineSeries[DBOnlineSeries.cSortName] = Helper.GetSortByName(value);
                        m_onlineSeries[fieldName] = value;
                    }
                    break;

                default:
                    if (m_onlineSeries != null)
                    {
                        m_onlineSeries[fieldName] = value;
                    }
                    break;
                }
            }
        }
Example #17
0
        public static void GlobalSet(DBTable obj, String sKey, DBValue Value, SQLCondition conditions)
        {
            if (obj.m_fields.ContainsKey(sKey))
            {
                String sqlQuery = "update " + obj.m_tableName + " SET " + sKey + "=";
                switch (obj.m_fields[sKey].Type)
                {
                    case DBField.cTypeInt:
                        sqlQuery += Value;
                        break;

                    case DBField.cTypeString:
                        sqlQuery += "'" + Value + "'";
                        break;
                }

                sqlQuery += conditions;
                SQLiteResultSet results = DBTVSeries.Execute(sqlQuery);
                if (dbUpdateOccured != null)
                    dbUpdateOccured(obj.m_tableName);
            }
        }
Example #18
0
 public bool ReadPrimary(DBValue Value)
 {
     try
     {
         m_fields[PrimaryKey()].Value = Value;
         SQLCondition condition = new SQLCondition();
         condition.Add(this, PrimaryKey(), m_fields[PrimaryKey()].Value, SQLConditionType.Equal);
         String sqlQuery = "select * from " + m_tableName + condition;
         SQLiteResultSet records = DBTVSeries.Execute(sqlQuery);
         return Read(ref records, 0);
     }
     catch (Exception ex)
     {
         MPTVSeriesLog.Write("An Error Occurred (" + ex.Message + ").");
     }
     return false;
 }
Example #19
0
        public void AddSubQuery(string field, DBTable table, SQLCondition innerConditions, DBValue value, SQLConditionType type)
        {
            string sValue;

            if (type == SQLConditionType.Like || type == SQLConditionType.NotLike)
            {
                sValue = "'%" + ((String)value).Replace("'", "''") + "%'";
            }
            else
            {
                sValue = ((String)value).Replace("'", "''");
            }

            AddCustom("( select " + field + " from " + table.m_tableName + innerConditions + innerConditions.orderString + innerConditions.limitString + " ) ", sValue, type);
        }
Example #20
0
 public DBOnlineEpisode(DBValue nSeriesID, DBValue nSeasonIndex, DBValue nEpisodeIndex)
     : base(cTableName)
 {
     InitColumns();
     if (!ReadPrimary(nSeriesID + "_" + nSeasonIndex + "x" + nEpisodeIndex))
         InitValues();
     this[cSeriesID] = nSeriesID;
     this[cSeasonIndex] = nSeasonIndex;
     this[cEpisodeIndex] = nEpisodeIndex;
 }
Example #21
0
 public SQLCondition(DBTable table, String sField, DBValue value, SQLConditionType type)
 {
     Add(table, sField, value, type);
 }
Example #22
0
 public static void GlobalSet(String sKey, DBValue Value, SQLCondition condition)
 {
     GlobalSet(new DBSeries(), sKey, Value, condition);
     GlobalSet(new DBOnlineSeries(), sKey, Value, condition);
 }
Example #23
0
 public static void GlobalSet(String sKey, DBValue Value, SQLCondition condition)
 {
     GlobalSet(new DBSeries(), sKey, Value, condition);
     GlobalSet(new DBOnlineSeries(), sKey, Value, condition);
 }