Accueil > > > 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
Sources de la même categorie
Commentaires et avis
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 à 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éinstaller le windows, et quand je veux attacher ma base de donnée sql server 2000, il me passe une erreur&nb
|
Derniers Blogs
SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE !MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE ! par Vko
Hier durant une session dédiée aux Techdays 2012, j'ai eu le plaisir d'annoncer la sortie de la Béta 2 de Mishra Reader. C'est quoi ? Pour les utilisateurs, c'est une vraie expérience de lecture de flux RSS sur Windows. Rien à voir avec les produit...
Cliquez pour lire la suite de l'article par Vko
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|