private static void Test1() { Energy.Source.Structure.Table table = Energy.Source.Structure.Table.Create(typeof(UserTableRecord)); string query; Energy.Interface.IDialect script = new Energy.Query.Dialect.MYSQL(); query = script.DropTable(table.Name); if (db.Execute(query) < 0) { Console.WriteLine(db.ErrorMessage); } Console.WriteLine(query); Energy.Query.Script scriptBuilder = new Energy.Query.Script(); scriptBuilder.Dialect = Energy.Enumeration.SqlDialect.SQLSERVER; Energy.Query.Format format = Energy.Enumeration.SqlDialect.MYSQL; query = script.CreateTable(table); if (db.Execute(query) < 0) { Console.WriteLine(db.ErrorMessage); } Console.WriteLine(query); Console.ReadLine(); }
public void Binary() { byte[] b; b = new byte[] { 1, 2, 3, 4 }; Energy.Query.Format format = new Energy.Query.Format(); string s; s = format.Binary(b); Assert.IsNotNull(s); Assert.AreEqual("0x01020304", s); }
public string ToString(string glue) { Energy.Query.Format format = _Format ?? Energy.Query.Format.Default; bool unicode = this.Unicode; List <string> l = new List <string>(); foreach (KeyValuePair <string, object> o in _Values) { l.Add(o.Key + glue + format.Value(o.Value, GetType(o.Key), unicode)); } return(string.Join(Energy.Base.Text.NL, l.ToArray())); }
public void QueryFormat() { string value; string result; string expect; Energy.Query.Format format = new Energy.Query.Format(); value = "1,2"; result = format.Number(value); expect = "1.2"; Assert.AreEqual(expect, result); value = "1.2"; result = format.Number(value); expect = "1.2"; Assert.AreEqual(expect, result); value = "'"; expect = "''''"; result = format.Text(value); Assert.AreEqual(expect, result); value = "'Database open'"; expect = "'''Database open'''"; result = format.Text(value); Assert.AreEqual(expect, result); format.Bracket.Object = "[]"; format.Bracket.Object.Include = "]]"; value = "[]"; expect = "[[]]]"; result = format.Object(value); Assert.AreEqual(expect, result); string[] array = new string[] { null, "", "'", "''" }; Assert.AreEqual(0, Energy.Base.Text.Compare(format.Text(array), new string[] { "NULL", "''", "''''", "''''''" })); }
// TODO Check if this property is needed anywhere. Maybe it should be removed? #if !NETCF public Format this[string dialect] { get { if (string.IsNullOrEmpty(dialect)) { return(null); } Energy.Query.Format findFormat = null; if (_DialectFormatDictionary == null) { _DialectFormatDictionary = new Dictionary <string, Format>(); } else { findFormat = Energy.Base.Collection.GetStringDictionaryValue <Energy.Query.Format>(_DialectFormatDictionary, dialect, true); } if (findFormat == null) { System.Type classFormat = null; System.Reflection.Assembly assembly = System.Reflection.Assembly.GetAssembly(typeof(Energy.Query.Format)); System.Type[] types; types = assembly.GetTypes(); System.Type[] class1Array = Energy.Base.Class.GetTypesWithAttribute(types, typeof(Energy.Attribute.Code.TemporaryAttribute)); System.Type[] class2Array = Energy.Base.Class.GetTypesWithInterface(types, typeof(Energy.Interface.IDialect)); classFormat = Energy.Base.Collection.GetFirstOrDefault <System.Type>(class1Array, class2Array); if (classFormat != null) { findFormat = (Energy.Query.Format)Activator.CreateInstance(classFormat); _DialectFormatDictionary[dialect] = findFormat; } } return(findFormat); } }
/// <summary> /// Parse parametrized query string. /// </summary> /// <param name="query"></param> /// <returns></returns> public string Parse(string query) { if (string.IsNullOrEmpty(query)) { return(query); } bool optionUnicode = this.Unicode; bool optionUnknownAsEmpty = this.UnknownAsEmpty; bool optionUnknownAsNull = this.UnknownAsNull; bool optionNullAsZero = this.NullAsZero; bool allowUnknow = optionUnknownAsEmpty || optionUnknownAsNull; Energy.Query.Format format = _Format ?? Energy.Query.Format.Default; RegexOptions regexOptions = RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace; Regex regexVariable = new Regex(patternVariable, regexOptions); int Δ = 0; foreach (Match matchVariable in regexVariable.Matches(query)) { string name = matchVariable.Groups["name"].Value; if (string.IsNullOrEmpty(name)) { continue; } string value; if (Contains(name)) { object o = GetValue(name); Energy.Enumeration.FormatType f = GetType(name); if (optionNullAsZero && o == null) { o = 0; } value = format.Value(o, f, optionUnicode); } else if (!allowUnknow) { continue; } else if (name.StartsWith("@@")) { continue; } else if (optionUnknownAsEmpty) { value = format.Text(""); } else if (optionNullAsZero) { value = "0"; } else { value = "NULL"; } int p = matchVariable.Index; int l = matchVariable.Length; query = "" + (p + Δ > 0 ? query.Substring(0, p + Δ) : "") + value + query.Substring(p + l + Δ) ; Δ += value.Length - l; } return(query); }
public SQLITE(Energy.Query.Format format) { this.Format = format; }
public MYSQL(Energy.Query.Format format) { this.Format = format; }