~replatformtech/+junk/esql

« back to all changes in this revision

Viewing changes to esqlOC/esqlOC.cpp

  • Committer: Jim Popovitch
  • Date: 2024-05-19 01:43:20 UTC
  • Revision ID: jim.popovitch@replatformtech.com-20240519014320-c5ht3s1c6rs0dh0j
Upstream changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2006-2021 Sergey Kashyrin <ska@kiska.net>
 
2
 * Copyright (C) 2006-2024 Sergey Kashyrin <ska@kiska.net>
3
3
 *               2012 enhanced by Doug Vogel <dv11674@gmail.com>
4
4
 *               2013 fixes and enhancements by Atilla Akarsular <030ati@gmail.com>
5
5
 *               2021 mf-compat by Simon Sobisch <simonsobisch@gnu.org>
40
40
 
41
41
#include "vcache.h"
42
42
 
43
 
static const char HEADER[] = "%s: ESQL for GnuCOBOL/OpenCOBOL Version 3 (2022.01.15) Build " __DATE__ "\n";
 
43
static const char HEADER[] = "%s: ESQL for GnuCOBOL/OpenCOBOL Version 3 (2024.04.30) Build " __DATE__ "\n";
44
44
/**  Version is present in SQLCA. Current is 03 */
45
45
 
46
46
static bool bAPOST = true;              // use apostroph instead of quote
47
47
static char Q = '\'';
48
48
static const char * sQ = "'";
49
49
static bool bStatic = false;    // static call
 
50
static bool bSplit = false;
50
51
static const char * sSQ = "";
51
52
static bool bForceUnknown = false;      // force unknown statements to be EXECUTE IMMEDIATE
52
53
static string W_ERR("");        // WHENEVER SQLERROR
926
927
                        addln(lineno++, buf);
927
928
                        sprintf(buf, "           05 SQL-STMLEN PIC S9(4) COMP-5 VALUE %d.", sql.length());
928
929
                        addln(lineno++, buf);
929
 
                        string fl("           05 SQL-STMT   PIC X(");
930
 
                        fl += sql.length();
931
 
                        fl += ") VALUE ";
932
 
                        fl += Q;
933
 
                        for(int k = 0; k < sql.length(); ++k) {
934
 
                                if(sql[k] == Q) {
935
 
                                        sql = sql.substr(0, k) + Q + sql.substr(k);
936
 
                                        ++k;
937
 
                                }
 
930
                        if(bSplit && sql.length() > 160) {
 
931
                                string fl("           05 SQL-STMT   PIC X(");
 
932
                                bool bProcess = true;
 
933
                                while(bProcess) {
 
934
                                        string sql1;
 
935
                                        if(sql.length() > 160) {
 
936
                                                sql1 = sql.substr(0, 160);
 
937
                                                sql = sql.substr(160);
 
938
                                        } else {
 
939
                                                sql1 = sql;
 
940
                                                bProcess = false;
 
941
                                        }
 
942
                                        fl += sql1.length();
 
943
                                        fl += ") VALUE ";
 
944
                                        fl += Q;
 
945
                                        for(int k = 0; k < sql1.length(); ++k) {
 
946
                                                if(sql1[k] == Q) {
 
947
                                                        sql1 = sql1.substr(0, k) + Q + sql1.substr(k);
 
948
                                                        ++k;
 
949
                                                }
 
950
                                        }
 
951
                                        fl += sql1;
 
952
                                        fl += Q;
 
953
                                        fl += '.';
 
954
                                        processfmt(lineno, fl);
 
955
                                        fl = "           05 FILLER     PIC X(";
 
956
                                }
 
957
                        } else {
 
958
                                string fl("           05 SQL-STMT   PIC X(");
 
959
                                fl += sql.length();
 
960
                                fl += ") VALUE ";
 
961
                                fl += Q;
 
962
                                for(int k = 0; k < sql.length(); ++k) {
 
963
                                        if(sql[k] == Q) {
 
964
                                                sql = sql.substr(0, k) + Q + sql.substr(k);
 
965
                                                ++k;
 
966
                                        }
 
967
                                }
 
968
                                fl += sql;
 
969
                                fl += Q;
 
970
                                fl += '.';
 
971
                                processfmt(lineno, fl);
938
972
                        }
939
 
                        fl += sql;
940
 
                        fl += Q;
941
 
                        fl += '.';
942
 
                        processfmt(lineno, fl);
943
973
                        if(cname.length() != 0) {
944
974
                                sprintf(buf, "           05 SQL-CNAME  PIC X(%d) VALUE %c%s%c.", cname.length(), Q, (const char*)cname, Q);
945
975
                                cname = buf;
3027
3057
 
3028
3058
static int nstart;
3029
3059
static void usage(char * pg) {
3030
 
        fprintf(stderr, "Usage: %s [-Q] [-F] [-static] [-I <copybook-directory> [| -I <copybook-directory>]] [-o <output-file>] <filename> ...\n", pg);
 
3060
        fprintf(stderr, "Usage: %s [-Q] [-F] [-S] [-static] [-I <copybook-directory> [| -I <copybook-directory>]] [-o <output-file>] <filename> ...\n", pg);
3031
3061
        fprintf(stderr, "       -Q        Use double quotes\n");
3032
3062
        fprintf(stderr, "       -F        Force unknown SQL statements to be accepted as \"execute immediate\"\n");
 
3063
        fprintf(stderr, "       -S        Split long alphanumeric into 160-bytes chunks\n");
3033
3064
        fprintf(stderr, "       -static   Use static calls to OCSQL library\n");
3034
3065
}
3035
3066
 
3091
3122
                        bForceUnknown = true;
3092
3123
                        continue;
3093
3124
                }
 
3125
                if(0 == strcmp(args[nstart], "-S")) {
 
3126
                        bSplit = true;
 
3127
                        continue;
 
3128
                }
3094
3129
                if(0 == strcmp(args[nstart], "-free")) {
3095
3130
                        fprintf(stderr, "%s: Free format is not implemented yet.\n", *args);
3096
3131
                        return 16;