bah....Avec MySQL (je sais pas si ça marche avec Oracle), on fait aussi un fichier de commandes MySQL.....(30 minutes après)
t'ain, tu m'en fais voir de belles!! D Je devrais pas répondre aux défis!! D
Si tu met ça dans un fichier (bash!!)
Citation :
#!/bin/sh
REQUEST=$@
TMP=/tmp/tmp_$$
echo "$REQUEST" > $TMP
echo "Target database : "
read TARGET
FIELDS=`mysql -u root < $TMP | head -1 | awk ' { cmd="("; for (i=1; i < NF; i++) {cmd=cmd $i ","} print(cmd $NF " )" ) }'`
AWKCMD="awk ' { cmd=\"insert into $TARGET $FIELDS values (\";
for (i=1; i< NF; i++) {
cmd=cmd \"\\\"\"\$i\"\\\"\,\"
}
print (cmd \"\\\"\"\$NF\"\\\" )\" ) }'"
mysql -u root < $TMP | tail | eval $AWKCMD
|
Avec une table qui a cette structure :
+---------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+------------------+------+-----+---------+-------+
| townId | varchar(30) | | PRI | | |
| day | int(10) unsigned | | PRI | 0 | |
| minTemp | int(10) unsigned | | | 0 | |
| maxTemp | int(10) unsigned | | | 0 | |
| icon | varchar(20) | | | | |
+---------+------------------+------+-----+---------+-------+
en lançant :
getDBvalues "select * from DBweather.Meteo limit 10"
et en mettant DBtoto quand on me pose une question, j'obtiens :
insert into DBtoto (townId,day,minTemp,maxTemp,icon) values ("54909","3","23","31","P3" )
insert into DBtoto (townId,day,minTemp,maxTemp,icon) values ("54909","2","22","30","P3" )
insert into DBtoto (townId,day,minTemp,maxTemp,icon) values ("54908","3","16","17","P7" )
insert into DBtoto (townId,day,minTemp,maxTemp,icon) values ("54909","1","21","30","P3" )
insert into DBtoto (townId,day,minTemp,maxTemp,icon) values ("54908","2","12","19","P7" )
insert into DBtoto (townId,day,minTemp,maxTemp,icon) values ("54907","3","18","21","P8" )
insert into DBtoto (townId,day,minTemp,maxTemp,icon) values ("54909","0","22","30","P3" )
insert into DBtoto (townId,day,minTemp,maxTemp,icon) values ("54908","1","13","23","P3" )
insert into DBtoto (townId,day,minTemp,maxTemp,icon) values ("54907","2","17","19","P8" )
insert into DBtoto (townId,day,minTemp,maxTemp,icon) values ("54906","3","13","21","P6" )
Donc, en faisant une redirection, plus de problème, t'as ton fichier de commande SQL...
Bon après, pâr contre....pour les autres SGBD, je garantis rien!
[jfdsdjhfuetppo]--Message édité par gfive le 30-05-2002 à 15:24:04--[/jfdsdjhfuetppo]