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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I update a single byte within a field using an embedded sql.

Status
Not open for further replies.

davcomp

Programmer
Sep 25, 2001
3
US
I am trying to change a single byte(pos.59) within a 100 byte field(group_formactions). The following code produces an error when it is compiled. I know the syntax is not right on the lines within the sql portion where I am trying to do the update. How can I fix it? Thanks in advance!!

#pragma symbols
#pragma inspect
#pragma sql

#include <stdio.h> nolist
#include <string.h> nolist
#include &quot;=cshellh&quot; nolist
#include &quot;ossf089.h&quot;
#include &quot;=ossclib( srv , oss_req_089 , oss_msg_089 )&quot;
static oss_msg_089_def msg;

short ossf089(char* request, char* response, short * reply_err)
{

exec sql begin declare section;
short sqlcode;
exec sql invoke =SECGROUP as secgroup_struct;
struct secgroup_struct hSecGroup;
exec sql invoke =TRANGRP as trangrp_struct;
struct trangrp_struct hTranGrp;
exec sql end declare section;

memcpy(&msg.srv, request, sizeof( msg.srv ));

memcpy(&msg.oss_req_089, &request[sizeof(msg.srv)], sizeof(msg.oss_req_089));

msg.srv.row_count = 0;

memcpy(hSecGroup.group_id,
msg.oss_req_089.group_id,
sizeof(msg.oss_req_089.group_id));
hSecGroup.group_id[sizeof(hSecGroup.group_id)-1] = NULL;

exec sql declare F089_cursor cursor for
select * from =TRANGRP
where group_id = :hSecGroup.group_id
and transaction_group = 8
browse access;

if (!sqlcode)
{
exec sql update =SECGROUP
set group_formactions[59] = '1'
where group_id = :hSecGroup.group_id;

if (!sqlcode)
{
msg.srv.row_count++;
}
else
{
msg.srv.tmf_abort_flag = TRUE;
fprintf(stderr, &quot;Error Updating Security Group Information: OSSF089\n&quot;);
fprintf(stderr, &quot;SQL code(%d)\n&quot;,sqlcode);
}
}
else
{
exec sql update =SECGROUP
set group_formactions[59] = '0'
where group_id = :hSecGroup.group_id;

if (!sqlcode)
{
msg.srv.row_count++;
}
else
{
msg.srv.tmf_abort_flag = TRUE;
fprintf(stderr, &quot;Error Updating Security Group Information: OSSF089\n&quot;);
fprintf(stderr, &quot;SQL code(%d)\n&quot;,sqlcode);
}
}

exec sql free resources;
memcpy(response, &msg, sizeof(msg) );
return (sizeof(msg));

} /* end ossf089 */
 
well... the easiest thing to do would be to make a struct with bitfields and set the byte there. However, you do need to make sure you know what type of ENDIANISM you have on the machine

// Little Endian

struct BITS
{
unsigned bit99: 1;
unsigned bit98: 1;
...
unsigned bit1: 1;
unsigned bit0: 1;
};

// Big Endian

struct BITS
{
unsigned bit0: 1;
unsigned bit1: 1;
...
unsigned bit98: 1;
unsigned bit99: 1;
};

Now you can just memcpy into a BITS struct and set the bit

Matt
 
what does pragma directive do?

#pragma symbols
#pragma inspect
#pragma sql


Please explain in detail.

Regards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top