#include #include #include
EXEC SQL INCLUDE sqlca; EXEC SQL INCLUDE oraca;
main( int argc, char *argv[] ) { EXEC SQL BEGIN DECLARE SECTION; VARCHAR vcBuffer[32];
int ID;
const char *dbname1 = "dbname1";
const char *dbname2 = "dbname2";
EXEC SQL END DECLARE SECTION;
/* Connect To Oracle Datebaase dbname1 */ if(OU_ConnectDatabase("weigw","weigw","orcl","dbname1") != 0) { printf("Connect Database failed!\n");
return -1;
}
/* Connect To Oracle Datebaase dbname2 */ if(OU_ConnectDatabase("weigw","weigw","orcl","dbname2") != 0) { printf("Connect Database dbname 2 failed!\n");
return -1;
}
ID = 0;
memset(vcBuffer.arr, 0x00, sizeof(vcBuffer.arr));
vcBuffer.len = 0;
EXEC SQL AT :dbname1 SELECT COUNT(*) INTO :ID FROM WEIGWTEST; ID += 1;
strncpy(vcBuffer.arr, "dbname1", sizeof(vcBuffer.arr) - 1);
vcBuffer.len = strlen(vcBuffer.arr);
EXEC SQL AT :dbname1 INSERT INTO WEIGWTEST VALUES(:ID, :vcBuffer);
EXEC SQL AT :dbname2 INSERT INTO WEIGWTEST VALUES(:ID, :vcBuffer);
EXEC SQL AT :dbname1 COMMIT;
EXEC SQL AT :dbname1 ROLLBACK;
EXEC SQL COMMIT WORK RELEASE;
return 0; }
/* ** ** 功能说明:连接数据库 ** 输入参数: ** 输入参数: ** 输出参数: ** 返回值说明:0-成功 其他-失败 */ int OU_ConnectDatabase( char *con_name, char *con_passwd, char *con_string, char *con_dbname
) { EXEC SQL BEGIN DECLARE SECTION; VARCHAR uid[20]; VARCHAR pwd[20]; VARCHAR sid[20]; VARCHAR dbname[20]; EXEC SQL END DECLARE SECTION;
memset(uid.arr, 0x00, sizeof(uid.arr));
uid.len = 0;
memset( pwd .arr, 0x00, sizeof( pwd .arr));
pwd .len = 0;
memset( sid .arr, 0x00, sizeof( sid .arr));
sid .len = 0;
memset( dbname .arr, 0x00, sizeof( dbname .arr));
dbname .len = 0;
strcpy(uid.arr,con_name); uid.len=strlen(uid.arr);
strcpy(pwd.arr,con_passwd); pwd.len=strlen(pwd.arr);
strcpy(sid.arr,con_string); sid.len=strlen(sid.arr);
strcpy(dbname.arr,con_dbname); dbname .len=strlen( dbname .arr);
EXEC SQL CONNECT :uid IDENTIFIED BY :pwd
AT :dbname USING :dbname;
return sqlca.sqlcode; } |