*** empty log message ***
[csql.git] / test / odbc / Metadata / metadata6nw.c
blobb7ae3ec8fbf968e89f346dbae1fe2fbc257ae74f
1 /* Use Connection String "DSN=mycsql;MODE=csql;SERVER=127.0.0.1;PORT=5678;" for Connect Data Source
2 * CREATE TABLE "T1" WITH 10 FIELDS.
3 SQLStatistics() Should return all Index information
5 */
7 #include<stdio.h>
8 #include<stdlib.h>
9 #include<sql.h>
10 #include<sqlext.h>
11 #include<string.h>
12 #include<CSql.h>
13 //*************************************************************************
14 // ERROR CHECK FUNCTION
15 inline void checkrc(int rc,int line)
17 if(rc)
19 printf("ERROR %d at line %d\n",rc,line);
20 exit(1);
24 //*************************************************************************
25 // FUNCTION FOR INSERTING ROWS IN IT.
27 int FetchTest(SQLHANDLE env, SQLHANDLE dbc, SQLHANDLE stmt,char *tablename)
29 int ret;
30 char f2[50]= "praba";
31 SWORD f1;
32 char f4[50]= "praba";
33 SWORD f3;
34 int f5;
35 char f6[50]= "praba";
37 ret = SQLStatistics(stmt, NULL, 0, NULL, SQL_NTS,
38 (SQLCHAR*) tablename, SQL_NTS, SQL_INDEX_ALL, SQL_QUICK);
40 checkrc(ret,__LINE__);
41 short totalFields=0;
42 ret = SQLNumResultCols (stmt, &totalFields);
43 checkrc(ret,__LINE__);
44 printf( "No of columns in resultset = %d\n",totalFields);
46 ret = SQLBindCol(stmt,4,SQL_C_SHORT,(void*)&f1,0,NULL);
47 checkrc(ret,__LINE__);
48 ret = SQLBindCol(stmt,6,SQL_C_CHAR,f2,sizeof(f2),NULL);
49 checkrc(ret,__LINE__);
50 ret = SQLBindCol(stmt,7,SQL_C_SHORT,(void *)&f3,0,NULL);
51 checkrc(ret,__LINE__);
52 ret = SQLBindCol(stmt,9,SQL_C_CHAR,f4,sizeof(f4),NULL);
53 checkrc(ret,__LINE__);
54 while(SQL_SUCCEEDED(ret = SQLFetch(stmt))){
55 printf(" Unique =%hd \tIndexName = %s \t Type=%hd ColumnName = %s \n ",f1,f2,f3,f4);
57 ret = SQLCloseCursor(stmt);
58 checkrc(ret,__LINE__);
60 ret = SQLTransact(env,dbc,SQL_COMMIT);
61 checkrc(ret,__LINE__);
62 return 0;
67 int main()
69 SQLHENV env;
70 SQLHDBC dbc;
71 SQLHSTMT stmt;
72 SQLRETURN ret;
73 SQLCHAR outstr[1024];
74 SQLSMALLINT outstrlen;
76 // Aloocate an environment handle
77 ret=SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&env);
78 checkrc(ret,__LINE__);
80 //we need odbc3 support
81 SQLSetEnvAttr(env,SQL_ATTR_ODBC_VERSION,(void*)SQL_OV_ODBC3,0);
83 //ALLOCATE A Connection handle
84 ret = SQLAllocHandle(SQL_HANDLE_DBC,env,&dbc);
85 checkrc(ret,__LINE__);
87 // connect to the DSN mydsn
88 ret = SQLConnect (dbc,
89 (SQLCHAR *) "DSN=mycsql;MODE=csql;SERVER=127.0.0.1;PORT=5678;", (SQLSMALLINT) strlen ("DSN=mycsql;MODE=csql;SERVER=127.0.0.1;PORT=5678;"),
90 (SQLCHAR *) "root",
91 (SQLSMALLINT) strlen ("root"),
92 (SQLCHAR *) "manager",
93 (SQLSMALLINT) strlen (""));
96 if(SQL_SUCCEEDED(ret))
98 printf("\nConnected to the Data Source..\n");
103 else
105 printf("error in conenction\n");
107 ret = SQLFreeHandle(SQL_HANDLE_DBC,dbc);
108 checkrc(ret,__LINE__);
110 ret = SQLFreeHandle(SQL_HANDLE_ENV,env);
111 checkrc(ret,__LINE__);
112 return 1;
116 //*****************************************************
117 // TABLE CREATED
118 ret = SQLAllocHandle(SQL_HANDLE_STMT,dbc,&stmt);
119 checkrc(ret,__LINE__);
121 SQLCHAR table[200]=
122 "CREATE TABLE T1(F1 INT,F2 SMALLINT,F3 CHAR(30),F4 FLOAT,F5 FLOAT,F6 DATE,F7 TIME,F8 TIMESTAMP,F9 TINYINT,F10 BIGINT, PRIMARY KEY(F2));";
124 ret = SQLPrepare(stmt,table,SQL_NTS);
125 checkrc(ret,__LINE__);
126 ret = SQLExecute(stmt);
127 checkrc(ret,__LINE__);
128 ret = SQLPrepare(stmt,(SQLCHAR *)"CREATE INDEX INDS ON T1(F3) TREE;",SQL_NTS);
129 checkrc(ret,__LINE__);
130 ret = SQLExecute(stmt);
131 checkrc(ret,__LINE__);
133 printf("\nTABLE CREATED\n");
134 //***************************
135 FetchTest(env,dbc,stmt,"T1");
136 //**************************************************
137 SQLCHAR drop[100]="DROP TABLE T1";
138 ret = SQLPrepare(stmt,drop,SQL_NTS);
139 checkrc(ret,__LINE__);
140 ret = SQLExecute(stmt);
141 if(ret!=SQL_SUCCESS && ret !=SQL_SUCCESS_WITH_INFO)
143 printf("Statement failed\n");
144 return 1;
148 printf("Tables dropped successfully\n");
150 ret = SQLFreeHandle(SQL_HANDLE_STMT,stmt);
151 checkrc(ret,__LINE__);
153 ret = SQLDisconnect(dbc);
154 checkrc(ret,__LINE__);
156 ret = SQLFreeHandle(SQL_HANDLE_DBC,dbc);
157 checkrc(ret,__LINE__);
159 ret = SQLFreeHandle(SQL_HANDLE_ENV,env);
160 checkrc(ret,__LINE__);
161 return 0;