1 /* create table T1 with two fields,
2 * insert 10 rows into the table ,
3 * select with nonexisting fields.
5 * Author : Jitendra Lenka
7 #include<SqlNwConnection.h>
8 #include<SqlNwStatement.h>
14 AbsSqlConnection
*con
= new SqlNwConnection();
15 con
->setInnerConnection(NULL
);
16 SqlNwConnection
*conn
= (SqlNwConnection
*)con
;
17 conn
->setHost("localhost", 5678);
18 rv
= con
->connect("root","manager");
21 AbsSqlStatement
*stmt
= new SqlNwStatement();
22 stmt
->setInnerStatement(NULL
);
23 stmt
->setConnection(con
);
26 strcpy(statement
,"CREATE TABLE T1(F1 INT,F2 INT);");
29 rv
= stmt
->prepare(statement
);
30 if(rv
!=OK
) { delete stmt
; delete con
; return 1; }
32 rv
= stmt
->execute(rows
);
33 if(rv
!=OK
) { delete stmt
; delete con
; return 2; }
34 printf("Table created\n");
38 strcpy(statement
,"INSERT INTO T1 VALUES(?,?);");
43 rv
= stmt
->prepare(statement
);
44 if(rv
!=OK
) { delete stmt
; delete con
; return 3; }
54 rv
= con
->beginTrans();
58 stmt
->setIntParam(1,f1var
);
59 stmt
->setIntParam(2,f2var
);
61 rv
= stmt
->execute(rows
);
67 printf("%d rows inserted\n",count
);
70 //*******************************************
72 strcpy(statement
,"SELECT F3 ,F2 FROM T1;");
73 rv
= stmt
->prepare(statement
);
76 printf("Test script passed\n");
77 strcpy(statement
,"DROP TABLE T1;");
78 rv
= stmt
->prepare(statement
);
79 if(rv
!=OK
)printf("Table drop prepare failed\n");
80 rv
= stmt
->execute(rows
);
81 if(rv
==OK
)printf("Table dropped\n");
88 printf("Test script failed\n");