private static void DumpStructureMember(StreamWriter output, LimitedLineLengthStringBuilder query, CStructureMemberInfo member) { var arraySize = member.ArraySize; string typeInfo; if (!MySQLTypeMap.TryGetValue(member.FormattedTypeName, out typeInfo)) { typeInfo = "ERROR TYPE" + member.TypeName; } if (member.TypeName == "flag128") { arraySize = 4; typeInfo = MySQLTypeMap["uint32"]; } for (var i = 0; i < arraySize; ++i) { var memberName = member.Name; if (arraySize > 1) { var langPos = memberName.IndexOf("_lang"); if (langPos == -1) { memberName += (i + 1).ToString(); } else { memberName = memberName.Insert(langPos, (i + 1).ToString()); } } if (!typeInfo.Contains("ERROR")) { DumpStructureMemberName(output, query, memberName, typeInfo); } else { switch (member.TypeName) { case "DBCPosition3D": DumpStructureMemberName(output, query, memberName + "X", MySQLTypeMap["float"]); DumpStructureMemberName(output, query, memberName + "Y", MySQLTypeMap["float"]); DumpStructureMemberName(output, query, memberName + "Z", MySQLTypeMap["float"]); break; case "DBCPosition2D": DumpStructureMemberName(output, query, memberName + "X", MySQLTypeMap["float"]); DumpStructureMemberName(output, query, memberName + "Y", MySQLTypeMap["float"]); break; default: output.WriteLine($" `{memberName}` ERROR TYPE {member.TypeName},"); break; } } } }
private static void DumpStructureMemberName(StreamWriter output, LimitedLineLengthStringBuilder query, string memberName, string typeName) { output.WriteLine($" `{memberName}` {typeName},"); if (memberName != "VerifiedBuild" && memberName != "locale") { if (!memberName.IsSqlKeyword()) { query.Append($"{memberName}, "); } else { query.Append($"`{memberName}`, "); } } }
private static void DumpStructureMemberName(StreamWriter output, LimitedLineLengthStringBuilder query, StringBuilder fieldsMetaH, string memberName, string typeName, string cpptype, string @enum) { output.WriteLine($" `{memberName}` {typeName},"); if (memberName != "VerifiedBuild" && memberName != "locale") { if (!memberName.IsSqlKeyword()) { query.Append($"{memberName}, "); } else { query.Append($"`{memberName}`, "); } fieldsMetaH.AppendLine($" {{ {SignedIntRegex.IsMatch(cpptype).ToString().ToLowerInvariant()}, {@enum}, \"{memberName}\" }},"); } }
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, 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.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())); }
private static void DumpStructureMemberName(StreamWriter output, LimitedLineLengthStringBuilder query, string memberName, string typeName) { output.WriteLine(String.Format(" `{0}` {1},", memberName, typeName)); if (memberName != "VerifiedBuild" && memberName != "locale") { if (!memberName.IsSqlKeyword()) query.AppendFormat("{0}, ", memberName); else query.AppendFormat("`{0}`, ", memberName); } }
private static void DumpStructureMember(StreamWriter output, LimitedLineLengthStringBuilder query, CStructureMemberInfo member) { var arraySize = 1; var indexOfArray = member.Name.IndexOf('['); if (indexOfArray != -1) { var arrayDef = member.Name.Substring(indexOfArray); if (!_parser.ArraySizes.TryGetValue(arrayDef, out arraySize)) if (!int.TryParse(arrayDef.Substring(1, arrayDef.Length - 2), out arraySize)) arraySize = 1; } string typeInfo; if (!MySQLTypeMap.TryGetValue(member.TypeName, out typeInfo)) typeInfo = "ERROR TYPE" + member.TypeName; if (member.TypeName == "flag128") { arraySize = 4; typeInfo = MySQLTypeMap["uint32"]; } for (var i = 0; i < arraySize; ++i) { var memberName = member.Name; if (indexOfArray != -1) memberName = member.Name.Substring(0, indexOfArray); if (arraySize > 1) { var langPos = memberName.IndexOf("_lang"); if (langPos == -1) memberName += (i + 1).ToString(); else memberName = memberName.Insert(langPos, (i + 1).ToString()); } if (!typeInfo.Contains("ERROR")) { DumpStructureMemberName(output, query, memberName, typeInfo); } else { switch (member.TypeName) { case "DBCPosition3D": DumpStructureMemberName(output, query, memberName + "X", MySQLTypeMap["float"]); DumpStructureMemberName(output, query, memberName + "Y", MySQLTypeMap["float"]); DumpStructureMemberName(output, query, memberName + "Z", MySQLTypeMap["float"]); break; case "DBCPosition2D": DumpStructureMemberName(output, query, memberName + "X", MySQLTypeMap["float"]); DumpStructureMemberName(output, query, memberName + "Y", MySQLTypeMap["float"]); break; default: output.WriteLine(String.Format(" `{0}` {1},", memberName, "ERROR TYPE " + member.TypeName)); break; } } } }