Beispiel #1
0
        private void ReloadDefinition()
        {
            using (DataTable tbl = _connection.GetSchema("Tables", new string[] { Catalog, null, Name }))
              {
            if (tbl.Rows.Count > 0)
            {
              _exists = true;
              _origSql = tbl.Rows[0]["TABLE_DEFINITION"].ToString().Trim().TrimEnd(';');
              _oldname = Name;
            }
            else
            {
              _exists = false;
              return;
            }
              }

              _indexes.Clear();
              _oldindexes.Clear();

              using (DataTable tbl = _connection.GetSchema("Indexes", new string[] { Catalog, null, Name }))
              {
            foreach (DataRow row in tbl.Rows)
            {
              if ((bool)row["PRIMARY_KEY"] == false)
              {
            if (row["INDEX_NAME"].ToString().StartsWith("sqlite_", StringComparison.OrdinalIgnoreCase) == false)
            {
              _indexes.Add(new Index(_connection, this, row));
              _oldindexes.Add(new Index(_connection, this, row));
            }
              }
              else if (_key == null)
              {
            _key = new PrimaryKey(_connection, this, row);
              }
            }
              }

              _check.Clear();
              StringBuilder builder = new StringBuilder();
              SimpleTokenizer.StringParts[] arr = SimpleTokenizer.BreakString(_origSql);
              for (int n = 0; n < arr.Length - 3; n++)
              {
            if (arr[n].keyword == "CONSTRAINT")
            {
              builder.Length = 0;
              int x;
              for (x = 1; x < 3; x++)
              {
            if (arr[n + x].keyword == "CHECK")
              break;
              }
              if (x == 3)
              {
            n += 2;
            continue;
              }
              x += n + 1;
              int depth = arr[n].depth;
              int basedepth = arr[x].depth;
              for (; x < arr.Length; x++)
              {
            if (arr[x].depth < basedepth)
              break;

            if (builder.Length > 0)
              builder.Append(" ");

            while (depth < arr[x].depth)
            {
              builder.Append("(");
              depth++;
            }
            while (depth > arr[x].depth)
            {
              builder.Append(")");
              depth--;
            }

            if (String.IsNullOrEmpty(arr[x].quote) == false)
              builder.Append(arr[x].quote[0]);
            builder.Append(arr[x].value);
            if (String.IsNullOrEmpty(arr[x].quote) == false)
              builder.Append(arr[x].quote[1]);

            if (arr[x].sep == true) break;
              }
              while (depth > arr[n].depth)
              {
            builder.Append(")");
            depth--;
              }
              n = x;
              _check.Add(builder.ToString());
            }
              }

              builder.Length = 0;
              builder.AppendLine("-- Original table schema");
              builder.Append(_origSql);

              builder.AppendLine(";");
              foreach (Index idx in _oldindexes)
              {
            builder.AppendFormat("{0};\r\n", idx.OriginalSql);
              }

              _triggers.Clear();
              _oldtriggers.Clear();

              using (DataTable tbl = _connection.GetSchema("Triggers", new string[] { Catalog, null, Name }))
              {
            foreach (DataRow row in tbl.Rows)
            {
              Trigger t = new Trigger(this, row);
              _triggers.Add(t);
              _oldtriggers.Add(((ICloneable)t).Clone() as Trigger);

              builder.AppendFormat("{0};\r\n", t.OriginalSql);
            }
              }

              _origSql = builder.ToString();
        }
Beispiel #2
0
 protected Trigger(Trigger source)
 {
   _triggerOccurs = source._triggerOccurs;
   _type = source._type;
   //_eachRow = source._eachRow;
   _when = source._when;
   _table = source._table;
   _name = source._name;
   _columns = source._columns;
   _action = source._action;
   _dirty = source._dirty;
 }