begin process at 2012 02 11 18:05:04
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Base de données

 > EDITEUR DE BATCH POUR LOTS DE REQUETES SQL POUR MYSQL

EDITEUR DE BATCH POUR LOTS DE REQUETES SQL POUR MYSQL


 Information sur la source

 Description

Voila, c'est un truc tout con, qui sert a rien, mais je l'ai fait... En fait, il faut saisir une série de requetes SQL conformes (car mon appli verifie pas la syntaxe !) et en cliquant sur creer, l'appli génère un fichier contenant toutes les requetes et un exécutable qui lancera MySQL et exécutera les requetes ! L'avantage est que ca permet aussi l'execution de requete d'administration (privilege, droit, creation de bd, etc...).
A quoi ca peut etre utile ? Bah, il arrive que vous ayez a faire des lots de requetes assez souvent, une fois par semaine, ou plus, notamment des requetes d'administration. Grace a ce batch et au planificateur de taches de Win XP, vous pourrez faire en sorte que ce soit automatique et ne plus vous faire chier. Bref, ca va pas servir a grand monde...

En revanche, c'est ma premiere appli en C# (qui fonctionne du moins) donc j'attends avec impatience vos commentaire, conseils et critiques qui me permettront de m'ameliorer dans le langage !

A plus et bonne lecture !

