- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Using SQL cursors in C program
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2005 03:15 AM
тАО08-26-2005 03:15 AM
I'm attempting to write some C applications to do basic queries of our ALLBASE/SQL database. I have two programs that make use of cursors to obtain and display multiple row results. On program works as expected while the other is unable to obtain a multiple row result set. The main difference between the two are their SQL cursor declarations.
Here's the "broken" one:
// SQL Cursor declarations
EXEC SQL DECLARE comp_ids_crs CURSOR FOR
SELECT COMPONENT_ID FROM REL_COMP_DETAIL
WHERE COMPONENT_NAME = :CompName
AND COMP_VERSION = :CompVer;
and the one that works:
// SQL Cursor declare
EXEC SQL DECLARE dest_ids_crs CURSOR FOR
SELECT DESTINATION_ID FROM COMP_DEST
WHERE COMPONENT_ID = :ComponentID;
Attached is the broken C source file. I would attach the working one, but can only attach one file to a post by the looks of things.
Any help would be greatly appreciated.
Solved! Go to Solution.
- Tags:
- SQL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2005 04:42 AM
тАО08-26-2005 04:42 AM
Re: Using SQL cursors in C program
it's not easy without database design help you. Statement seems to be right. May be a stupid question, but does exist some record with CompName and CompVer passed? Did you try direct sql command with console?
Antonio Vigliotti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2005 04:48 AM
тАО08-26-2005 04:48 AM
Re: Using SQL cursors in C program
CREATE TABLE Rel_Comp_Detail (
Component_ID INTEGER NOT NULL,
Component_Name CHAR(20),
Comp_Version CHAR(5),
When the broken SQL select statement is run via isql a multiple row result set is returned.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2005 05:39 AM
тАО08-26-2005 05:39 AM
SolutionThe query for 'ComponentID' is relatively easy because it is a simple integer.
But the Name/Ver query can have trouble with fill characters and null terminators.
I suggest you print those variables and their length just before the query and print them with some delimiter to make it clear where they end, much like how you print the result, but now before the query:
printf("CompName = '%s' %d\n", CompName, strlen(CompName));
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2005 06:04 AM
тАО08-26-2005 06:04 AM
Re: Using SQL cursors in C program
I thought that might be the problem too, but our C "experts" disagreed with me.
I ended up hard coding in the lenth of the strncat() call to populate CompName. I had previously been using sizeof() instead of strlen() to determine the length of the strncat() call.
$ ./getCompIDs.r -v GR423A30
RawInput = 'GR423A30' and is 8 bytes long
CompName = 'GR423' and is 5 bytes long
CompVer = 'A30' and is 3 bytes long
GR423A30 - 26888
GR423A30 - 26889
GR423A30 - 26897