0

i want a unix script that will show the number of rows updated after an update command in the script...some one please help.. i am using mysql version---4.1.x

The Script should take the update the table and then return "successfull" if the number of rows changed is 1 or more than that.

user3747182
  • 361
  • 2
  • 4
  • 10

1 Answers1

0

Do you mean something like this...?
Change HOST, USER_NAME, USER_PWD, DB_NAME, SQL_SLT, SQL_TABLE to your setting
and try this, it would echo the update row count.

 
    #!/bin/sh

    # database parameters
    HOST="localhost"
    USER_NAME="db_user_name"
    USER_PWD="db_user_pwd"
    DB_NAME="database"

    # query SQL parameters
    SQL_SLT="SET \`group\` = '8' WHERE \`devName\` = 'IPR1'"
    SQL_TABLE="\`devInfos\`"

    # connect db
    db_conn="mysql -h $HOST -u $USER_NAME --password=$USER_PWD --database=$DB_NAME"
    sql="UPDATE $SQL_TABLE $SQL_SLT; SELECT ROW_COUNT();";

    echo $sql | $db_conn | while read row ;
    do
        echo $row
    done
 
TCHsu
  • 11
  • 3