private bool isTableExist(object obj) { dbPropertyInfoManager mgr = dbPropertyInfoManager.Instance; mgr.setObject(obj); return(isTableExist(mgr.tableName)); }
public string getDelete(object obj) { dbPropertyInfoManager mgr = dbPropertyInfoManager.Instance; mgr.setObject(obj); StringBuilder b = new StringBuilder(); string cond = ""; if (m_Conditions.Count > 0) { foreach (string field in m_Conditions.Keys) { b.Append(string.Format("{0}={1} AND", field, m_Values[field])); } cond = b.ToString(0, b.Length - 3); } string query; if (m_Conditions.Count > 0) { query = string.Format("DELETE {0} WHERE {1} ;", mgr.tableName, cond); } else { query = string.Format("DELETE {0};", mgr.tableName); } clear(); return(query); }
public string getInsert(object obj) { dbPropertyInfoManager mgr = dbPropertyInfoManager.Instance; mgr.setObject(obj); StringBuilder b = new StringBuilder(); foreach (string field in m_Values.Keys) { b.Append(field + ","); } string fields = string.Format("({0})", b.ToString(0, b.Length - 1)); b = new StringBuilder(); foreach (string v in m_Values.Values) { b.Append(v + ","); } string values = string.Format("({0});", b.ToString(0, b.Length - 1)); string sql = string.Format("INSERT INTO {0} {1} VALUES {2}", mgr.tableName, fields, values); clear(); return(sql); }
public string getTableXml(object obj) { dbPropertyInfoManager mgr = dbPropertyInfoManager.Instance; mgr.setObject(obj); return(getTableXml(mgr.tableName)); }
public string getCreateTable(object obj) { dbPropertyInfoManager mgr = dbPropertyInfoManager.Instance; mgr.setObject(obj); StringBuilder flds = new StringBuilder(); StringBuilder pk = new StringBuilder(); bool use_pk = false; flds.Append(string.Format("CREATE TABLE [{0}]", mgr.tableName)); flds.Append("("); foreach (dbPropertyInfo p in mgr) { if (p.isKey == true) { if (p.isAutoInc == true) { flds.Append(string.Format("{0} INTEGER PRIMARY KEY AUTOINCREMENT,", p.fieldName)); use_pk = true; continue; } else { pk.Append(p.fieldName + ","); } } if (p.defaultValue.Length > 0) { flds.Append(string.Format("{0} {1},", p.fieldName, p.fieldType)); } else { flds.Append(string.Format("{0} {1} {2},", p.fieldName, p.fieldType, p.defaultValue)); } } string prim_keys = ""; if (use_pk == false) { if (pk.Length > 0) { prim_keys = string.Format("PRIMARY KEY({0})", pk.ToString(0, pk.Length - 1)); } } string sql; if (prim_keys.Length > 0) { sql = string.Format("{0}{1})", flds.ToString(), prim_keys); } else { sql = string.Format("{0})", flds.ToString(0, flds.Length - 2)); } return(sql); }
public void select(IEnumerable list, object obj) { dbPropertyInfoManager mgr = dbPropertyInfoManager.Instance; mgr.setObject(obj); string query = string.Format("select * from {0}", mgr.tableName); select(list, obj, query); }
public void delete(object obj) { dbPropertyInfoManager mgr = dbPropertyInfoManager.Instance; mgr.setObject(obj); foreach (dbPropertyInfo p in mgr) { if (p.isKey == true) { addCondition(p.fieldName, p.getValue()); } } execute(getDelete(obj)); }
public void insert(object obj) { dbPropertyInfoManager mgr = dbPropertyInfoManager.Instance; mgr.setObject(obj); foreach (dbPropertyInfo p in mgr) { if (p.isAutoInc == false) { addValue(p.fieldName, p.getValue()); } } execute(getInsert(obj)); }
public string getSelect(object obj) { dbPropertyInfoManager mgr = dbPropertyInfoManager.Instance; mgr.setObject(obj); StringBuilder b = new StringBuilder(); string set = "", cond = ""; foreach (string field in m_Values.Keys) { b.Append(string.Format("{0},", field)); } if (b.Length > 1) { set = b.ToString(0, b.Length - 1); } if (m_Conditions.Count > 0) { foreach (string field in m_Conditions.Keys) { b.Append(string.Format("{0}={1} AND ", field, m_Conditions[field])); } cond = b.ToString(0, b.Length - 4); } string query; if (m_Values.Count == 0) { set = "*"; } if (m_Conditions.Count > 0) { query = string.Format("SELECT {0} FROM {1} WHERE {2} ;", set, mgr.tableName, cond); } else { query = string.Format("SELECT {0} FROM {1};", set, mgr.tableName); } clear(); return(query); }
public void select(IEnumerable list, object obj, string query) { dbPropertyInfoManager mgr = dbPropertyInfoManager.Instance; IDataReader r = select(query); while (r.Read()) { object newObject = Activator.CreateInstance(obj.GetType()); mgr.setObject(newObject); for (int i = 0; i < r.FieldCount; i++) { mgr.setValue(r.GetName(i), r.GetValue(i)); } IList ilist = (IList)list; ilist.Add(newObject); } }
public void select(object obj) { dbPropertyInfoManager mgr = dbPropertyInfoManager.Instance; mgr.setObject(obj); foreach (dbPropertyInfo p in mgr) { if (p.isKey) { addCondition(p.fieldName, p.getValue()); } } using (IDataReader r = select(getSelect(obj))) { if (r.Read()) { for (int i = 0; i < r.FieldCount; i++) { mgr.setValue(r.GetName(i), r.GetValue(i)); } } r.Close(); } }
public bool isItemExist(object obj) { dbPropertyInfoManager mgr = dbPropertyInfoManager.Instance; mgr.setObject(obj); addValue("count(*)", ""); foreach (dbPropertyInfo p in mgr) { if (p.isKey) { addCondition(p.fieldName, p.getValue()); } } using (IDataReader r = select(getSelect(obj)))//executeSelect(mgr.tableName)) { if (r.Read()) { return(r.GetInt32(0) > 0); } r.Close(); } return(false); }