mspadaru

CodeForce QtSql 4

Aug 19th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. def insert(db):
  2.  
  3.     query = QtSql.QSqlQuery()
  4.  
  5.     sql = """INSERT INTO EMPLOYEE(FIRST_NAME,
  6.  
  7.             LAST_NAME, AGE, SEX, INCOME)
  8.  
  9.             VALUES ('Mac', 'Mohan', 20, 'M', 2000)"""
  10.  
  11.     try:
  12.  
  13.         query.exec_(sql)
  14.  
  15.         db.commit()
  16.  
  17.     except:
  18.  
  19.         # Rollback in case there is any error
  20.  
  21.         db.rollback()  
  22.  
  23. def update(db):
  24.  
  25.     query = QtSql.QSqlQuery()
  26.  
  27.     sql = "UPDATE EMPLOYEE SET AGE = AGE + 1 \
  28.  
  29.                              WHERE SEX = '%c'" % ('M')
  30.  
  31.     try:
  32.  
  33.         query.exec_(sql)
  34.  
  35.         db.commit()
  36.  
  37.     except:
  38.  
  39.         # Rollback in case there is any error
  40.  
  41.         db.rollback()
  42.  
  43.    
  44.  
  45. def delete(db):
  46.  
  47.     query = QtSql.QSqlQuery()
  48.  
  49.     sql = "DELETE FROM EMPLOYEE WHERE AGE > '%d'" % (20)
  50.  
  51.     try:
  52.  
  53.         query.exec_(sql)
  54.  
  55.         db.commit()
  56.  
  57.     except:
  58.  
  59.         # Rollback in case there is any error
  60.  
  61.         db.rollback()
Advertisement
Add Comment
Please, Sign In to add comment