2 CopyStatement Testing.(field level and table level).
3 CREATE TABLE MASTER(f1 TINYINT ,f2 SMALLINT ,f3 INT ,f4 BIGINT ,f5 CHAR(20) ,f6 VARCHAR(30) ,f7 FLOAT ,f8 DOUBLE ,f9 DATE ,f10 TIME ,f11 TIMESTAMP);
4 CREATE TABLE COPYMASTER AS SELECT * FROM MASTER;
5 CREATE TABLE COPYMASTER_FIELDLEVEL AS SELECT f2,f5,f1,f9,f11,f10,f6,f4,f7,f3 FROM MASTER;
6 CREATE TABLE COPYMASTER_DUPLICATEFIELD AS SELECT f2,f5,f2 FROM MASTER; This should be failed
14 AbsSqlConnection
*con
= createConnection();
15 rv
= con
->connect("root","manager");
20 printf("Connection opened\n");
21 AbsSqlStatement
*stmt
= createStatement();
22 stmt
->setConnection(con
);
25 strcpy(statement
,"CREATE TABLE MASTER(f1 TINYINT ,f2 SMALLINT ,f3 INT ,f4 BIGINT ,f5 CHAR(20) ,f6 VARCHAR(30) ,f7 FLOAT ,f8 DOUBLE ,f9 DATE ,f10 TIME ,f11 TIMESTAMP);");
27 rv
= stmt
->prepare(statement
);
28 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 2; }
29 rv
= stmt
->execute(rows
);
30 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 3; }
31 printf("Table MASTER Created\n");
34 strcpy(statement
,"CREATE TABLE COPYMASTER AS SELECT * FROM MASTER;");
36 rv
= stmt
->prepare(statement
);
37 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 4; }
38 rv
= stmt
->execute(rows
);
39 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 5; }
40 printf("Table COPYMASTER Created\n");
43 strcpy(statement
,"CREATE TABLE COPYMASTER_FIELDLEVEL AS SELECT f2,f5,f1,f9,f11,f10,f6,f4,f7,f3 FROM MASTER;");
45 rv
= stmt
->prepare(statement
);
46 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 6; }
47 rv
= stmt
->execute(rows
);
48 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 7; }
49 printf("Table COPYMASTER_FIELDLEVEL Created\n");
52 strcpy(statement
,"CREATE TABLE COPYMASTER_DUPLICATEFIELD AS SELECT f2,f5,f2 FROM MASTER;");
54 rv
= stmt
->prepare(statement
);
55 if(rv
==OK
) { delete stmt
; con
->disconnect(); delete con
; return 8; }
56 printf("Table COPYMASTER_DUPLICATEFIELD can not be Created because of duplicate fields\n");
59 strcpy(statement
,"GETALLTABLES;");
61 rv
= stmt
->prepare(statement
);
62 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 9; }
64 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 10; }
65 printf("\t TABLES\n");
66 printf("\t--------\n");
67 while(stmt
->next() !=NULL
) {
68 printf("\t%s\n",stmt
->getFieldValuePtr(2)); //stmt->getFieldValuePtr(2) returns the TABLE_NAME (src/sql/SqlStatement.cxx)
73 rv
= stmt
->prepare("DROP TABLE MASTER;");
74 rv
= stmt
->execute(rows
);
75 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 11; }
76 printf("MASTER Table Dropped\n");
78 rv
= stmt
->prepare("DROP TABLE COPYMASTER;");
79 rv
= stmt
->execute(rows
);
80 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 12; }
81 printf("COPYMASTER Table Dropped\n");
83 rv
= stmt
->prepare("DROP TABLE COPYMASTER_FIELDLEVEL;");
84 rv
= stmt
->execute(rows
);
85 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 13; }
86 printf("COPYMASTER_FIELDLEVEL Table Dropped\n");
90 strcpy(statement
,"GETALLTABLES;");
92 rv
= stmt
->prepare(statement
);
93 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 14; }
95 if(rv
!=OK
) { delete stmt
; con
->disconnect(); delete con
; return 15; }
96 while(stmt
->next() !=NULL
) {
97 printf("Table Name is %s\n",stmt
->getFieldValuePtr(2)); //stmt->getFieldValuePtr(2) returns the TABLE_NAME (src/sql/SqlStatement.cxx)
102 printf("Connection Closed\n");
104 delete stmt
; delete con
;