private static void DumpStructure(StreamWriter output, StreamWriter hotfixesCpp, StreamWriter hotfixesH, StreamWriter infoH, CStructureInfo structure) { output.WriteLine("--"); output.WriteLine($"-- Table structure for table `{structure.GetTableName()}`"); output.WriteLine("--"); output.WriteLine(); output.WriteLine($"DROP TABLE IF EXISTS `{structure.GetTableName()}`;"); output.WriteLine("/*!40101 SET @saved_cs_client = @@character_set_client */;"); output.WriteLine("/*!50503 SET character_set_client = utf8mb4 */;"); output.WriteLine($"CREATE TABLE `{structure.GetTableName()}` ("); var cppBuilder = new LimitedLineLengthStringBuilder() { WrappedLinePrefix = " \"", WrappedLineSuffix = "\"" }; var infoBuilder = new StringBuilder(); if (!structure.IsLocale) { cppBuilder.AppendLine(); cppBuilder.AppendLine($" // {structure.NormalizedName}.db2"); cppBuilder.Append($" PrepareStatement(HOTFIX_SEL_{structure.GetTableName().ToUpperInvariant()}"); hotfixesH.WriteLine(); infoH.WriteLine($"struct {structure.NormalizedName}LoadInfo"); infoH.WriteLine("{"); infoH.WriteLine(" static DB2LoadInfo const* Instance()"); infoH.WriteLine(" {"); infoH.WriteLine($" static DB2FieldMeta const fields[] ="); infoH.WriteLine(" {"); } else { cppBuilder.Append($" PREPARE_LOCALE_STMT(HOTFIX_SEL_{structure.GetTableName().ToUpperInvariant().Replace("_LOCALE", "")}"); } cppBuilder.Append(", \"SELECT "); foreach (var member in structure.Members) { DumpStructureMember(output, cppBuilder, infoBuilder, member); } cppBuilder.Remove(cppBuilder.Length - 2, 2); if (!structure.GetTableName().IsSqlKeyword()) { cppBuilder.Append($" FROM {structure.GetTableName()}"); } else { cppBuilder.Append($" FROM `{structure.GetTableName()}`"); } cppBuilder.Append(" WHERE (`VerifiedBuild` > 0) = ?"); if (!structure.IsLocale) { output.WriteLine($" PRIMARY KEY (`ID`,`VerifiedBuild`)"); } else { cppBuilder.Append(" AND locale = ?"); output.WriteLine(" PRIMARY KEY (`ID`,`locale`,`VerifiedBuild`)"); } output.Write(") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"); if (!structure.IsLocale) { output.WriteLine(";"); } else { output.WriteLine(); output.WriteLine("/*!50500 PARTITION BY LIST COLUMNS(locale)"); output.WriteLine("(PARTITION deDE VALUES IN ('deDE') ENGINE = InnoDB,"); output.WriteLine(" PARTITION esES VALUES IN ('esES') ENGINE = InnoDB,"); output.WriteLine(" PARTITION esMX VALUES IN ('esMX') ENGINE = InnoDB,"); output.WriteLine(" PARTITION frFR VALUES IN ('frFR') ENGINE = InnoDB,"); output.WriteLine(" PARTITION itIT VALUES IN ('itIT') ENGINE = InnoDB,"); output.WriteLine(" PARTITION koKR VALUES IN ('koKR') ENGINE = InnoDB,"); output.WriteLine(" PARTITION ptBR VALUES IN ('ptBR') ENGINE = InnoDB,"); output.WriteLine(" PARTITION ruRU VALUES IN ('ruRU') ENGINE = InnoDB,"); output.WriteLine(" PARTITION zhCN VALUES IN ('zhCN') ENGINE = InnoDB,"); output.WriteLine(" PARTITION zhTW VALUES IN ('zhTW') ENGINE = InnoDB) */;"); } output.WriteLine("/*!40101 SET character_set_client = @saved_cs_client */;"); output.WriteLine(); output.WriteLine("--"); output.WriteLine($"-- Dumping data for table `{structure.GetTableName()}`"); output.WriteLine("--"); output.WriteLine(); output.WriteLine($"LOCK TABLES `{structure.GetTableName()}` WRITE;"); output.WriteLine($"/*!40000 ALTER TABLE `{structure.GetTableName()}` DISABLE KEYS */;"); output.WriteLine($"/*!40000 ALTER TABLE `{structure.GetTableName()}` ENABLE KEYS */;"); output.WriteLine("UNLOCK TABLES;"); output.WriteLine(); cppBuilder.Nonbreaking().Append("\", CONNECTION_SYNCH);"); hotfixesCpp.WriteLine(cppBuilder.Finalize()); hotfixesH.WriteLine($" HOTFIX_SEL_{structure.GetTableName().ToUpperInvariant()},"); if (!structure.IsLocale) { if (!structure.GetTableName().IsSqlKeyword()) { hotfixesCpp.WriteLine($" PREPARE_MAX_ID_STMT(HOTFIX_SEL_{structure.GetTableName().ToUpperInvariant()}, \"SELECT MAX(ID) + 1 FROM {structure.GetTableName()}\", CONNECTION_SYNCH);"); } else { hotfixesCpp.WriteLine($" PREPARE_MAX_ID_STMT(HOTFIX_SEL_{structure.GetTableName().ToUpperInvariant()}, \"SELECT MAX(ID) + 1 FROM `{structure.GetTableName()}`\", CONNECTION_SYNCH);"); } hotfixesH.WriteLine($" HOTFIX_SEL_{structure.GetTableName().ToUpperInvariant()}_MAX_ID,"); } if (!structure.IsLocale) { infoH.Write(infoBuilder.ToString()); infoH.WriteLine(" };"); infoH.WriteLine($" static DB2LoadInfo const loadInfo(&fields[0], std::extent<decltype(fields)>::value, {structure.Name.Replace("Entry", "")}Meta::Instance(), HOTFIX_SEL_{structure.GetTableName().ToUpperInvariant().Replace("_LOCALE", "")});"); infoH.WriteLine(" return &loadInfo;"); infoH.WriteLine(" }"); infoH.WriteLine("};"); infoH.WriteLine(); } }
private static void DumpStructure(StreamWriter output, StreamWriter hotfixesCpp, StreamWriter hotfixesH, CStructureInfo structure) { output.WriteLine("--"); output.WriteLine($"-- Table structure for table `{structure.GetTableName()}`"); output.WriteLine("--"); output.WriteLine(); output.WriteLine($"DROP TABLE IF EXISTS `{structure.GetTableName()}`;"); output.WriteLine("/*!40101 SET @saved_cs_client = @@character_set_client */;"); output.WriteLine("/*!40101 SET character_set_client = utf8 */;"); output.WriteLine($"CREATE TABLE `{structure.GetTableName()}` ("); var cppBuilder = new LimitedLineLengthStringBuilder() { WrappedLinePrefix = " \"", WrappedLineSuffix = "\"" }; if (!structure.IsLocale) { cppBuilder.AppendLine(); cppBuilder.AppendLine($" // {structure.Name}.db2"); cppBuilder.Append($" PrepareStatement(HOTFIX_SEL_{structure.GetTableName().ToUpperInvariant()}"); hotfixesH.WriteLine(); } else { cppBuilder.Append($" PREPARE_LOCALE_STMT(HOTFIX_SEL_{structure.GetTableName().ToUpperInvariant().Replace("_LOCALE", "")}"); } cppBuilder.Append(", \"SELECT "); foreach (var member in structure.Members) { DumpStructureMember(output, cppBuilder, member); } cppBuilder.Remove(cppBuilder.Length - 2, 2); if (!structure.GetTableName().IsSqlKeyword()) { cppBuilder.Append($" FROM {structure.GetTableName()}"); } else { cppBuilder.Append($" FROM `{structure.GetTableName()}`"); } if (!structure.IsLocale) { output.WriteLine($" PRIMARY KEY (`ID`)"); cppBuilder.Append($" ORDER BY ID DESC"); } else { cppBuilder.Append(" WHERE locale = ?"); output.WriteLine($" PRIMARY KEY (`ID`,`locale`)"); } output.WriteLine(") ENGINE=MyISAM DEFAULT CHARSET=utf8;"); output.WriteLine("/*!40101 SET character_set_client = @saved_cs_client */;"); output.WriteLine(); output.WriteLine("--"); output.WriteLine($"-- Dumping data for table `{structure.GetTableName()}`"); output.WriteLine("--"); output.WriteLine(); output.WriteLine($"LOCK TABLES `{structure.GetTableName()}` WRITE;"); output.WriteLine($"/*!40000 ALTER TABLE `{structure.GetTableName()}` DISABLE KEYS */;"); output.WriteLine($"/*!40000 ALTER TABLE `{structure.GetTableName()}` ENABLE KEYS */;"); output.WriteLine("UNLOCK TABLES;"); output.WriteLine(); cppBuilder.Nonbreaking().Append("\", CONNECTION_SYNCH);"); hotfixesCpp.WriteLine(cppBuilder.Finalize()); hotfixesH.WriteLine($" HOTFIX_SEL_{structure.GetTableName().ToUpperInvariant()},"); }
private static void DumpStructure(StreamWriter output, StreamWriter hotfixesCpp, StreamWriter hotfixesH, CStructureInfo structure) { output.WriteLine("--"); output.WriteLine("-- Table structure for table `" + structure.GetTableName() + "`"); output.WriteLine("--"); output.WriteLine(); output.WriteLine("DROP TABLE IF EXISTS `" + structure.GetTableName() + "`;"); output.WriteLine("/*!40101 SET @saved_cs_client = @@character_set_client */;"); output.WriteLine("/*!40101 SET character_set_client = utf8 */;"); output.WriteLine("CREATE TABLE `" + structure.GetTableName() + "` ("); var cppBuilder = new LimitedLineLengthStringBuilder() { WrappedLinePrefix = " \"", WrappedLineSuffix = "\"" }; if (!structure.Name.Contains("Locale")) { cppBuilder.AppendLine(); cppBuilder.AppendFormatLine(" // {0}.db2", structure.Name); cppBuilder.Append(" PrepareStatement(HOTFIX_SEL_"); hotfixesH.WriteLine(); } else cppBuilder.Append(" PREPARE_LOCALE_STMT(HOTFIX_SEL_"); cppBuilder.Append(String.Format("{0}, \"SELECT ", structure.GetTableName().ToUpperInvariant().Replace("_LOCALE", ""))); foreach (var member in structure.Members) DumpStructureMember(output, cppBuilder, member); cppBuilder.Remove(cppBuilder.Length - 2, 2); cppBuilder.Append(String.Format(" FROM {0}", structure.GetTableName())); if (!structure.Name.Contains("Locale")) { output.WriteLine(String.Format(" PRIMARY KEY (`{0}`)", structure.Members.First().Name)); cppBuilder.Append(String.Format(" ORDER BY {0} DESC", structure.Members.First().Name)); } else { cppBuilder.Append(" WHERE locale = ?"); output.WriteLine(String.Format(" PRIMARY KEY (`{0}`,`locale`)", structure.Members.First().Name)); } output.WriteLine(") ENGINE=MyISAM DEFAULT CHARSET=utf8;"); output.WriteLine("/*!40101 SET character_set_client = @saved_cs_client */;"); output.WriteLine(); output.WriteLine("--"); output.WriteLine("-- Dumping data for table `" + structure.GetTableName() + "`"); output.WriteLine("--"); output.WriteLine(); output.WriteLine("LOCK TABLES `" + structure.GetTableName() + "` WRITE;"); output.WriteLine("/*!40000 ALTER TABLE `" + structure.GetTableName() + "` DISABLE KEYS */;"); output.WriteLine("/*!40000 ALTER TABLE `" + structure.GetTableName() + "` ENABLE KEYS */;"); output.WriteLine("UNLOCK TABLES;"); output.WriteLine(); cppBuilder.Nonbreaking().Append("\", CONNECTION_SYNCH);"); hotfixesCpp.WriteLine(cppBuilder.Finalize()); hotfixesH.WriteLine(String.Format(" HOTFIX_SEL_{0},", structure.GetTableName().ToUpperInvariant())); }