I have written the following c++ function:
/*
@ ---------------------------------------------
@ int importTable::getTableStructureFromInformix();
@ Uses the INFO query to get the column names
@ of the table, and puts them into the tables
@ deque for the object.
@ Returns the number of columns in the table.
@ ---------------------------------------------
*/
int importTable::getTableStructureFromInformix(){
EXEC SQL BEGIN DECLARE SECTION;
char tableName[6] = {"badge"};
char sql[4096] = {'\0'};
char colName[50] = {'\0'};
char colType[50] = {'\0'};
char colNull[50] = {'\0'};
EXEC SQL END DECLARE SECTION;
// tableName = "badge"; May not need this
sprintf(sql, "INFO COLUMNS FOR %s", tableName);
cout << sql << endl;
EXEC SQL PREPARE SQLQueryStmt FROM :sql;
if(SQLCODE && KEEP_LOG)
cerr << "Error preparing to get Column info, error # " << SQLCODE << endl;
EXEC SQL DECLARE cursor CURSOR FOR SQLQueryStmt;
if(SQLCODE && KEEP_LOG)
cerr << "Error declaring cursor, error # " << SQLCODE << endl;
EXEC SQL OPEN cursor;
if(SQLCODE && KEEP_LOG)
cerr << "Error opening cursor, error # " << SQLCODE << endl;
while(SQLCODE == 0){
EXEC SQL FETCH cursor INTO :colName, :colType, :colNull;
cerr << colName << endl;
}
EXEC SQL CLOSE cursor;
EXEC SQL FREE cursor;
EXEC SQL FREE SQLProxUpdStmt;
return 0;
}
and for some reason, after connecting to the database, I get error 201 from this:
-201 A syntax error has occurred.
This general error message indicates mistakes in the form of an SQL
statement. Look for missing or extra punctuation (such as missing or
extra commas, omission of parentheses around a subquery, and so on),
keywords misspelled (such as VALEUS for VALUES), keywords misused (such
as SET in an INSERT statement or INTO in a subquery), keywords out of
sequence (such as a condition of "value IS NOT" instead of "NOT value
IS", or a reserved word used as an identifier.
Database servers that provide full NIST compliance do not reserve any
words; queries that work with these database servers might fail and
return error -201 when they are used with earlier versions of Informix
database servers.
The cause of this error might be an attempt to use round-robin syntax with
CREATE INDEX or ALTER FRAGMENT INIT on an index. You cannot use round-robin
indexes.
[mike@sam cimport]$
If I change this to a select statement, such as "SELECT * FROM badge" it works fine. Why does the "INFO COLUMNS FOR badge" not work?
I am using csdk -v: 2.40.UC1
on informix server v.9 on AIX v4.
The client program is on a linux machine.
As I said, I can connect and run select statements fine, but I can't use INFO. If this is not the way to do it, how do I get the column information from a table?
Thanks
Mike Baranski
--
*********************************
Mike W. Baranski
mike@secmgmt.com
info@secmgmt.com
Web : Phone: 919-788-9200
Fax : 919-510-0037
P.O. box 30099
Raleigh, N.C. USA 27622
*********************************
As always, I hope that helped!
Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
/*
@ ---------------------------------------------
@ int importTable::getTableStructureFromInformix();
@ Uses the INFO query to get the column names
@ of the table, and puts them into the tables
@ deque for the object.
@ Returns the number of columns in the table.
@ ---------------------------------------------
*/
int importTable::getTableStructureFromInformix(){
EXEC SQL BEGIN DECLARE SECTION;
char tableName[6] = {"badge"};
char sql[4096] = {'\0'};
char colName[50] = {'\0'};
char colType[50] = {'\0'};
char colNull[50] = {'\0'};
EXEC SQL END DECLARE SECTION;
// tableName = "badge"; May not need this
sprintf(sql, "INFO COLUMNS FOR %s", tableName);
cout << sql << endl;
EXEC SQL PREPARE SQLQueryStmt FROM :sql;
if(SQLCODE && KEEP_LOG)
cerr << "Error preparing to get Column info, error # " << SQLCODE << endl;
EXEC SQL DECLARE cursor CURSOR FOR SQLQueryStmt;
if(SQLCODE && KEEP_LOG)
cerr << "Error declaring cursor, error # " << SQLCODE << endl;
EXEC SQL OPEN cursor;
if(SQLCODE && KEEP_LOG)
cerr << "Error opening cursor, error # " << SQLCODE << endl;
while(SQLCODE == 0){
EXEC SQL FETCH cursor INTO :colName, :colType, :colNull;
cerr << colName << endl;
}
EXEC SQL CLOSE cursor;
EXEC SQL FREE cursor;
EXEC SQL FREE SQLProxUpdStmt;
return 0;
}
and for some reason, after connecting to the database, I get error 201 from this:
-201 A syntax error has occurred.
This general error message indicates mistakes in the form of an SQL
statement. Look for missing or extra punctuation (such as missing or
extra commas, omission of parentheses around a subquery, and so on),
keywords misspelled (such as VALEUS for VALUES), keywords misused (such
as SET in an INSERT statement or INTO in a subquery), keywords out of
sequence (such as a condition of "value IS NOT" instead of "NOT value
IS", or a reserved word used as an identifier.
Database servers that provide full NIST compliance do not reserve any
words; queries that work with these database servers might fail and
return error -201 when they are used with earlier versions of Informix
database servers.
The cause of this error might be an attempt to use round-robin syntax with
CREATE INDEX or ALTER FRAGMENT INIT on an index. You cannot use round-robin
indexes.
[mike@sam cimport]$
If I change this to a select statement, such as "SELECT * FROM badge" it works fine. Why does the "INFO COLUMNS FOR badge" not work?
I am using csdk -v: 2.40.UC1
on informix server v.9 on AIX v4.
The client program is on a linux machine.
As I said, I can connect and run select statements fine, but I can't use INFO. If this is not the way to do it, how do I get the column information from a table?
Thanks
Mike Baranski
--
*********************************
Mike W. Baranski
mike@secmgmt.com
info@secmgmt.com
Web : Phone: 919-788-9200
Fax : 919-510-0037
P.O. box 30099
Raleigh, N.C. USA 27622
*********************************
As always, I hope that helped!
Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.