private void InitialDataHelper(string connName) { if (connName == null) { m_dataHelper = SQLHelper.Create(); return; } DatabaseMode databaseMode = m_DatabaseMode; if (databaseMode == DatabaseMode.SqlClient) { m_dataHelper = SQLHelper.Create(connName); } else { m_dataHelper = SQLHelper.Create(connName); } }
/// <summary> /// ���������ַ����������ݿ����Ӷ��� /// </summary> /// <param name="connName">���ݿ�������</param> private void InitialDataHelper(string connName) { if (connName == null) { this.m_dataHelper = SQLHelper.Create(); } else { switch (m_DatabaseMode) { case DatabaseMode.SqlClient: { this.m_dataHelper = SQLHelper.Create(connName); break; } default: { this.m_dataHelper = SQLHelper.Create(connName); break; } } } }
/// <summary> /// 根据Model数据表属性,预生成Select,Update,Delete,Insert语句主干 /// </summary> /// <param name="table">Model数据表属性</param> /// <param name="dataHelper">数据库连接对象</param> /// <param name="t">Model类型</param> internal void Initial(ModelAttribute table, IDbDataHelper dataHelper, Type t) { string selectColumns = string.Empty; string updateColumns = string.Empty; string insertColumns = string.Empty; string identityColumn = string.Empty; string insertselectColumns = string.Empty; string keysColumns = string.Empty; this.m_parameters = new Collection <IDataParameter>(); foreach (DBFieldInfoAttribute f in table) { if (f.Field == null) { FieldInfo field = t.GetField(f.FieldName); if (field == null) { throw new MyModel.MyException(string.Format("Model[{0}]中没有字段名为[{1}]的private或protected的字段。", t, f.FieldName)); } f.Field = field; } f.ParameterPrefix = dataHelper.ParameterPrefix; f.Prefix = dataHelper.Prefix; f.Suffix = dataHelper.Suffix; IDataParameter parm = dataHelper.Parameter(f.ParameterName, dataHelper.DbType(f), f.ColumnName); this.m_parameters.Add(parm); // 自增字段 if (f.IsIdentity) { this.m_identityParm = new ParmCollection(parm); this.m_identityParm.WhereSql = string.Format(" WHERE {0}={1} ", f.ColumnNameFix, f.ParameterName); identityColumn = f.ColumnNameFix; } else { if (f.SqlDbType != SqlDbType.Timestamp) { updateColumns += string.Format("{0}={1}, ", f.ColumnNameFix, f.ParameterName); insertColumns += string.Format("{0}, ", f.ParameterName); insertselectColumns += string.Format("{0}, ", f.ColumnNameFix); } selectColumns += string.Format("{0}, ", f.ColumnNameFix); } if (f.IsKey) { this.m_keysParms.Add(parm); keysColumns += string.Format("{0}={1} AND ", f.ColumnNameFix, f.ParameterName); } if (f.IsMainKey) { this.m_treeMainKeyColName = f.ColumnName; } if (f.IsParentKey) { this.m_treeParentKeyColName = f.ColumnName; } } if (identityColumn == string.Empty && selectColumns == string.Empty) { throw new MyModel.MyException(t.ToString() + " 类中没有一个Field应用DbFieldInfoAttribute属性。"); } string select = selectColumns.Substring(0, selectColumns.Length - 2); string insertselect = insertselectColumns.Substring(0, insertselectColumns.Length - 2); this.m_fields = table; this.m_modelName = t.ToString(); this.m_tableName = table.AttrTable.TableName; this.m_select = string.Format("SELECT {0}{1} FROM {2} {3} {4}", identityColumn == string.Empty ? string.Empty : (identityColumn + ", "), select, "{0}", "{1}", "{2}"); this.m_update = string.Format("UPDATE {0} SET {1} {2}", "{0}", updateColumns.Substring(0, updateColumns.Length - 2), "{1}"); this.m_insert = string.Format("INSERT INTO {0}({1}) OUTPUT INSERTED.* VALUES({2})", "{0}", insertselect, insertColumns.Substring(0, insertColumns.Length - 2)); this.m_insertCol = string.Format("INSERT INTO {0}({1}) VALUES({2})", "{0}", insertselect, "{1}"); this.m_keysParms.WhereSql = keysColumns.Length > 0 ? string.Format(" WHERE {0}", keysColumns.Substring(0, keysColumns.Length - 4)) : string.Empty; }
public DALBaseNew() { m_dataHelper = SQLHelper.Create(); }
/// <summary> /// ����DAL���� /// </summary> public DALBase() { this.m_dataHelper = SQLHelper.Create(); }