Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with INFO sql statement

Status
Not open for further replies.

mbaranski

Programmer
Nov 3, 2000
421
US
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 &amp;&amp; KEEP_LOG)
cerr << &quot;Error preparing to get Column info, error # &quot; << SQLCODE << endl;

EXEC SQL DECLARE cursor CURSOR FOR SQLQueryStmt;

if(SQLCODE &amp;&amp; KEEP_LOG)
cerr << &quot;Error declaring cursor, error # &quot; << SQLCODE << endl;

EXEC SQL OPEN cursor;
if(SQLCODE &amp;&amp; KEEP_LOG)
cerr << &quot;Error opening cursor, error # &quot; << 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 &quot;value IS NOT&quot; instead of &quot;NOT value
IS&quot;), 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 &quot;SELECT * FROM badge&quot; it works fine. Why does the &quot;INFO COLUMNS FOR badge&quot; 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.
 
Sorry for my english.

First you must have the Administrator or Informix or Root privileges.
The information that you want, are stored in two tables:
systables and syscolumns.

The select format is:

SELECT a.* FROM syscolumns a, systables b
WHERE b.tabname=&quot;badge&quot; AND a.tabid = b.tabid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top