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.

0

1 Answer 1

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
 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.