public override void GenSql(AbstractDb.ISqlDumper dmp) { Commands.ForEach(x => { x.GenSql(dmp); dmp.EndCommand(); }); }
public override void GenSql(AbstractDb.ISqlDumper dmp) { dmp.Put("^insert ^into %l%f (%,i)&n", LinkedInfo, TargetTable, TargetColumns); Select.GenSql(dmp); }
public static void DbItemsWriterSub <TKey>(StringBuilder builder, AbstractDb <TKey> db, IEnumerable <ReadableTuple <TKey> > tuples, ServerType to) { if (to == ServerType.RAthena) { bool fromTxtDb = AllLoaders.DetectPath(db.DbSource).IsExtension(".txt"); foreach (ReadableTuple <TKey> tuple in tuples) { List <string> rawElements = tuple.GetRawElements().Take(22).Select(p => p.ToString()).ToList(); if (tuple.Normal && fromTxtDb) { builder.AppendLine(string.Join(",", rawElements.ToArray())); continue; } string script1 = tuple.GetValue <string>(19); string script2 = tuple.GetValue <string>(20); string script3 = tuple.GetValue <string>(21); string refine = tuple.GetValue <string>(17); if (refine == "") { refine = ""; } else if (refine == "true" || refine == "1") { refine = "1"; } else { refine = "0"; } builder.AppendLine(string.Join(",", new string[] { rawElements[0], rawElements[1], rawElements[2], _outputInteger(rawElements[3]), // Type _zeroDefault(rawElements[4]), _zeroDefault(rawElements[5]), String.IsNullOrEmpty(rawElements[6]) ? "0" : rawElements[6], _zeroDefault(rawElements[7]), _zeroDefault(rawElements[8]), _zeroDefault(rawElements[9]), _zeroDefault(rawElements[10]), // Slots String.IsNullOrEmpty(rawElements[11]) ? "0xFFFFFFFF" : !rawElements[11].StartsWith("0x") ? "0x" + Int32.Parse(rawElements[11]).ToString("X8") : rawElements[11], _hexToInt(rawElements[12]), // Upper _zeroDefault(rawElements[13]), _zeroDefault(_hexToInt(rawElements[14])), _zeroDefault(rawElements[15]), _zeroDefault(rawElements[16]), refine, _zeroDefault(rawElements[18]), String.IsNullOrEmpty(script1) ? "{}" : "{ " + script1 + " }", String.IsNullOrEmpty(script2) ? "{}" : "{ " + script2 + " }", String.IsNullOrEmpty(script3) ? "{}" : "{ " + script3 + " }" })); } } else if (to == ServerType.Hercules) { foreach (int id in tuples.Select(p => p.GetKey <int>()).OrderBy(p => p)) { builder.AppendLineUnix(ItemParser.ToHerculesEntry(db, id)); } } }
private static void _loadItemsGroupdDb(AbstractDb <int> db, ServerDbs serverDb, string file) { int numberOfErrors = 3; TextFileHelper.LatestFile = file; if (String.IsNullOrEmpty(file)) { DbIOErrorHandler.Handle(StackTraceException.GetStrackTraceException(), "File not found " + ServerDbs.ItemGroups + ".", ErrorLevel.NotSpecified); return; } var itemDb1 = db.ProjectDatabase.GetDb <int>(ServerDbs.Items); var itemDb2 = db.ProjectDatabase.GetDb <int>(ServerDbs.Items2); if (!itemDb1.IsLoaded) { itemDb1.LoadDb(); } if (!itemDb2.IsLoaded) { itemDb2.LoadDb(); } var itemDb = new MetaTable <int>(ServerItemAttributes.AttributeList); itemDb.AddTable(itemDb1.Table); itemDb.AddTable(itemDb2.Table); itemDb.MergeOnce(); Dictionary <string, ReadableTuple <int> > bufferredTuples = new Dictionary <string, ReadableTuple <int> >(); foreach (var tuple in itemDb.FastItems) { bufferredTuples[tuple.GetStringValue(ServerItemAttributes.AegisName.Index)] = tuple; } var table = db.Table; if (db.Attached[serverDb] == null) { db.Attached[serverDb] = new Tuple <ServerDbs, HashSet <int> >(serverDb, new HashSet <int>()); } HashSet <int> loadedIds = ((Tuple <ServerDbs, HashSet <int> >)db.Attached[serverDb]).Item2; foreach (string[] elements in TextFileHelper.GetElementsByCommas(FtpHelper.ReadAllBytes(file))) { try { int itemId; int iItemId; if (Int32.TryParse(elements[0], out iItemId)) { itemId = iItemId; } else { var constantDb = db.ProjectDatabase.GetDb <string>(ServerDbs.Constants); if (!constantDb.IsLoaded) { constantDb.LoadDb(); } var tuple = constantDb.Table.TryGetTuple(elements[0]); if (tuple == null) { if (DbPathLocator.GenericErrorHandler(ref numberOfErrors, elements[0])) { return; } continue; } itemId = tuple.GetValue <int>(1); } string orate = elements[2]; int nameId; int rate; if (Int32.TryParse(elements[1], out nameId)) { } else { var tuple = bufferredTuples[elements[1]]; if (tuple == null) { if (DbPathLocator.GenericErrorHandler(ref numberOfErrors, elements[0])) { return; } continue; } nameId = tuple.Key; } Int32.TryParse(orate, out rate); var id = (object)itemId; loadedIds.Add((int)id); if (!table.ContainsKey(itemId)) { ReadableTuple <int> tuple = new ReadableTuple <int>(itemId, db.AttributeList); tuple.SetRawValue(ServerItemGroupAttributes.Table, new Dictionary <int, ReadableTuple <int> >()); table.Add(itemId, tuple); } Dictionary <int, ReadableTuple <int> > dico = (Dictionary <int, ReadableTuple <int> >)table.GetRaw(itemId, ServerItemGroupAttributes.Table); ReadableTuple <int> newTuple = new ReadableTuple <int>(nameId, ServerItemGroupSubAttributes.AttributeList); List <DbAttribute> attributes = new List <DbAttribute>(ServerItemGroupSubAttributes.AttributeList.Attributes); for (int i = 2; i < elements.Length; i++) { newTuple.SetRawValue(attributes[i - 1], elements[i]); } newTuple.SetRawValue(ServerItemGroupSubAttributes.ParentGroup, itemId); dico[nameId] = newTuple; } catch { if (DbPathLocator.GenericErrorHandler(ref numberOfErrors, elements[0])) { return; } } } }
public static void DbLoaderComma <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db) { DbLoaderAny(debug, db, TextFileHelper.GetElementsByCommas); }
public static void DbIntComma <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db) { DbIntCommaRange(debug, db, 0, db.AttributeList.Attributes.Count); }
public static void DbLoaderAny <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db, TextFileHelper.TextFileHelperGetterDelegate getter, bool uniqueKey = true, int numberOfAttributesToGuess = -1) { List <DbAttribute> attributes = new List <DbAttribute>(db.AttributeList.Attributes); int indexOffset = uniqueKey ? 1 : 0; int attributesOffset = uniqueKey ? 0 : 1; bool hasGuessedAttributes = false; int rndOffset = 0; Func <string, TKey> keyConverter; if (typeof(TKey) == typeof(int)) { keyConverter = q => (TKey)(object)Int32.Parse(q); } else { keyConverter = q => (TKey)(object)q; } if (!uniqueKey) { TextFileHelper.SaveLastLine = true; } foreach (string[] elements in getter(IOHelper.ReadAllBytes(debug.FilePath))) { try { if (!hasGuessedAttributes) { GuessAttributes(elements, attributes, numberOfAttributesToGuess, db); hasGuessedAttributes = true; } TKey id; if (uniqueKey) { id = keyConverter(elements[0]); } else { id = (TKey)(object)TextFileHelper.LastLineRead; while (db.Table.ContainsKey(id)) { id = (TKey)(object)((string)(object)id + "_" + rndOffset++); } } db.Table.SetRawRange(id, attributesOffset, indexOffset, attributes, elements); //for (int index = indexOffset; index < elements.Length; index++) { // db.Table.SetRaw(id, attributes[index + attributesOffset], elements[index]); //} } catch { if (elements.Length <= 0) { if (!debug.ReportIdException("#")) { return; } } else if (!debug.ReportIdException(elements[0])) { return; } } } if (!uniqueKey) { TextFileHelper.SaveLastLine = false; } }
public static void DbWriterComma(DbDebugItem <int> debug, AbstractDb <int> db, int from, int to, Action <ReadableTuple <int>, List <object> > funcItems) { try { IntLineStream lines = new IntLineStream(debug.OldPath); if (db.Attached["EntireRewrite"] != null && (bool)db.Attached["EntireRewrite"]) { lines.ClearAfterComments(); } lines.Remove(db); string line; for (int i = from; i < to; i++) { DbAttribute att = db.AttributeList.Attributes[i]; if ((att.Visibility & VisibleState.Hidden) == VisibleState.Hidden) { to = i; break; } } List <DbAttribute> attributes = new List <DbAttribute>(db.AttributeList.Attributes.Skip(from).Take(to)); attributes.Reverse(); List <DbAttribute> attributesToRemove = (from attribute in attributes where db.Attached[attribute.DisplayName] != null let isLoaded = (bool)db.Attached[attribute.DisplayName] where !isLoaded select attribute).ToList(); IEnumerable <ReadableTuple <int> > list; if (db.Attached["EntireRewrite"] != null && (bool)db.Attached["EntireRewrite"]) { list = db.Table.FastItems.Where(p => !p.Deleted).OrderBy(p => p.Key); } else { list = db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.Key); } foreach (ReadableTuple <int> tuple in list) { int key = tuple.GetKey <int>(); List <object> rawElements = tuple.GetRawElements().Skip(from).Take(to).ToList(); funcItems(tuple, rawElements); foreach (var attribute in attributesToRemove) { rawElements.RemoveAt(attribute.Index - from); } line = string.Join(",", rawElements.Select(p => (p ?? "").ToString()).ToArray()); lines.Write(key, line); } lines.WriteFile(debug.FilePath); } catch (Exception err) { debug.ReportException(err); } }
public static void DbWriterComma(DbDebugItem <int> debug, AbstractDb <int> db, int from, int to) { DbWriterComma(debug, db, from, to, (t, p) => { }); }
public static void DbWriterComma(DbDebugItem <int> debug, AbstractDb <int> db) { DbWriterComma(debug, db, 0, db.AttributeList.Attributes.Count); }
public override void GenSql(AbstractDb.ISqlDumper dmp) { dmp.PutCmd("^alter ^table %f %k ^constraint %i", TableName, Disable ? "nocheck" : "check", ConstraintName); }