Question : Execute command for each record in a mysql table using a Window's batch file

Hello,

I have a remote mysql table I am using as a queue.

Using a Windows batch file I need to:

1) cycle through each record of the table and execute a command using the field values from each record. (eg. command.cmd feild1 feid2)
2) delete the row after the command is executed

It would be awesome if you can post the code to do this.

Thank you!

Drew

Answer : Execute command for each record in a mysql table using a Window's batch file

I would not use a windows batch file, but a vbscript (much easier to handle that kind of stuff),
you can of course prefer perl or any other similar scripting language.
vbscript has the main advantage that it shall run on any windows platform without additional installation,
while perl has the main advantage that apart from the file operations, the code should be portable to other platforms...

now, what do you know already?
* vbscript in general (resp the language you want to choose)
* connection parameters to mysql
* running sql statements

with vbscript

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
'create and open database connection
Dim c 
set c = CreateObject("ADODB.Connection")
c.Open "connection string goes here"
 
'prepare shell object to run command statements
Dim objShell
Set objShell = CreateObject("WScript.Shell")  
 
 
dim r 
set r = c.Open("select col1, col2, col3 ... from yourtable ")
while not r.eof
  Dim strCol1 
  Dim intCol2
  Dim datCol3
  'get the field values
  strCol1 = r.Fields("Col1").value
  intCol1 = r.Fields("col2").value
  datCol1 = r.Fields("col3").value
 
  'here shall come the code to run the command you need ...
  objShell.Run("your command goes here")
  
  ' get to the next record, if any 
  r.movenext
wend
r.close
c.close
Open in New Window Select All
Random Solutions  
 
programming4us programming4us