Esempio n. 1
0
    internal Column(DataRow row, Table source)
    {
      _table = source;
      _unique = new Unique(this, row);

      if (row.IsNull("AUTOINCREMENT") == false && (bool)row["AUTOINCREMENT"] == true)
        _table.PrimaryKey.AutoIncrement = true;

      _dataType = (row.IsNull("DATA_TYPE") == false) ? row["DATA_TYPE"].ToString() : String.Empty;
      _columnName = row["COLUMN_NAME"].ToString();
      _origName = _columnName;
      _allowNulls = (bool)row["IS_NULLABLE"];
      _defaultValue = (row.IsNull("COLUMN_DEFAULT") == false) ? row["COLUMN_DEFAULT"].ToString() : String.Empty;
      _collate = (row.IsNull("COLLATION_NAME") == false) ? row["COLLATION_NAME"].ToString() : String.Empty;

      string edmtype = (row.IsNull("EDM_TYPE") == false) ? row["EDM_TYPE"].ToString() : String.Empty;
      if (edmtype == "nvarchar" || edmtype == "varchar" || edmtype == "blob" || edmtype == "nchar" || edmtype == "char")
      {
        int size = (row.IsNull("CHARACTER_MAXIMUM_LENGTH") == false) ? Convert.ToInt32(row["CHARACTER_MAXIMUM_LENGTH"], CultureInfo.InvariantCulture) : int.MaxValue;
        if (size != int.MaxValue)
          _dataType = string.Format(CultureInfo.InvariantCulture, "{0}({1})", _dataType, size);
      }
      else if (edmtype == "decimal")
      {
        int size = (row.IsNull("NUMERIC_PRECISION") == false) ? Convert.ToInt32(row["NUMERIC_PRECISION"], CultureInfo.InvariantCulture) : 53;
        int scale = (row.IsNull("NUMERIC_SCALE") == false) ? Convert.ToInt32(row["NUMERIC_SCALE"], CultureInfo.InvariantCulture) : int.MaxValue;

        if (size != 53)
        {
          string scalestr = (scale == int.MaxValue) ? "" : String.Format(CultureInfo.InvariantCulture, ",{0}", scale);
          _dataType = string.Format(CultureInfo.InvariantCulture, "{0}({1}{2})", _dataType, size, scalestr);
        }
      }
    }
    public TableDesignerDoc(int itemId, DataViewHierarchyAccessor accessor, string tableName)
    {
      _accessor = accessor;
      _connection = accessor.Connection;
      _itemId = itemId;
      _init = true;

      InitializeComponent();

      StringBuilder tables = new StringBuilder();

      using (DataReader reader = _connection.Command.Execute("SELECT * FROM sqlite_master", 1, null, 30))
      {
        while (reader.Read())
        {
          tables.Append(reader.GetItem(2).ToString());
          tables.Append(",");
        }
      }

      int n = 1;

      if (String.IsNullOrEmpty(tableName))
      {
        string alltables = tables.ToString();

        do
        {
          tableName = String.Format(CultureInfo.InvariantCulture, "Table{0}", n);
          n++;
        } while (alltables.IndexOf(tableName + ",", StringComparison.OrdinalIgnoreCase) > -1 || _editingTables.ContainsValue(tableName));

        _editingTables.Add(GetHashCode(), tableName);
      }
      _table = new Table(tableName, _connection.ConnectionSupport.ProviderObject as DbConnection, this);
      foreach(Column c in _table.Columns)
      {
        n = _dataGrid.Rows.Add();
        _dataGrid.Rows[n].Tag = c;
        c.Parent = _dataGrid.Rows[n];
      }
      _init = false;

      if (_dataGrid.Rows.Count > 0)
      {
        _dataGrid.EndEdit();
        _sqlText.Text = _table.OriginalSql;
      }
    }
