Exemplo n.º 1
0
        public virtual bool AddColumn(String sName, DBField field)
        {
            // verify if we already have that field avail
            if (!m_fields.ContainsKey(sName))
            {
                if (m_fields.Count == 0 && !field.Primary)
                {
                    throw new Exception("First field added needs to be the index");
                }

                try
                {
                    // ok, we don't, add it
                    SQLiteResultSet results;
                    results = DBTVSeries.Execute("SELECT name FROM sqlite_master WHERE name='" + m_tableName + "'");
                    if (results != null && results.Rows.Count > 0)
                    {
                        // table already exists, alter it
                        String sQuery = "ALTER TABLE " + m_tableName + " ADD " + sName + " " + field.Type;
                        DBTVSeries.Execute(sQuery);
                    }
                    else
                    {
                        // new table, create it
                        // no tables, assume it's going to be created later (using AddColumn)
                        string type = field.Type.ToString();
                        if (field.Primary && field.Type == DBField.cType.Int && field.AutoIncrement)
                        {
                            //for the automatic creation of an auto incremental integer primary key you must use the full "Integer" not just "int"
                            type = "Integer";
                        }

                        String sQuery = "CREATE TABLE " + m_tableName + " (" + sName + " " + type + (field.Primary ? " primary key)" : ")");
                        DBTVSeries.Execute(sQuery);
                    }
                    // delete the s_fields cache so newed up objects get the right fields
                    lock (fields)
                        fields.Remove(m_tableName);
                    m_fields.Add(sName, field);
                    return true;
                }
                catch (Exception ex)
                {
                    MPTVSeriesLog.Write(m_tableName + " table.AddColumn failed (" + ex.Message + ").");
                    return false;
                }
            }
            return false;
        }
Exemplo n.º 2
0
 public override bool AddColumn(string sName, DBField field)
 {
     if (!s_fields.ContainsKey(sName))
     {
         s_fields.Add(sName, field);
         return base.AddColumn(sName, field);
     }
     else
     {
         // we globally know about this key already, so don't call the base
         if (!m_fields.ContainsKey(sName))
             m_fields.Add(sName, field);
         return false;
     }
 }
Exemplo n.º 3
0
 public override bool AddColumn(string sName, DBField field)
 {
     // can't add columns to 
     if (m_onlineSeries != null)
         return m_onlineSeries.AddColumn(sName, field);
     else
         return false;
 }