/// <summary> /// Generates the 'fill entity with row' method. /// </summary> /// <param name="file">The file.</param> /// <param name="map">The map.</param> public override void GenerateFillEntityWithRow(StreamWriter file, IClassMap map) { // string entityTypeName = EntityGenerator.GetTypeName(map); // file.WriteLine(" " + entityTypeName + " entity = new " + entityTypeName + "();"); int columnIndex = 0; foreach (IPropertyMap propertyMap in map.PropertyMaps) { file.Write(" entity."+ propertyMap.Name); file.Write(" = reader." + MySqlUtility.GetReaderMethod(propertyMap.GetColumnMap().DataType)); file.Write("(" + columnIndex.ToString() + ");"); file.WriteLine(); ++columnIndex; } // file.WriteLine(" return entity;"); }
/// <summary> /// Generates the 'verify schema' code. /// </summary> /// <param name="file">The file.</param> /// <param name="classMap">The class map.</param> public override void GenerateVerifySchema(StreamWriter file, IClassMap classMap) { #warning TODO: finish VerifySchema method if (classMap.PropertyMaps.Count <= 0) { file.WriteLine(" return null; // no property maps"); return; // ??? } // no table - create it bool firstColumn = true; StringBuilder sqlCommandText = new StringBuilder("\"CREATE TABLE IF NOT EXISTS `" + classMap.Table + "` (\"", classMap.PropertyMaps.Count * 16); foreach (IPropertyMap propertyMap in classMap.PropertyMaps) { IColumnMap columnMap = propertyMap.GetColumnMap(); // close prev statement's quote, start new line if (firstColumn) { sqlCommandText.Append("\n"); firstColumn = false; } else { sqlCommandText.Append(",\"\n"); } // opening quote sqlCommandText.Append(" +\""); // build one field creation statement sqlCommandText .Append("`") .Append(columnMap.Name) .Append("` ") .Append(MySqlUtility.GetDataType(columnMap)); // is nulls allowed if (!columnMap.AllowNulls) { sqlCommandText.Append(" NOT NULL"); } // default value if (columnMap.DefaultValue != null && columnMap.DefaultValue.Length > 0) { sqlCommandText .Append(" default '") .Append(MySqlUtility.Escape(columnMap.DefaultValue)) .Append("'"); } // auto_increment? if (columnMap.IsAutoIncrease) { sqlCommandText.Append(" auto_increment"); } } // close last statement's quotes, start new line sqlCommandText.Append("\"\n"); // primary keys ArrayList primaryKeyMaps = classMap.GetTableMap().GetPrimaryKeyColumnMaps(); if (primaryKeyMaps.Count > 0) { // opening quote sqlCommandText.Append(" +\""); // write primary key name and open fields list string pkName = StringUtility.CombineObjects((IColumnMap[])primaryKeyMaps.ToArray(typeof(IColumnMap)), MapToStringConverters.Join).ToString(); sqlCommandText.Append(", primary key `" + pkName + "`"); // combine primary key fields IColumnMap[] primaryKeyMapsTyped = (IColumnMap[])primaryKeyMaps.ToArray(typeof(IColumnMap)); StringBuilder primaryKeyMapNames = StringUtility.CombineObjects(primaryKeyMapsTyped, MapToStringConverters.Columns); sqlCommandText.Append(" ("); sqlCommandText.Append(primaryKeyMapNames); sqlCommandText.Append(")\"\n"); } else { // no primary // sqlCommandText.Append("\n"); } // close the field list sqlCommandText.Append(" +\")\""); // write to file file.WriteLine(" m_state.ExecuteNonQuery("+ sqlCommandText.ToString() + "\n );"); file.WriteLine(" m_state.ExecuteNonQuery(\"OPTIMIZE TABLE `"+ classMap.GetTableMap().Name + "`\");"); file.WriteLine(" return null;"); }