public void AddRange(TableSchema[] value) 
		{
			for (int i = 0; (i < value.Length); i = (i + 1)) 
			{
				this.Add(value[i]);
			}
		}
//		private DatabaseSchema CreateMySqlDatabaseSchema(string connectionString)
//		{
//			DataTable schemaTables = this.GetMySqlSchema(connectionString);
//
//			DatabaseSchema di = new DatabaseSchema();
//			MySqlConnection c = new MySqlConnection(connectionString);
//			di.Name = c.Database;
//			c = null;
//
//			foreach (DataRow dr in schemaTables.Rows)
//			{
//				TableSchema ti = CreateMySqlTableSchema(dr);
//				CreateColumnSchemas(ti, connectionString, Adapdev.Data.DbType.MYSQL);
//
//				DataTable columns = this.GetMySqlColumnSchema(connectionString, ti.Name);
//
//				foreach(DataRow columnRow in columns.Rows)
//				{
//					if (columnRow["Key"] + "" == "PRI")
//					{
//						ti[columnRow["Field"].ToString()].IsPrimaryKey = true;
//					}
//					else if (columnRow["Key"] + "" == "MUL")
//					{
//						ti[columnRow["Field"].ToString()].IsForeignKey = true;
//					}
//				}
//				di.AddTable(ti);
//			}
//
//			return di;
//		}
//
		/// <summary>
		/// Creates the ColumnSchemas for a specified table
		/// </summary>
		/// <param name="ts">The TableSchema to add the ColumnSchema to</param>
		/// <param name="connectionString">The OleDb connectionstring to use</param>
		private void CreateColumnSchemas(TableSchema ts, string connectionString, Adapdev.Data.DbType databaseType)
		{
			DataTable dt = this.GetReaderSchema(connectionString, ts.Name, databaseType);
			if (!(dt == null)) 
			{
				foreach (DataRow dr in dt.Rows) 
				{
					ColumnSchema ci = new ColumnSchema();
					ci.Alias = (string) dr["ColumnName"];
					ci.AllowNulls = (bool) dr["AllowDBNull"];
					ci.DataTypeId = (int) dr["ProviderType"];
					ci.DataType = ProviderInfoManager.GetInstance().GetNameById(this.dbProviderType, ci.DataTypeId);
					ci.DefaultTestValue = ProviderInfoManager.GetInstance().GetTestDefaultById(this.dbProviderType, ci.DataTypeId);
					ci.DefaultValue = ProviderInfoManager.GetInstance().GetDefaultById(this.dbProviderType, ci.DataTypeId);
					ci.IsAutoIncrement = (bool) dr["IsAutoIncrement"];
					ci.IsForeignKey = false;
					ci.IsPrimaryKey = false;
					ci.IsUnique = (bool) dr["IsUnique"];
					ci.Length = (int) dr["ColumnSize"];
					ci.Name = (string) dr["ColumnName"];
					ci.NetType = dr["DataType"].ToString();
					ci.Ordinal = (int) dr["ColumnOrdinal"];
					ci.IsReadOnly = (bool) dr["IsReadOnly"];

					// hack because MySql has the same provider type for
					// strings and blobs, which results in blob
					// default and test values being incorrectly assigned to
					// string columns
					if((ci.DataTypeId == 252 && ci.NetType.Equals("System.String")) || ci.DataTypeId == 254)
					{
						ci.DataTypeId = 253;
						ci.DataType = ProviderInfoManager.GetInstance().GetNameById(this.dbProviderType, ci.DataTypeId);
						ci.DefaultTestValue = ProviderInfoManager.GetInstance().GetTestDefaultById(this.dbProviderType, ci.DataTypeId);
						ci.DefaultValue = ProviderInfoManager.GetInstance().GetDefaultById(this.dbProviderType, ci.DataTypeId);
					}
					ts.AddColumn(ci);
				} 
			}
		}
		public int Add(TableSchema value) 
		{
			return List.Add(value);
		}
		public TableSchemaCollection(TableSchema[] value) 
		{
			this.AddRange(value);
		}
		public ForeignKeyAssociation(ColumnSchema columnSchema, ColumnSchema foreignColumn, TableSchema foreignTable)
		{
			this._columnSchema = columnSchema;
			this._foreignColumn = foreignColumn;
			this._foreignTable = foreignTable;
		}
