Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/mridoni/gixsql
Browse files Browse the repository at this point in the history
  • Loading branch information
mridoni committed Sep 9, 2023
2 parents cc826ed + 7c8f0e2 commit f26e70d
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 106 deletions.
137 changes: 68 additions & 69 deletions libgixpp/gix_esql_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,13 @@ cb_field_ptr gix_esql_driver::cb_build_field_tree(int level, std::string name, c
f->level != 77 && f->level != 66 && f->level != 88) {
return NULL;
}
} else {
if (f->level != 1 && f->level != 77) {
fprintf(stderr, "parse error: %s level should start from 01 or 66 or 77 or 88\n", name.c_str());
//exit(-1);
return NULL;
}

}

if (f->level == 1 || f->level == 77) {
Expand All @@ -488,84 +495,74 @@ cb_field_ptr gix_esql_driver::cb_build_field_tree(int level, std::string name, c
cb_field_founder(last_field)->sister = f;
}
}
else {
if (last_field == NULL) {
fprintf(stderr, "parse error: %s level should start from 01 or 66 or 77 or 88\n", name.c_str());
//exit(-1);
return NULL;
else if (f->level == 66) {
/* level 66 */
f->parent = cb_field_founder(last_field);
for (p = f->parent->children; p && p->sister; p = p->sister);
if (p) {
p->sister = f;
}

if (f->level == 66) {
/* level 66 */
f->parent = cb_field_founder(last_field);
for (p = f->parent->children; p && p->sister; p = p->sister);
if (p) {
p->sister = f;
}
else if (f->level == 88) {
/* level 88 */
f->parent = last_field;
}
else if (f->level > last_field->level) {
/* lower level */
last_field->children = f;
f->parent = last_field;
}
else if (f->level == last_field->level) {
/* same level */
same_level:
last_field->sister = f;
f->parent = last_field->parent;
}
else {
/* upper level */
for (p = last_field->parent; p; p = p->parent) {
if (p->level == f->level) {
last_field = p;
goto same_level;
}
}
else if (f->level == 88) {
/* level 88 */
f->parent = last_field;
}
else if (f->level > last_field->level) {
/* lower level */
last_field->children = f;
f->parent = last_field;
}
else if (f->level == last_field->level) {
/* same level */
same_level:
last_field->sister = f;
f->parent = last_field->parent;
}
else {
/* upper level */
for (p = last_field->parent; p; p = p->parent) {
if (p->level == f->level) {
last_field = p;
goto same_level;
}
if (p->level < f->level) {
break;
}
if (p->level < f->level) {
break;
}
return NULL;
}
return NULL;
}

if (f) {
std::string path = f->sname;
cb_field_ptr p = f;
while (p->parent) {
path = p->parent->sname + ":" + path;
p = p->parent;
}
std::string path = f->sname;
cb_field_ptr p = f;
while (p->parent) {
path = p->parent->sname + ":" + path;
p = p->parent;
}

switch (this->data_division_section) {
case DD_SECTION_WS:
f->path = "WS:" + path;
f->data_section = DataSectionType::WorkingStorage;
break;
switch (this->data_division_section) {
case DD_SECTION_WS:
f->path = "WS:" + path;
f->data_section = DataSectionType::WorkingStorage;
break;

case DD_SECTION_LS:
f->path = "LS:" + path;
f->data_section = DataSectionType::LinkageSection;
break;
case DD_SECTION_LS:
f->path = "LS:" + path;
f->data_section = DataSectionType::LinkageSection;
break;

case DD_SECTION_LL:
f->path = "LL:" + path;
f->data_section = DataSectionType::LocalStorage;
break;
case DD_SECTION_LL:
f->path = "LL:" + path;
f->data_section = DataSectionType::LocalStorage;
break;


case DD_SECTION_FS:
f->path = "FS:" + path;
f->data_section = DataSectionType::FileSection;
break;
case DD_SECTION_FS:
f->path = "FS:" + path;
f->data_section = DataSectionType::FileSection;
break;

}
parser_data()->add_to_field_map(f->sname, f);
}
parser_data()->add_to_field_map(f->sname, f);

f->defined_at_source_line = lexer.getLineNo();
f->defined_at_source_file = lexer.driver->file;
Expand All @@ -575,6 +572,12 @@ cb_field_ptr gix_esql_driver::cb_build_field_tree(int level, std::string name, c

int gix_esql_driver::build_picture(const std::string str, cb_field_ptr pic)
{
if (pic == NULL || str.length() > 50) {
/* arbitrary limit; note on implementation limits: COBOL85 (30),
COBOL2002 and most others (50), COBOL2014 (63), GC (255) */
return 0;
}

const char *p = str.c_str();

int i;
Expand All @@ -589,10 +592,6 @@ int gix_esql_driver::build_picture(const std::string str, cb_field_ptr pic)
int scale = 0;
int allocated = 0;

if (str.length() > 50) {
return 0;
}

for (; *p; p++) {
n = 1;
c = *p;
Expand Down
12 changes: 12 additions & 0 deletions libgixpp/gix_esql_parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ static std::string to_std_string(connect_to_info_t *i) { if (i) { char buffer [3
%token COMP_5 "COMP-5"
%token COMP
%token<uint64_t> CHAR
%token<uint64_t> CHARF
%token<uint64_t> VARCHAR
%token<uint64_t> VARCHAR2
%token<uint64_t> BINARY
%token<uint64_t> VARBINARY
%token<uint64_t> FLOAT
Expand Down Expand Up @@ -494,6 +496,10 @@ DECLARE_VAR TOKEN IS sql_type END_EXEC {
driver->parser_data()->exec_list()->push_back(stmt);
}
}
| DECLARE_VAR error END_EXEC
{
yyerrok;
}
;

dbid: strliteral_or_hostref { $$ = $1; }
Expand Down Expand Up @@ -914,7 +920,13 @@ sql_type:
BINARY { $$ = (TYPE_SQL_BINARY << 60) + $1; }
| VARBINARY { $$ = (TYPE_SQL_VARBINARY << 60) + $1; }
| CHAR { $$ = (TYPE_SQL_CHAR << 60) + $1; }
| CHARF { $$ = (TYPE_SQL_CHAR << 60) + $1;
driver->warning(@$, "Unsupported SQL TYPE, will handle CHARF as CHAR.");
}
| VARCHAR { $$ = (TYPE_SQL_VARCHAR << 60) + $1; }
| VARCHAR2{ $$ = (TYPE_SQL_VARCHAR << 60) + $1;
driver->warning(@$, "Unsupported SQL TYPE, will handle VARCHAR2 as VARCHAR.");
}
| INTEGER { $$ = (TYPE_SQL_INT << 60) + $1; }
| FLOAT { $$ = (TYPE_SQL_FLOAT << 60) + $1; }
| DECIMAL { $$ = (TYPE_SQL_DECIMAL << 60) + $1; }
Expand Down
4 changes: 2 additions & 2 deletions runtime/libgixsql-pgsql/DbInterfacePGSQL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class pgsqlParamArray {
if (_data) {
for (int i = 0; i < nitems; i++) {
if (_data[i])
delete _data[i];
delete[] _data[i];
}
delete[] _data;
}
Expand Down Expand Up @@ -1047,4 +1047,4 @@ bool DbInterfacePGSQL::retrieve_prepared_statement_source(const std::string& pre
}

return false;
}
}
51 changes: 16 additions & 35 deletions runtime/libgixsql/SqlVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,29 +175,19 @@ void SqlVar::createRealData()
dlength = ceil(((double)length + 1) / 2);
skip_first = (length + 1) % 2; // 1 -> skip first 4 bits

int i;
int index = 0;
char* ptr;
unsigned char tmp;
unsigned char ubit = 0xF0;
unsigned char lbit = 0x0F;
const unsigned char ubit = 0xF0;
const unsigned char lbit = 0x0F;

for (i = 0; i < (int)dlength; i++) {
for (int i = 0; i < (int)dlength; i++) {

ptr = ((char*)addr) + i * sizeof(char);
tmp = (unsigned char)*ptr;
unsigned char *ptr = (unsigned char *)addr + i * sizeof(char);

if (i != 0 || !skip_first) {
//sprintf(val, "%d", (tmp & ubit) >> 4);
unsigned char c = ((tmp & ubit) >> 4) + ASCII_ZERO;
db_data_buffer[index] = c;
index++;
db_data_buffer[index++] = ASCII_ZERO + ((*ptr & ubit) >> 4);
}
if (i != dlength - 1) {
//sprintf(val, "%d", tmp & lbit);
unsigned char c = (tmp & lbit) + ASCII_ZERO;
db_data_buffer[index] = c;
index++;
db_data_buffer[index++] = ASCII_ZERO + (*ptr & lbit);
}
}

Expand All @@ -217,36 +207,27 @@ void SqlVar::createRealData()
skip_first = (length + 1) % 2; // 1 -> skip first 4 bits

/* set real data */
int i;
int index = SIGN_LENGTH;
char* ptr;
unsigned char tmp;
unsigned char ubit = 0xF0;
unsigned char lbit = 0x0F;
const unsigned char ubit = 0xF0;
const unsigned char lbit = 0x0F;

for (i = 0; i < (int)dlength; i++) {
for (int i = 0; i < (int)dlength; i++) {

ptr = ((char*)addr) + i * sizeof(char);
tmp = (unsigned char)*ptr;
unsigned char *ptr = (unsigned char *)addr + i * sizeof(char);

if (i != 0 || !skip_first) {
//sprintf(val, "%d", (tmp & ubit) >> 4);
unsigned char c = ((tmp & ubit) >> 4) + 48;
db_data_buffer[index] = c;
index++;
db_data_buffer[index++] = ASCII_ZERO + ((*ptr & ubit) >> 4);
}
if (i != dlength - 1) {
//sprintf(val, "%d", tmp & lbit);
unsigned char c = (tmp & lbit) + 48;
db_data_buffer[index] = c;
index++;
db_data_buffer[index++] = ASCII_ZERO + (*ptr & lbit);
}
else {
if ((tmp & lbit) == 0x0C) {
db_data_buffer[0] = '+';
if ((tmp & lbit) == 0x0D) {
db_data_buffer[0] = '-';
}
else {
db_data_buffer[0] = '-';
// expected 0x0C, but -std=ibm may lead to 0x0F (and Pro*COB handles that as positive, too)
db_data_buffer[0] = '+';
}
}
}
Expand Down

0 comments on commit f26e70d

Please sign in to comment.