Seth77
Messages postés572Date d'inscriptionmardi 30 avril 2002StatutMembreDernière intervention 4 mai 2020
-
4 sept. 2006 à 14:31
Seth77
Messages postés572Date d'inscriptionmardi 30 avril 2002StatutMembreDernière intervention 4 mai 2020
-
13 nov. 2006 à 09:37
Salut
voila je commence a faire un package pour l'accés à la base de données ...qu'en pensez vous ?
c juste un debut
je pense ensuite faire les ajout par SQL...
--------------------------------------------------------------------------------------------------------------------------------------
namespace Create_BD
{
class DB_Type
{
static public String getBool() { return "BIT"; }
static public String getShort() { return "SHORT"; }
}
class DB_Champ
{
private String Nom;
private String Type;
private int Size = 0;
class DB_Table
{
private String Nom;
private ArrayList ListeChamp;
public DB_Table()
{
this.ListeChamp = new ArrayList();
}
public void setNom(String theNom) {this.Nom = theNom;}
public String getNom() {return this.Nom;}
public bool Add(DB_Champ theChamp)
{
for (int i = 0; i < this.ListeChamp.Count; i++)
{
if (((DB_Champ)this.ListeChamp[i]).getNom() == theChamp.getNom())
return false;
}
ListeChamp.Add(theChamp);
return true;
}
public void toConsole()
{
Console.WriteLine("------------------------------------------------------------------");
Console.WriteLine(this.Nom);
for (int i = 0; i < this.ListeChamp.Count; i++)
{
((DB_Champ)this.ListeChamp[i]).toConsole();
}
Console.WriteLine("------------------------------------------------------------------");
}
}
class Create_DB
{
private String DBPath;
private ArrayList ListTable;
public String getDBPath()
{
return this.DBPath;
}
public void setDBPath(String theDBPath)
{
this.DBPath = theDBPath;
}
public void AddTable(DB_Table theTable)
{
this.ListTable.Add(theTable);
}
public Create_DB() {
this.DBPath = "";
this.ListTable = new ArrayList();
}
}
}
--------------------------------------------------------------------------------------------------------------------------------------
Seth77
Messages postés572Date d'inscriptionmardi 30 avril 2002StatutMembreDernière intervention 4 mai 20201 6 sept. 2006 à 16:29
Est ce correcte :
try
{
if (ListeChamp.Contains(theChamp))
throw new Exception("Champ déja présent dans la table");
ListeChamp.Add(theChamp);
}
catch (Exception aExcep)
{
MessageBox.Show(aExcep.Message);
}
Seth77
Messages postés572Date d'inscriptionmardi 30 avril 2002StatutMembreDernière intervention 4 mai 20201 26 oct. 2006 à 18:32
Voici une nouvelle version de ma classe
using System;
using System.Collections;
using System.Text;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Data;
using ADOX;
using Fonctions_Time;
public String Nom
{
get { return this.nom; }
set { this.nom = value; }
}
public DB_ObjType Type
{
get { return this.type; }
set { this.type = value; }
}
public bool Nullable
{
get { return this.nullable; }
set { this.nullable = value; }
}
public override string ToString()
{
return this.nom;
}
public override int GetHashCode()
{
return this.nom.ToLowerInvariant().GetHashCode();
}
public override bool Equals(object obj)
{
DB_Champ t = obj as DB_Champ;
return t.Nom == this.nom;
}
public DB_Table(String theNom)
{
this.ListeChamp = new List<DB_Champ>();
this.ListeKey = new List<DB_Champ>();
this.nom = theNom;
}
public String Nom
{
get { return this.nom; }
set { this.nom = value; }
}
public List<DB_Champ> Champs
{
get { return this.ListeChamp; }
}
public List<DB_Champ> Keys
{
get { return this.ListeKey; }
}
public void Add(DB_Champ theChamp)
{
try
{
if (ListeChamp.Contains(theChamp))
throw new DB_Exception("Champ déjà présent dans la table");
ListeChamp.Add(theChamp);
}
catch{}
}
public void AddKey(DB_Champ theChamp)
{
try
{
if (ListeKey.Contains(theChamp))
throw new DB_Exception("Champ déjà présent dans la table");
ListeKey.Add(theChamp);
}
catch {}
}
public void toConsole()
{
Console.WriteLine("--------------------------------------------------------------------------------------------------------");
Console.WriteLine("Table : " + this.nom);
Console.WriteLine(" - CHAMPS -");
for (int i = 0; i < this.ListeChamp.Count; i++)
this.ListeChamp[i].toConsole();
Console.WriteLine(" -> Nb champs :" + this.ListeChamp.Count);
Console.WriteLine(" - KEYS -");
for (int i = 0; i < this.ListeKey.Count; i++)
this.ListeKey[i].toConsole();
Console.WriteLine(" -> Nb keys :" + this.ListeKey.Count);
Console.WriteLine("--------------------------------------------------------------------------------------------------------");
}
}
public OleDbConnection DBConnection
{
get { return this.DbConnec; }
}
public static DB_ConnectDB GetInstance()
{
//creer une nouvelle instance s il n en existe pas deja une autre
if (_theUniqueInstance == null)
return _theUniqueInstance = new DB_ConnectDB();
else
return _theUniqueInstance;
}
public DB_ConnectDB()
{ String chaineCnx "provider microsoft.jet.oledb.4.0 ; data source = " + ConfigApp.Config.DbPath;
DbConnec = new OleDbConnection(chaineCnx);
this.Open();
}
public void Open()
{
if (DbConnec.State == System.Data.ConnectionState.Closed)
DbConnec.Open();
}
public void Close()
{
if (DbConnec.State == System.Data.ConnectionState.Open)
DbConnec.Close();
}
}
MorpionMx
Messages postés3466Date d'inscriptionlundi 16 octobre 2000StatutMembreDernière intervention30 octobre 200857 28 oct. 2006 à 09:51
C'est pas que ca nous inspire pas, c'est surtout qu'on a pas forcément le temps de tout analyser ;)
Pour eviter les injections SQL, utilises des requetes paramétrées plutot que des chaines concaténées pour tes requetes.
N'hésite pas a poster une source avec ton code, que tu feras évoluer, plutot que de tout poster en bloc sur le forum ;)
MorpionMx
Messages postés3466Date d'inscriptionlundi 16 octobre 2000StatutMembreDernière intervention30 octobre 200857 28 oct. 2006 à 11:34
Non, pas un ArrayList, sachant qu'un ArrayList stocke des object.
Ca voudrait dire boxing (tu vas passer d'un string a un object quand tu vas ajouter tes strings a ta collection) puis unboxing (tu vas repasser d'un object a un string qaund tu vas vouloir recuperer tes valeurs) -> Donc baisse de perfs.
A la limite, tu peux utiliser un List<string> plutot, là tu n'auras plus ce probleme de boxing / unboxing. (de facon générale, en .Net 2, on utilise des collections génériques)
D'ailleurs, quand tu recuperes les elements de ton tableau, tu n'as pas besoin d'appeler ToString(), sachant que tu recuperes deja des strings
Seth77
Messages postés572Date d'inscriptionmardi 30 avril 2002StatutMembreDernière intervention 4 mai 20201 13 nov. 2006 à 09:03
Salut
J'ai remarque un probleme, dans mon app je test au
demarrage l'existence de la BDD sinon je la cree.. et ensuite je fais
qq requetes ...mon prob est que lorsque je lance le prog, sans BDD, il
ZAP la premiere requete
Si je la lance en pas a pas ou que la bdd existe deja, il n'y a aucun
probleme, la premiere est bien lance et existe dans la BDD !
le plus etrange c'est que le prog passe bien dans les differentes fonctions ....
MorpionMx
Messages postés3466Date d'inscriptionlundi 16 octobre 2000StatutMembreDernière intervention30 octobre 200857 13 nov. 2006 à 09:17
Salut
Sans bout de code, ca va etre difficile de t'indiquer le probleme.
Cependant, je t'invite a ouvrir nu nouveau sujet, ou indiquant précisément ton souci, plutot que d'utiliser ce sujet a rallonge ;) Comme ca tout le monde pourra en profiter.