/// <summary> /// Виконання SQL запитів /// </summary> /// <param name="fileStepSQL">Файл з запитами</param> public bool ExecuteSqlList(string fileStepSQL) { XPathDocument xPathDoc = new XPathDocument(fileStepSQL); XPathNavigator xPathDocNavigator = xPathDoc.CreateNavigator(); XPathNodeIterator rowNodes = xPathDocNavigator.Select("/root/row"); while (rowNodes.MoveNext()) { if (Cancel) { return(false); } XPathNavigator sqlNode = rowNodes.Current.SelectSingleNode("sql"); string sqlText = sqlNode.Value; Dictionary <string, object> param = new Dictionary <string, object>(); XPathNodeIterator paramNodes = rowNodes.Current.Select("p"); while (paramNodes.MoveNext()) { string paramName = paramNodes.Current.GetAttribute("name", ""); string paramType = paramNodes.Current.GetAttribute("type", ""); string paramValue = paramNodes.Current.Value; object paramObj; switch (paramType) { case "Guid": { paramObj = Guid.Parse(paramValue); break; } case "Int32": { paramObj = int.Parse(paramValue); break; } case "DateTime": { paramObj = DateTime.Parse(paramValue); break; } case "TimeSpan": { paramObj = TimeSpan.Parse(paramValue); break; } case "Boolean": { paramObj = Boolean.Parse(paramValue); break; } case "Decimal": { paramObj = Decimal.Parse(paramValue); break; } case "String": { paramObj = paramValue; break; } case "String[]": { paramObj = ArrayToXml.Convert(paramNodes.Current.InnerXml); break; } case "Int32[]": { string[] tmpValue = ArrayToXml.Convert(paramNodes.Current.InnerXml); int[] tmpIntValue = new int[tmpValue.Length]; for (int i = 0; i < tmpValue.Length; i++) { tmpIntValue[i] = int.Parse(tmpValue[i]); } paramObj = tmpIntValue; break; } case "Decimal[]": { string[] tmpValue = ArrayToXml.Convert(paramNodes.Current.InnerXml); decimal[] tmpDecimalValue = new decimal[tmpValue.Length]; for (int i = 0; i < tmpValue.Length; i++) { tmpDecimalValue[i] = decimal.Parse(tmpValue[i]); } paramObj = tmpDecimalValue; break; } case "UuidAndText": { paramObj = ArrayToXml.ConvertUuidAndText(paramNodes.Current.InnerXml); break; } default: { ApendLine("Не оприділений тип: " + paramType); paramObj = paramValue; break; } } param.Add(paramName, paramObj); } int result = Program.Kernel.DataBase.ExecuteSQL(sqlText, param); ApendInfo("."); } return(true); }
/// <summary> /// Виконання запиту та запис даних /// </summary> /// <param name="xmlWriter">ХМЛ</param> /// <param name="query">Запит</param> void WriteQuerySelect(XmlWriter xmlWriter, string query) { string[] columnsName; List <object[]> listRow; Program.Kernel.DataBase.SelectRequest(query, null, out columnsName, out listRow); foreach (object[] row in listRow) { int counter = 0; xmlWriter.WriteStartElement("row"); foreach (string column in columnsName) { string typeName = row[counter].GetType().Name; if (typeName != "DBNull") { xmlWriter.WriteStartElement(column); xmlWriter.WriteAttributeString("type", typeName); switch (typeName) { case "String[]": { xmlWriter.WriteRaw(ArrayToXml <string> .Convert((string[])row[counter])); break; } case "Int32[]": { xmlWriter.WriteRaw(ArrayToXml <int> .Convert((int[])row[counter])); break; } case "Decimal[]": { xmlWriter.WriteRaw(ArrayToXml <decimal> .Convert((decimal[])row[counter])); break; } case "UuidAndText": { xmlWriter.WriteRaw(((UuidAndText)row[counter]).ToXml()); break; } default: { xmlWriter.WriteString(row[counter].ToString()); break; } } xmlWriter.WriteEndElement(); } counter++; } xmlWriter.WriteEndElement(); } xmlWriter.Flush(); }