// 添加新列 Column & Table::NewColumn(const std::string & column_name) { int32_t new_index = (int32_t)_columns.size(); Column * col = new Column(this, new_index); assert(col); if (!column_name.empty()) { col->SetName(column_name); } _columns.push_back(col); return *col; }
void TableSettings::OnColumnChanged(wxDataViewEvent& event) { Column *col = reinterpret_cast<Column*>(m_dvColumns->GetItemData( event.GetItem() ) ); if( col ) { wxVariant val; event.GetModel()->GetValue( val, event.GetItem(), event.GetColumn() ); if( ! val.IsNull() ) { switch( event.GetColumn() ) { case 0: { // rename local columns in keys SerializableList keys; GetConstraints( keys, col->GetName() ); for(SerializableList::iterator it = keys.begin(); it != keys.end(); ++it ) { Constraint *key = (Constraint*) *it; if( key->GetType() == Constraint::primaryKey ) key->SetName( wxT("PK_") + val.GetString() ); key->SetLocalColumn( val.GetString() ); } // rename table column col->SetName( val.GetString() ); break; } case 1: { col->SetType( m_pDbAdapter->GetDbTypeByName( val.GetString() ) ); break; } case 2: { long s1, s2; s1 = s2 = 0; wxSscanf( val.GetString(), wxT("%ld,%ld"), &s1, &s2 ); IDbType *type = col->GetType(); if( type->HaveSize() ) type->SetSize( s1 ); else { m_infobar->ShowMessage( wxT("This data type doesn't support size definition."), wxICON_WARNING ); Refresh(); } if( type->HaveSize2() ) type->SetSize2( s1 ); else { m_infobar->ShowMessage( wxT("This data type doesn't support size definition."), wxICON_WARNING ); Refresh(); } break; } case 3: { IDbType *type = col->GetType(); if( type->HaveNotNull() ) type->SetNotNull( val.GetBool() ); else { m_infobar->ShowMessage( wxT("This data type doesn't support NOT NULL feature."), wxICON_WARNING ); Refresh(); } break; } case 4: { IDbType *type = col->GetType(); if( type->HaveAutoIncrement() ) type->SetAutoIncrement( val.GetBool() ); else { m_infobar->ShowMessage( wxT("This data type doesn't support AUTOINCREMENT feature."), wxICON_WARNING ); Refresh(); } break; } case 5: { Constraint *key = GetConstraint( Constraint::primaryKey, col->GetName() ); if( key ) { // remove primary key if exists m_lstKeys.DeleteObject( key ); delete key; } else { // create new primary key key = new Constraint( wxT("PK_") + col->GetName(), col->GetName(), Constraint::primaryKey, Constraint::noAction, Constraint::noAction ); m_lstKeys.Append( key ); } break; } } } } event.Skip(); UpdateView(); }