Esempio n. 3
0
 internal ForeignKey(DbConnection cnn, Table table, DataRow row)
 {
   _table = table;
   if (row != null)
   {
     _id = (int)row["FKEY_ID"];
     _ordinal = (int)row["FKEY_FROM_ORDINAL_POSITION"];
     _from = new ForeignKeyFromItem(this, row["FKEY_FROM_COLUMN"].ToString());
     _to = new ForeignKeyToItem(this, row["FKEY_TO_CATALOG"].ToString(), row["FKEY_TO_TABLE"].ToString(), row["FKEY_TO_COLUMN"].ToString());
     _name = row["CONSTRAINT_NAME"].ToString();
     _onUpdate = row["FKEY_ON_UPDATE"].ToString();
     _onDelete = row["FKEY_ON_DELETE"].ToString();
     _match = row["FKEY_MATCH"].ToString();
   }
   else
   {
     _id = -1;
     _ordinal = -1;
     _from = new ForeignKeyFromItem(this, "");
     _to = new ForeignKeyToItem(this, _table.Catalog, "", "");
   }
 }
Esempio n. 4
0
 private ForeignKey(ForeignKey source)
 {
   _table = source._table;
   _id = source._id;
   _ordinal = source._ordinal;
   _from = new ForeignKeyFromItem(this, source._from.Column);
   _to = new ForeignKeyToItem(this, source._to.Catalog, source._to.Table, source._to.Column);
   _name = source._name;
   _onUpdate = source._onUpdate;
   _onDelete = source._onDelete;
   _match = source._match;
   _dirty = source._dirty;
 }
Esempio n. 5
0
 internal ForeignKeyEditor(Table parent)
   : base(typeof(List<ForeignKey>))
 {
   _table = parent;
   _count = _table.ForeignKeys.Count;
 }
 internal EditorHolder(Table tbl)
 {
   _indexes = tbl.Indexes;
   _fkeys = tbl.ForeignKeys;
   _check = tbl.Check;
   _triggers = tbl.Triggers as List<Trigger>;
 }
Esempio n. 7
0
 internal CheckEditor(Table parent)
   : base(typeof(List<string>))
 {
   _table = parent;
 }
Esempio n. 8
0
 internal PrimaryKey(DbConnection cnn, Table table, DataRow row)
   : base(cnn, table, row)
 {
   if (String.IsNullOrEmpty(_name) == false && _name.StartsWith("sqlite_", StringComparison.OrdinalIgnoreCase))
     _name = null;
 }
Esempio n. 9
0
 internal Column(Table table, DataGridViewRow row)
 {
   _parent = row;
   _table = table as Table;
   _unique = new Unique(this);
 }
Esempio n. 10
0
    internal Index(DbConnection cnn, Table table, DataRow index)
    {
      _table = table;
      if (index != null)
      {
        _name = index["INDEX_NAME"].ToString();
        _unique = (bool)index["UNIQUE"];
        _definition = index["INDEX_DEFINITION"].ToString();

        using (DataTable tbl = cnn.GetSchema("IndexColumns", new string[] { table.Catalog, null, table.Name, Name }))
        {
          foreach (DataRow row in tbl.Rows)
          {
            _columns.Add(new IndexColumn(this, row));
          }
        }
      }
    }
Esempio n. 11
0
    protected Index(Index source)
    {
      _table = source._table;
      _name = source._name;
      _unique = source._unique;
      _definition = source._definition;
      _conflict = source._conflict;
      _dirty = source._dirty;

      foreach (IndexColumn c in source._columns)
      {
        IndexColumn copy = ((ICloneable)c).Clone() as IndexColumn;
        copy._parent = this;
        _columns.Add(copy);
      }
    }
Esempio n. 12
0
 internal IndexEditor(Table parent)
   : base(typeof(List<Index>))
 {
   _table = parent;
 }
Esempio n. 13
0
 internal ForeignKey(DbConnection cnn, Table table, DataRow row)
 {
   _table = table;
   if (row != null)
   {
     _from = new ForeignKeyFromItem(this, row["FKEY_FROM_COLUMN"].ToString());
     _to = new ForeignKeyToItem(this, row["FKEY_TO_CATALOG"].ToString(), row["FKEY_TO_TABLE"].ToString(), row["FKEY_TO_COLUMN"].ToString());
     _name = row["CONSTRAINT_NAME"].ToString();
   }
   else
   {
     _from = new ForeignKeyFromItem(this, "");
     _to = new ForeignKeyToItem(this, _table.Catalog, "", "");
   }
 }
Esempio n. 14
0
 private ForeignKey(ForeignKey source)
 {
   _table = source._table;
   _from = new ForeignKeyFromItem(this, source._from.Column);
   _to = new ForeignKeyToItem(this, source._to.Catalog, source._to.Table, source._to.Column);
   _name = source._name;
   _dirty = source._dirty;
 }