On 15/02/12 14:17, JOSEPH MARTIN MPALAKA wrote:
take an example of updating Bank Accounts, gaving the following table:acc_id acc_name standing_Balance mn0001 computer 20000
cur.execute("UPDATE accounts SET Standing_Amount =
(Standing_Amount + dep) WHERE Acc_ID = 'MN0001'")
Note that in programming consistency is critically important. In your table description you have standing_Balance. In your SQL query you have Standing_Amount Which is it? Also the ID is mn0001 and MN0001 which is it? You also use Acc_ID and acc_id but I believe SQL is universally case agnostic so you probably get away with that. But its better to be consistent. How to format the dep will depend on the data format of your database. If we assume it's an integer then you have several options:1) Calculate the total and insert it into the SQL statement (may require a select first to retrieve the current value)
2) Replace dep with the value using a MySql format operation. This allows you to validate the value before inserting it.
3) Replace dep with the input string as is (slightly harder to do validation)
There are probably more... -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
