If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > structure host variables in Emb SQL ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-02-04, 07:18
TALK2RITESH TALK2RITESH is offline
Registered User
 
Join Date: Jun 2004
Posts: 1
Question structure host variables in Emb SQL ?

plz reply me ,I am not able to solve the problem,I want to know that how can I use a structure,a pointer to structure and passing arguments using host variables in c so that same variables could be used in SQL queries also....
Thanks in advance...
if u know abt any good link then also plz give the URL
RITESH

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sqlenv.h>
#include <sqlutil.h>
#define SQLDASIZE(n) (sizeof(struct sqlda) + (n-1) * sizeof(struct sqlvar))
#define TRUE 1
#define FALSE 0

EXEC SQL INCLUDE SQLCA;

int main()
{
int valid;
EXEC SQL BEGIN DECLARE SECTION ;
struct employee
{
short empno;
char name[15];
float sal;

}emp;
EXEC SQL END DECLARE SECTION ;
printf("IN THE MAIN\n");

printf("ENTER THE EMPNO :");
scanf("%d",&emp.empno);

printf("\nENTER THE NAME:");
scanf("%s",emp.name);

printf("\nENTER THE SAL :");
scanf("%f",&emp.sal);

EXEC SQL CONNECT TO sample USER udb USING tryudb;
printf("\nDATABASE CONNECTED\n");

valid = Called_Fun(emp);

printf("BACK IN THE MAIN\n");
return(1);
}
int Called_Fun( struct employee temp )
{
EXEC SQL BEGIN DECLARE SECTION ;
struct empolyee new;
EXEC SQL END DECLARE SECTION ;
new.empno = temp.empno;
strcpy(new.name,temp.name);
new.sal = temp.sal ;
printf("\nEMP ID %d :",new.empno);
printf("\nEMP NAME %s :",new.name);
printf("\nEMP SAL %f :",new.sal);
EXEC SQL INSERT INTO UDB.RIT_EMP VALUES(:new.empno,':new.name',:new.sal);
EXEC SQL COMMIT;
printf("RECORD NO INSERTED SUCCESSFULLY");
return(1);
}
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On