Example #6
0
		private void FillFields(TableSchema table) {
			foreach (ColumnSchema column in table.Columns.Values) {
				EntityField field = GetEntityField(column);
				field.RefreshDBInfo(column);
				if (!Fields.Contains(field)) {
					Fields.Add(field);
				}
			}
		}
		public void Insert(int index, TableSchema value) 
		{
			List.Insert(index, value);
		}
		public void CopyTo(TableSchema[] array, int index) 
		{
			List.CopyTo(array, index);
		}
		private string GetEntityFileName(TableSchema table) {
			return Path.Combine(_dataSource.Project.GetFullMetadataPath(), table.Name + ".xml");
		}
		private Entity CreateMetadataEntity(TableSchema table) {
			//string fileName = GetEntityFileName(table);
			MetadataFile file = new MetadataFile(_dataSource.Project);
			Entity entity = new Entity();
			file.MetadataEntities.Add(entity);
			file.Save(GetEntityFileName(table));
			_dataSource.Project.MetadataFiles.Add(file);
			return entity;
		}
		private Entity GetMetadataEntity(TableSchema table) {
			foreach (MetadataFile file in _dataSource.Project.MetadataFiles) {
				foreach (IMetadataEntity entity in file.MetadataEntities) {
					if ((entity as Entity) != null &&
					    (((Entity) entity).DataSourceName == _dataSource.Name || file.GetFullPath() == GetEntityFileName(table)) &&
					    ((Entity) entity).DBEntityName == table.Name) {
						return (Entity) entity;
					}
				}
			}
			return CreateMetadataEntity(table);
		}
		private void FillFields(TableSchema table, Entity entity) 
		{
			_dbfields = new ArrayList();
			EntityField previousField = null;
			foreach (ColumnSchema column in table.OrdinalColumns.Values) 
			{
				_dbfields.Add(column.Name);
				EntityField field = GetEntityField(column, entity);
				field.SetEntity(entity);
				this.RefreshFieldDBInfo(column, field);
//				if (entity.Fields.Contains(field))
//				{
//					entity.Fields.Add(field);
//				}
//				else
//				{
//					entity.Fields.Insert(entity.Fields.IndexOf(previousField), field);
//				}
				entity.Fields.Insert(entity.Fields.IndexOf(previousField)+1, field);
				previousField = field;
			}
			RemoveStaleDBFields(entity);
		}
		private void RefreshDBInfo(TableSchema table, Entity entity) 
		{
			Debug.WriteLine("Parsing data source information for the table [" + table.Name + "].");
			Debug.Indent();
			try
			{
				entity.DataSourceName = this.Name;
				entity.DBName = _dbschema.Name;
				entity.DBEntityName = table.Name;
				if (entity.Name == string.Empty) 
				{
					entity.Name = table.Name.Replace(" ", "");
				}
				this.FillFields(table, entity);
				if (this.OrmConfiguration.AutoMapIndexes)
				{
					this.FillIndexes(entity);
				}
			}
			finally
			{
				Debug.Unindent();
			}
		}
		/// <summary>
		/// Adds the specified table schema to the database
		/// </summary>
		/// <param name="table">The TableSchema to add</param>
		public void AddTable(TableSchema table)
		{
			tables[table.Name] = table;
		}
		public void Add(String key, TableSchema value)
		{
			Dictionary.Add(key, value);
		}
		private TableSchema CreateTableSchema(DataRow dr)
		{
			TableSchema ti = new TableSchema();
			ti.Alias = dr["TABLE_NAME"].ToString();
			ti.Name = dr["TABLE_NAME"].ToString();
			ti.TableType = TableTypeConverter.Convert(dr["TABLE_TYPE"].ToString());
			return ti;
		}
		public bool Contains(TableSchema value) 
		{
			return List.Contains(value);
		}
		/// <summary>
		/// Creates the ColumnSchemas for a specified table
		/// </summary>
		/// <param name="ts">The TableSchema to add the ColumnSchema to</param>
		/// <param name="oledbConnectionString">The OleDb connectionstring to use</param>
		public void CreateColumnSchemas(TableSchema ts, string oledbConnectionString, Adapdev.Data.DbType databaseType)
		{
			DataTable dt = this.GetReaderSchema(oledbConnectionString, ts.Name, databaseType);
			if (!(dt == null)) 
			{
				foreach (DataRow dr in dt.Rows) 
				{
					ColumnSchema ci = new ColumnSchema();
					ci.Alias = (string) dr["ColumnName"];
					ci.AllowNulls = (bool) dr["AllowDBNull"];
					ci.DataTypeId = (int) dr["ProviderType"];
					ci.DataType = ProviderInfoManager.GetInstance().GetNameById(dbProviderType, ci.DataTypeId);
					ci.DefaultTestValue = ProviderInfoManager.GetInstance().GetTestDefaultById(this.dbProviderType, ci.DataTypeId);
					ci.DefaultValue = ProviderInfoManager.GetInstance().GetDefaultById(this.dbProviderType, ci.DataTypeId);
					ci.IsAutoIncrement = (bool) dr["IsAutoIncrement"];
					ci.IsForeignKey = false;
					ci.IsPrimaryKey = false;
					ci.IsUnique = (bool) dr["IsUnique"];
					ci.Length = (int) dr["ColumnSize"];
					ci.Name = (string) dr["ColumnName"];
					ci.NetType = dr["DataType"].ToString();
					ci.Ordinal = (int) dr["ColumnOrdinal"];
					ci.IsReadOnly = (bool) dr["IsReadOnly"];
					ts.AddColumn(ci);
				} 
			}
		}
		public int IndexOf(TableSchema value) 
		{
			return List.IndexOf(value);
		}
Example #20
0
		public void RefreshDBInfo(DataSource dataSource, DatabaseSchema database, TableSchema table) {
			DataSourceName = dataSource.Name;
			DBName = database.Name;
			DBEntityName = table.Name;
			if (Name == string.Empty) {
				Name = table.Name.Replace(" ", "");
			}
			FillFields(table);
			FillIndexes(dataSource);
		}
		public void Remove(TableSchema value) 
		{
			List.Remove(value);
		}
		private TableSchema CreateMySqlTableSchema(DataRow dr)
		{
			TableSchema ti = new TableSchema();
			ti.Alias = dr[0].ToString();
			ti.Name = ti.Alias;
			ti.TableType = TableType.TABLE;
			return ti;
		}