public override string BuildConnectionString(NameValueList pms) { StringBuilder res = new StringBuilder("Provider=Microsoft.Jet.OLEDB.4.0;"); if (pms.ContainsKey("FilePath")) { if (!string.IsNullOrEmpty(pms["FilePath"] as string)) { res.AppendFormat("Data Source={0};", Path.GetFullPath(pms["FilePath"] as string)); } } if (pms.ContainsKey("Password")) { if (!string.IsNullOrEmpty(pms["Password"] as string)) { res.AppendFormat("Password={0};", pms["Password"]); } } if (pms.ContainsKey("ExtraConfiguration")) { if (pms["ExtraConfiguration"] is NameValueList) { foreach (NameValue nv in pms["ExtraConfiguration"] as NameValueList) { res.AppendFormat("{0}={1};", nv.Name, nv.Value); } } } return(res.ToString()); }
public override string BuildConnectionString(NameValueList pms) { StringBuilder res = new StringBuilder("Provider=Microsoft.Jet.OLEDB.4.0;"); if (pms.ContainsKey("FilePath")) if (!string.IsNullOrEmpty(pms["FilePath"] as string)) res.AppendFormat("Data Source={0};", Path.GetFullPath(pms["FilePath"] as string)); if (pms.ContainsKey("Password")) if (!string.IsNullOrEmpty(pms["Password"] as string)) res.AppendFormat("Password={0};", pms["Password"]); if (pms.ContainsKey("ExtraConfiguration")) if (pms["ExtraConfiguration"] is NameValueList) foreach (NameValue nv in pms["ExtraConfiguration"] as NameValueList) res.AppendFormat("{0}={1};", nv.Name, nv.Value); return res.ToString(); }
public static Command GetUpdateCommand(Where where, IEnumerable <NameValue> pms) { if (pms.Count() == 0) { return(null); } StringBuilder ss = new StringBuilder(); NameValueList pre = new NameValueList(pms); NameValueList _pms = new NameValueList(); foreach (var fi in AllFields) { if (pre.ContainsKey(fi.Attribute.DbFieldName)) { ss.AppendFormat("{0}=@{1},", fi.EnsuredName, fi.Attribute.DbFieldName); _pms.Add(GetFieldValue(fi, InsertType.None, pre[fi.Attribute.DbFieldName])); } } if (ss.Length > 0) { ss.Remove(ss.Length - 1, 1); } Command cmd = DbProvider.CreateCommand(string.Format("update {0} set {1}", EnsuredTableName, ss), _pms); Builder.AppendWhereByEnsuredKey(cmd, where, KeyField.EnsuredName, DbProvider.Adapter); return(cmd); }
public static Command GetInsertCommand(InsertType iops, IEnumerable <NameValue> pms) { if (pms.Count() == 0) { return(null); } StringBuilder ss = new StringBuilder(), vs = new StringBuilder(); NameValueList pre = new NameValueList(pms); NameValueList _pms = new NameValueList(); foreach (var fi in AllFields) { if (pre.ContainsKey(fi.Attribute.DbFieldName)) { if (iops == InsertType.New && fi.Key) { continue; } ss.AppendFormat("{0},", fi.EnsuredName); vs.AppendFormat("@{0},", fi.Attribute.DbFieldName); _pms.Add(GetFieldValue(fi, InsertType.None, pre[fi.Attribute.DbFieldName])); } } if (ss.Length > 0) { ss.Remove(ss.Length - 1, 1); vs.Remove(vs.Length - 1, 1); } return(DbProvider.CreateCommand(string.Format("insert into {0} ({1}) values ({2})", EnsuredTableName, ss, vs), _pms)); }
/// <summary> /// 所需参数: Host, Database, Username, Password, ExtraConfiguration(NameValueList)。 /// </summary> public virtual string BuildConnectionString(NameValueList pms) { string res = ""; if (pms.ContainsKey("Host")) { if (!string.IsNullOrEmpty(pms["Host"] as string)) { res = string.Format("Data Source={0};", pms["Host"]); } } if (pms.ContainsKey("Database")) { if (!string.IsNullOrEmpty(pms["Database"] as string)) { res = string.Format("{0}Initial Catalog={1};", res, pms["Database"]); } } if (pms.ContainsKey("Username")) { if (!string.IsNullOrEmpty(pms["Username"] as string)) { res = string.Format("{0}User ID={1};", res, pms["Username"]); } } if (pms.ContainsKey("Password")) { if (!string.IsNullOrEmpty(pms["Password"] as string)) { res = string.Format("{0}Password={1};", res, pms["Password"]); } } if (pms.ContainsKey("ExtraConfiguration")) { if (pms["ExtraConfiguration"] is NameValueList) { foreach (NameValue nv in pms["ExtraConfiguration"] as NameValueList) { res = string.Format("{0}{1}={2};", res, nv.Name, nv.Value); } } } return(res); }
/* * public virtual void InitializeOwner(Transaction trans, params string[] fields) * { * bool all = false; * if (fields.Length == 0) * all = true; * foreach (MemberInfo mi in OwnerFields) * { * if (all || mi.Name.In(fields)) * { * DataOwnerFieldAttribute a = mi.GetAttribute<DataOwnerFieldAttribute>(); * SetValue(mi.Name, a.GetMethod( * new Where(a.OwnedFieldName + "=@0", Key), null, null, trans)); * } * } * } * protected virtual void InitializeAutoLoadFields(Transaction trans) * { * List<string> autoloadfields = new List<string>(); * foreach (MemberInfo mi in OwnerFields) * { * DataOwnerFieldAttribute a = mi.GetAttribute<DataOwnerFieldAttribute>(); * if (a.AutoLoad) * autoloadfields.Add(mi.Name); * } * if (autoloadfields.Count > 0) * InitializeOwner(trans, autoloadfields.ToArray()); * } */ protected virtual void InitializeOri(NameValueList nv, Transaction trans) { foreach (var fi in AllFields) { if (nv.ContainsKey(fi.Attribute.DbFieldName)) { SetValue(fi.Attribute.DbFieldName, nv[fi.Attribute.DbFieldName]); } } //InitializeAutoLoadFields(trans); }
public static void Reload(Transaction trans, params string[] fields) { lock (Singleton) { if (_buf == null) { _buf = new NameValueList(); } Command cmd = new Command(string.Format("select * from {0}", EnsuredTableName)); if (fields.Length > 0) { Builder.AppendWhere( cmd, new Compare(KeyFieldName, fields as object[]).ToWhere(), KeyFieldName, DbProvider.Adapter ); } else { _buf.Clear(); } NameValueList _old_buf = _buf; _buf = new NameValueList(); (Singleton as DbConfiguration <T>).Initialize(); foreach (var i in _buf) { if (!_old_buf.ContainsKey(i.Name)) { _old_buf.Add(i); } } _buf = _old_buf; NameValueList[] res = cmd.Execute(trans); foreach (var nv in res) { try { _buf.Add( nv.Get <string>(KeyFieldName), Burst.Utils.DeserializeAs( nv.Get <object>(ValueFieldName), Type.GetType(nv.Get <string>(TypeFieldName)), SerializeType ) ); } catch { } } } }
/// <summary> /// 所需参数: Host, Database, Username, Password, ExtraConfiguration(NameValueList)。 /// </summary> public virtual string BuildConnectionString(NameValueList pms) { string res = ""; if (pms.ContainsKey("Host")) if (!string.IsNullOrEmpty(pms["Host"] as string)) res = string.Format("Data Source={0};", pms["Host"]); if (pms.ContainsKey("Database")) if (!string.IsNullOrEmpty(pms["Database"] as string)) res = string.Format("{0}Initial Catalog={1};", res, pms["Database"]); if (pms.ContainsKey("Username")) if (!string.IsNullOrEmpty(pms["Username"] as string)) res = string.Format("{0}User ID={1};", res, pms["Username"]); if (pms.ContainsKey("Password")) if (!string.IsNullOrEmpty(pms["Password"] as string)) res = string.Format("{0}Password={1};", res, pms["Password"]); if (pms.ContainsKey("ExtraConfiguration")) if (pms["ExtraConfiguration"] is NameValueList) foreach (NameValue nv in pms["ExtraConfiguration"] as NameValueList) res = string.Format("{0}{1}={2};", res, nv.Name, nv.Value); return res; }