internal ArrayList p_ReadMultiple(object persistableObject, string top, string where, string orderby, string groupby) { PersistDataSourceAttribute pdsa; // contient les requetes utile pour l'acces au données PersistConnectionStringAttribute pcs; // contient l'attribut de la chaine de connexion ArrayList alPrimaryKeys; // contient la liste des clés primaire SortedList slFieldsValue; // contient la liste des champs et leur valeurs Type persistableObjectType = persistableObject.GetType(); // on recupere les informations sur le type de l'objet a persister ArrayList alAggregatedObjects = GetAggregatedObject(persistableObject); GetDatabaseInformation(persistableObjectType, out pdsa, out pcs); // on recupere les infos sur les cle primaires CreateFieldAndPKeyList(persistableObjectType, out alPrimaryKeys, out slFieldsValue); ArrayList alMultObject = new ArrayList(); string reqSql = "SELECT"; if (top != null) { reqSql += " TOP " + top; } reqSql += " "; string separateur = ""; foreach (string pk in alPrimaryKeys) { PersistFieldInfo pfi = (PersistFieldInfo)slFieldsValue[pk]; reqSql += separateur + pfi.DBFieldName; separateur = ","; } if (groupby != null) { reqSql += separateur + groupby; } reqSql += " FROM " + pdsa.TableName; if (where != null) { reqSql += " WHERE " + where; } if (groupby != null) { reqSql += " GROUP BY " + groupby; } if (orderby != null) { reqSql += " ORDER BY " + orderby; } // on se connecte a la base de donnée en utilisant la chaine de connection présent dans l'attribut [PersistConnectionString] IDbConnection cnx = dbhelper.GetConnection(pcs.ConnectionString); IDbCommand cmd = dbhelper.GetNewCommand(reqSql); cmd.Connection = cnx; IDataReader rdr = cmd.ExecuteReader(); Type tpo = persistableObject.GetType(); while (rdr.Read()) { SortedList slNewFieldValue = new SortedList(); object npo = Activator.CreateInstance(tpo); foreach (string pk in alPrimaryKeys) { PersistFieldInfo pfi = (PersistFieldInfo)slFieldsValue[pk]; pfi.SetInstanceValue(npo, rdr[pfi.DBFieldName]); } PersistDAL.Read(npo); alMultObject.Add(npo); } rdr.Close(); rdr.Dispose(); cmd.Dispose(); dbhelper.GetConnection("").Close(); return(alMultObject); }
public override void GenerateCommands(object persistableObject, IDBContextHelper helper, ArrayList PrimaryKeys, SortedList FieldValue) { // crée les 4 Commandes SQL pour l'execution des proc stock ainsi que La listes des paramètres if (p_ct_select != null) // creation d'une requete SELECT ? { // creation de la requete Select p_cmdSelect = helper.GetNewCommand(p_ct_select); p_cmdSelect.CommandType = CommandType.StoredProcedure; // creation des parametres de la requete foreach (string spparamname in PrimaryKeys) { helper.AddParameter(p_cmdSelect, "@" + spparamname, ((PersistFieldInfo)(FieldValue[spparamname])).DBType, ((PersistFieldInfo)(FieldValue[spparamname])).DBValue(persistableObject)); } } if (p_ct_insert != null) // creation d'une requete INSERT ? { // creation de la requete Insert p_cmdInsert = helper.GetNewCommand(p_ct_insert); p_cmdInsert.CommandType = CommandType.StoredProcedure; // creation des parametres de la requete foreach (string spparamname in FieldValue.Keys) { if (((PersistFieldInfo)(FieldValue[spparamname])).Identity == true) { helper.AddParameter(p_cmdInsert, "@" + spparamname, ((PersistFieldInfo)(FieldValue[spparamname])).DBType, ((PersistFieldInfo)(FieldValue[spparamname])).DBValue(persistableObject), ParameterDirection.Output); } else { helper.AddParameter(p_cmdInsert, "@" + spparamname, ((PersistFieldInfo)(FieldValue[spparamname])).DBType, ((PersistFieldInfo)(FieldValue[spparamname])).DBValue(persistableObject)); } } } if (p_ct_update != null) // creation d'une requete UPDATE ? { // creation de la requete Update p_cmdUpdate = helper.GetNewCommand(p_ct_update); p_cmdUpdate.CommandType = CommandType.StoredProcedure; // creation des parametres de la requete foreach (string spparamname in FieldValue.Keys) { PersistFieldInfo pfi = (PersistFieldInfo)(FieldValue[spparamname]); helper.AddParameter(p_cmdUpdate, "@" + spparamname, pfi.DBType, pfi.DBValue(persistableObject)); } } if (p_ct_delete != null) // creation d'une requete DELETE ? { // creation de la requete Delete p_cmdDelete = helper.GetNewCommand(p_ct_delete); p_cmdDelete.CommandType = CommandType.StoredProcedure; // creation des parametres de la requete foreach (string spparamname in PrimaryKeys) { helper.AddParameter(p_cmdDelete, "@" + spparamname, ((PersistFieldInfo)(FieldValue[spparamname])).DBType, ((PersistFieldInfo)(FieldValue[spparamname])).DBValue(persistableObject)); } } }
internal ArrayList p_Query(Type persistableObjectType, params SQLRequestElement[] sqle) { throw new PersistException("Not implemented"); PersistDataSourceAttribute pdsa; // contient les requetes utile pour l'acces au données PersistConnectionStringAttribute pcs; // contient l'attribut de la chaine de connexion ArrayList alPrimaryKeys; // contient la liste des clés primaire SortedList slFieldsValue; // contient la liste des champs et leur valeurs //ArrayList alAggregatedObjects=GetAggregatedObject(persistableObject); GetDatabaseInformation(persistableObjectType, out pdsa, out pcs); // on recupere les infos sur les cle primaires CreateFieldAndPKeyList(persistableObjectType, out alPrimaryKeys, out slFieldsValue); ArrayList alMultObject = new ArrayList(); // ICI : appel du dbhelper pour contruire la requete SQL ! string reqSql = ""; ////// if (top!=null) reqSql+=" TOP " + top; ////// ////// reqSql+=" "; ////// ////// string separateur=""; ////// foreach(string pk in alPrimaryKeys) ////// { ////// PersistFieldInfo pfi=(PersistFieldInfo)slFieldsValue[pk]; ////// reqSql+=separateur + pfi.DBFieldName; ////// separateur=","; ////// } ////// if (groupby!=null) reqSql+=separateur+groupby; ////// ////// reqSql+=" FROM " + pdsa.TableName; ////// if (where!=null) reqSql+=" WHERE " + where; ////// if (groupby!=null) reqSql+=" GROUP BY " + groupby; ////// if (orderby!=null) reqSql+=" ORDER BY " + orderby; ////// // on se connecte a la base de donnée en utilisant la chaine de connection présent dans l'attribut [PersistConnectionString] IDbConnection cnx = dbhelper.GetConnection(pcs.ConnectionString); IDbCommand cmd = dbhelper.GetNewCommand(reqSql); cmd.Connection = cnx; IDataReader rdr = cmd.ExecuteReader(); Type tpo = persistableObjectType; while (rdr.Read()) { SortedList slNewFieldValue = new SortedList(); object npo = Activator.CreateInstance(tpo); foreach (string pk in alPrimaryKeys) { PersistFieldInfo pfi = (PersistFieldInfo)slFieldsValue[pk]; pfi.SetInstanceValue(npo, rdr[pfi.DBFieldName]); } PersistDAL.Read(npo); alMultObject.Add(npo); } rdr.Close(); rdr.Dispose(); cmd.Dispose(); dbhelper.GetConnection("").Close(); return(alMultObject); }