Source

  • using System;
  • using System.Windows.Forms;
  • using System.IO;
  • using System.Diagnostics;
  • namespace DefaultNamespace
  • {
  • /// <summary>
  • /// Description of MainForm.
  • /// </summary>
  • public class MainForm : System.Windows.Forms.Form
  • {
  • private System.Windows.Forms.TextBox txtSQL;
  • private System.Windows.Forms.Label label2;
  • private System.Windows.Forms.Button cmdReset;
  • private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog;
  • private System.Windows.Forms.Label label3;
  • private System.Windows.Forms.TextBox txtUser;
  • private System.Windows.Forms.Button cmdCreer;
  • public MainForm()
  • {
  • //
  • // The InitializeComponent() call is required for Windows Forms designer support.
  • //
  • InitializeComponent();
  • //
  • // TODO: Add constructor code after the InitializeComponent() call.
  • //
  • }
  • [STAThread]
  • public static void Main(string[] args)
  • {
  • Application.Run(new MainForm());
  • }
  • #region Windows Forms Designer generated code
  • /// <summary>
  • /// This method is required for Windows Forms designer support.
  • /// Do not change the method contents inside the source code editor. The Forms designer might
  • /// not be able to load this method if it was changed manually.
  • /// </summary>
  • private void InitializeComponent() {
  • this.cmdCreer = new System.Windows.Forms.Button();
  • this.txtUser = new System.Windows.Forms.TextBox();
  • this.label3 = new System.Windows.Forms.Label();
  • this.folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
  • this.cmdReset = new System.Windows.Forms.Button();
  • this.label2 = new System.Windows.Forms.Label();
  • this.txtSQL = new System.Windows.Forms.TextBox();
  • this.SuspendLayout();
  • //
  • // cmdCreer
  • //
  • this.cmdCreer.Location = new System.Drawing.Point(408, 240);
  • this.cmdCreer.Name = "cmdCreer";
  • this.cmdCreer.TabIndex = 7;
  • this.cmdCreer.Text = "&Créer";
  • this.cmdCreer.Click += new System.EventHandler(this.CmdCreerClick);
  • //
  • // txtUser
  • //
  • this.txtUser.Location = new System.Drawing.Point(104, 8);
  • this.txtUser.Name = "txtUser";
  • this.txtUser.Size = new System.Drawing.Size(160, 20);
  • this.txtUser.TabIndex = 3;
  • this.txtUser.Text = "";
  • this.txtUser.WordWrap = false;
  • //
  • // label3
  • //
  • this.label3.Location = new System.Drawing.Point(8, 8);
  • this.label3.Name = "label3";
  • this.label3.TabIndex = 2;
  • this.label3.Text = "Utilisateur :";
  • //
  • // cmdReset
  • //
  • this.cmdReset.Location = new System.Drawing.Point(328, 240);
  • this.cmdReset.Name = "cmdReset";
  • this.cmdReset.TabIndex = 8;
  • this.cmdReset.Text = "&Reset";
  • this.cmdReset.Click += new System.EventHandler(this.CmdResetClick);
  • //
  • // label2
  • //
  • this.label2.Location = new System.Drawing.Point(8, 32);
  • this.label2.Name = "label2";
  • this.label2.TabIndex = 6;
  • this.label2.Text = "Requêtes :";
  • //
  • // txtSQL
  • //
  • this.txtSQL.Location = new System.Drawing.Point(8, 56);
  • this.txtSQL.Multiline = true;
  • this.txtSQL.Name = "txtSQL";
  • this.txtSQL.Size = new System.Drawing.Size(472, 176);
  • this.txtSQL.TabIndex = 5;
  • this.txtSQL.Text = "";
  • //
  • // MainForm
  • //
  • this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  • this.ClientSize = new System.Drawing.Size(488, 270);
  • this.Controls.Add(this.cmdReset);
  • this.Controls.Add(this.cmdCreer);
  • this.Controls.Add(this.label2);
  • this.Controls.Add(this.txtSQL);
  • this.Controls.Add(this.txtUser);
  • this.Controls.Add(this.label3);
  • this.Location = new System.Drawing.Point(-21, 0);
  • this.Name = "MainForm";
  • this.Text = "MainForm";
  • this.Load += new System.EventHandler(this.MainFormLoad);
  • this.ResumeLayout(false);
  • }
  • #endregion
  • void MainFormLoad(object sender, System.EventArgs e)
  • {
  • this.folderBrowserDialog.Description = "Sélectionnez le répertoire où vous désirez enregistrer les fichiers.\n(Conseil : mettez les dans un répertoire à eux pour les retrouver plus facilement.)";
  • }
  • void CmdCreerClick(object sender, System.EventArgs e)
  • {
  • string sFichierBatch;
  • string sFichierSQL;
  • string sCommande;
  • if((this.txtUser.Text != "") && (this.txtSQL.Text!=""))
  • {
  • if((this.folderBrowserDialog.ShowDialog() == DialogResult.OK)&&((MessageBox.Show("Si des fichiers ont déjà été créés à cet emplacement, ils seront perdus.\nEtes-vous sûr de vouloir sélectionner ce dossier ?","Attention",MessageBoxButtons.YesNo, MessageBoxIcon.Hand)) == DialogResult.Yes))
  • {
  • string sChemin = this.folderBrowserDialog.SelectedPath ;
  • if(sChemin[sChemin.Length-1].ToString() != "\\")
  • sChemin += "\\";
  • sFichierBatch = sChemin + "Executable.bat";
  • sFichierSQL = sChemin + "Requete.sql";
  • StreamWriter fBatch = File.CreateText(sFichierBatch);
  • StreamWriter fSQL = File.CreateText(sFichierSQL);
  • sCommande = "mysql -u " + this.txtUser.Text + " -p < Requete.sql";
  • fBatch.WriteLine(sCommande);
  • fBatch.Close();
  • fSQL.Write(this.txtSQL.Text);
  • fSQL.Close();
  • if(MessageBox.Show("Création des fichiers terminée.\nVoulez vous exécuter les requêtes maintenant ?","Création terminée",MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  • {
  • Process pBatch = new Process();
  • pBatch.StartInfo = new ProcessStartInfo();
  • pBatch.StartInfo.FileName = sFichierBatch;
  • pBatch.Start();
  • }
  • }
  • }
  • else
  • MessageBox.Show("Vous devez saisir un nom d'utilisateur (enregistré dans MySQL avec les droits nécessaires de préférence) et des requêtes à exécutées !","Erreur de saisie",MessageBoxButtons.OK, MessageBoxIcon.Error);
  • }
  • void CmdResetClick(object sender, System.EventArgs e)
  • {
  • if(MessageBox.Show("Etes-vous sûr de vouloir effacer tous les champs ?","Confirmation",MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
  • {
  • this.txtUser.Text = "";
  • this.txtSQL.Text = "";
  • }
  • }
  • }
  • }
using System;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;

namespace DefaultNamespace
{
	/// <summary>
	/// Description of MainForm.	
	/// </summary>
	public class MainForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox txtSQL;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Button cmdReset;
		private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox txtUser;
		private System.Windows.Forms.Button cmdCreer;
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		[STAThread]
		public static void Main(string[] args)
		{
			Application.Run(new MainForm());
		}
		
		#region Windows Forms Designer generated code
		/// <summary>
		/// This method is required for Windows Forms designer support.
		/// Do not change the method contents inside the source code editor. The Forms designer might
		/// not be able to load this method if it was changed manually.
		/// </summary>
		private void InitializeComponent() {
			this.cmdCreer = new System.Windows.Forms.Button();
			this.txtUser = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
			this.cmdReset = new System.Windows.Forms.Button();
			this.label2 = new System.Windows.Forms.Label();
			this.txtSQL = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			// 
			// cmdCreer
			// 
			this.cmdCreer.Location = new System.Drawing.Point(408, 240);
			this.cmdCreer.Name = "cmdCreer";
			this.cmdCreer.TabIndex = 7;
			this.cmdCreer.Text = "&Créer";
			this.cmdCreer.Click += new System.EventHandler(this.CmdCreerClick);
			// 
			// txtUser
			// 
			this.txtUser.Location = new System.Drawing.Point(104, 8);
			this.txtUser.Name = "txtUser";
			this.txtUser.Size = new System.Drawing.Size(160, 20);
			this.txtUser.TabIndex = 3;
			this.txtUser.Text = "";
			this.txtUser.WordWrap = false;
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(8, 8);
			this.label3.Name = "label3";
			this.label3.TabIndex = 2;
			this.label3.Text = "Utilisateur :";
			// 
			// cmdReset
			// 
			this.cmdReset.Location = new System.Drawing.Point(328, 240);
			this.cmdReset.Name = "cmdReset";
			this.cmdReset.TabIndex = 8;
			this.cmdReset.Text = "&Reset";
			this.cmdReset.Click += new System.EventHandler(this.CmdResetClick);
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(8, 32);
			this.label2.Name = "label2";
			this.label2.TabIndex = 6;
			this.label2.Text = "Requêtes :";
			// 
			// txtSQL
			// 
			this.txtSQL.Location = new System.Drawing.Point(8, 56);
			this.txtSQL.Multiline = true;
			this.txtSQL.Name = "txtSQL";
			this.txtSQL.Size = new System.Drawing.Size(472, 176);
			this.txtSQL.TabIndex = 5;
			this.txtSQL.Text = "";
			// 
			// MainForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(488, 270);
			this.Controls.Add(this.cmdReset);
			this.Controls.Add(this.cmdCreer);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.txtSQL);
			this.Controls.Add(this.txtUser);
			this.Controls.Add(this.label3);
			this.Location = new System.Drawing.Point(-21, 0);
			this.Name = "MainForm";
			this.Text = "MainForm";
			this.Load += new System.EventHandler(this.MainFormLoad);
			this.ResumeLayout(false);
		}
		#endregion
		
		
		void MainFormLoad(object sender, System.EventArgs e)
		{
			this.folderBrowserDialog.Description = "Sélectionnez le répertoire où vous désirez enregistrer les fichiers.\n(Conseil : mettez les dans un répertoire à eux pour les retrouver plus facilement.)";
		}
		
		void CmdCreerClick(object sender, System.EventArgs e)
		{
			string sFichierBatch;
			string sFichierSQL;
			string sCommande;
			
				
			if((this.txtUser.Text != "") && (this.txtSQL.Text!=""))
			{
				if((this.folderBrowserDialog.ShowDialog() == DialogResult.OK)&&((MessageBox.Show("Si des fichiers ont déjà été créés à cet emplacement, ils seront perdus.\nEtes-vous sûr de vouloir sélectionner ce dossier ?","Attention",MessageBoxButtons.YesNo, MessageBoxIcon.Hand)) == DialogResult.Yes))
				{
					string sChemin = this.folderBrowserDialog.SelectedPath ;
				
					if(sChemin[sChemin.Length-1].ToString() != "\\")
						sChemin += "\\";
				
					
					sFichierBatch = sChemin + "Executable.bat";
					sFichierSQL = sChemin + "Requete.sql";
					
					StreamWriter fBatch = File.CreateText(sFichierBatch);
					StreamWriter fSQL = File.CreateText(sFichierSQL);
					
					sCommande = "mysql -u " + this.txtUser.Text + " -p < Requete.sql";
					fBatch.WriteLine(sCommande);
					fBatch.Close();
					fSQL.Write(this.txtSQL.Text);
					fSQL.Close();
					if(MessageBox.Show("Création des fichiers terminée.\nVoulez vous exécuter les requêtes maintenant ?","Création terminée",MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
					{
						Process pBatch = new Process();
						pBatch.StartInfo = new ProcessStartInfo();
						pBatch.StartInfo.FileName = sFichierBatch;
						pBatch.Start();
					}
				}
			}
			else
				MessageBox.Show("Vous devez saisir un nom d'utilisateur (enregistré dans MySQL avec les droits nécessaires de préférence) et des requêtes à exécutées !","Erreur de saisie",MessageBoxButtons.OK, MessageBoxIcon.Error);
		}
		void CmdResetClick(object sender, System.EventArgs e)
		{
			if(MessageBox.Show("Etes-vous sûr de vouloir effacer tous les champs ?","Confirmation",MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
			{
				this.txtUser.Text = "";
				this.txtSQL.Text = "";
			}
		}
		
	}
}

 Conclusion

Allez, je me suis un peu laché sur les boites de dialogue, mais c'est pas grave, c'est marrant ! lol
Sinon, il y a surement des bugs, mais j'en ai pas vu. Signalez les moi pour que je corrige ca !

(Ils sont marrants, il demande le niveau ??? Bah, c'est du code expert, ca, au moins, non ????)


 Sources du même auteur

Source avec Zip Source .NET (Dotnet) CLASSE POUR CONNEXION À UN SERVEUR POP3 ET CHARGER LES EMAIL...
Source avec Zip Source avec une capture Source .NET (Dotnet) OUTIL D'ADMINISTRATION DE MYSQL

 Sources de la même categorie

Source .NET (Dotnet) ENTITY FRAMEWORK - AVOIR UN INCLUDE TYPÉ par jesusonline
Source avec Zip APPLICATION BASE DE DONNÉES par pretude
Source avec Zip Source avec une capture Source .NET (Dotnet) CRÉATION DE CLASSES MÉTIERS À PARTIR D'UNE BASE DE DONNÉES par sebmafate
Source avec Zip Source avec une capture Source .NET (Dotnet) C# SQLCE DEMO par DanMor498
Source avec Zip EXPORTATION DE FICHIER CSV VERS UNE TABLE SQLSERVER par imothepe_33

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture Source .NET (Dotnet) ORIONAPPLICATION par toutphp
Source avec Zip Source .NET (Dotnet) CRYSTALREPORT C# SQLSERVER par badis1996
Source avec Zip Source avec une capture Source .NET (Dotnet) SPLIT SQL SANS TABLE TEMPORAIRE par TheOnlyMaX
Source avec Zip Source avec une capture Source .NET (Dotnet) GENEREREQUÊTE par donald42
Source avec Zip Source .NET (Dotnet) EXPLORATEUR MYSQL par bikergete

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

SQL -> MySql.Data.MySqlClient [ par abdoulax ] J'utilise la librairie MySql.Data.MySqlClient cependant j'ai du mal &#224; l'utiliser comme je veux !! Est-ce que qlq1 connais un tuto probleme de requete sql [ par diamentelle ] salut a tous je suis entrain de creer une application avec .net j utilise c# comme language et mysql comme SGBD.je veux afficher dans un combobox tous Réplcation Base de données-Chaine ODBC(assez urgent) [ par bene86 ] Bonjour,   Mon problème concerne les bases de données mysql, mais aussi les base de donnée SQL Server, donc si vous pensez que j'ai placé mon sujet au Lister les parametres d'une procédure Stockée SQl server et MYSQL [ par Arthenius ] Salut tout le monde,bon je sais c'est une question que je devrai poser sur sqlfr.com, chose que j'ai déjà fait sans trop de succès...alors voila j'exp accès à une base SQL à travers intranet, problème de sécu? [ par feuillou ] Bonjour à tous,si l'un d'entre vous pouvait m'aider ce serait vraimment le bonheur!!Alors voilà, j'ai développé un logiciel de BdD sous Visual Studio sql express?? [ par Fildomen ] salutj'ai installer ce truc (sql express 2005 beta) sur mon windows xp pro sp2, mais je vois toujours pas qu'il a crée un serveur, ya seulement un tit Image dans Sql Server [ par 238723 ] Bonjour, j'ai un petit probleme dans sql server J'ai une colonne de type image dans une table et j'aimerai insérer une image dans chaque ligne de ma t Modification d'une base sql avec sql express [ par Fildomen ] sltje veux modifier le contenu de qlq tables de ma base, mais g rien trouver de ce genre dans sql express 2005, et même quand g installé son express m désinstallation des serveurs sql [ par Fildomen ] salutj'ai installé plusieurs sql server express, et chacun a ajouté un serveur dans mon pc, et quand j'ai tout désinstallé, les serveurs restent, et j base sql problème [ par Fildomen ] salut ( 4fois par jour!!)j'ai r&#233;installer le windows, et quand je veux attacher ma base de donn&#233;e sql server 2000, il me passe une erreur&nb


Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,030 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales