2 // UPDATE WHERE EID = 1001, 1003, 1005
3 // seletct all rows from the table.
6 #include <AbsSqlStatement.h>
12 AbsSqlConnection
*con
= SqlFactory :: createConnection(CSql
);
13 rv
= con
->connect("root","manager");
16 AbsSqlStatement
*stmt
= SqlFactory :: createStatement(CSql
);
17 stmt
->setConnection(con
);
22 // UPDATE EMP WITH WHERE CLAUSE(EID<1006)
23 strcpy(statement
, "UPDATE EMP SET SALARY=?, ENAME=? WHERE EID=?;" );
24 rv
= stmt
->prepare(statement
);
25 if(rv
!= OK
) { delete stmt
; delete con
; return 3; }
30 strcpy(ename
, "Mani");
32 char *name
[20] = { "Ravi", "Kiran", "Ganesh", "Yogesh", "Vishnu" };
37 if (eid
> 1005) break;
38 strcpy(ename
, name
[i
]);
39 salary
= 1111.00 * (1 + i
);
40 rv
= con
->beginTrans();
41 stmt
->setFloatParam(1,salary
);
42 stmt
->setStringParam(2,ename
);
43 stmt
->setIntParam(3, eid
);
44 if(rv
!= OK
) { delete stmt
; delete con
; return 4; }
45 rv
= stmt
->execute(rows
);
47 if(rv
!= OK
) { delete stmt
; delete con
; return 5; }
52 //fetching the rows from EMP Table
53 strcpy(statement
, "SELECT * FROM EMP;");
54 rv
= stmt
->prepare(statement
);
55 if(rv
!= OK
) { delete stmt
; delete con
; return 6; }
59 stmt
->bindField(1, &eid
);
60 stmt
->bindField(2, ename
);
61 stmt
->bindField(3, &salary
);
63 printf("updated values are as follows\n");
64 printf("EmpId | name\t| salary\n");
65 printf("--------------------------\n");
67 rv
= con
->beginTrans();
68 if(rv
!= OK
) { delete stmt
; delete con
; return 6; }
70 while(stmt
->fetch() != NULL
)
71 printf("%d | %s\t| %6.2f\n", eid
, ename
, salary
);
73 if(rv
!= OK
) { delete stmt
; delete con
; return 7; }