Menu

OCESQL example

2020-07-04
2024-06-04
1 2 > >> (Page 1 of 2)
  • celsofigueiredo

    celsofigueiredo - 2020-07-04

    Dear friends,
    Following the example of this link: https://gnucobol.sourceforge.io/faq/gcfaq.html#index-917 , I managed to get to this point:

    celso@celso-Aspire-4740:~/Cobol$ ocesql INSERTTBL.cbl inserttbl.cob
    precompile start: INSERTTBL.cbl
    =======================================================
                  LIST OF CALLED DB Library API            
    =======================================================
    Generate:OCESQLConnect
    Generate:OCESQLExec
    Generate:OCESQLExec
    Generate:OCESQLExec
    Generate:OCESQLExec
    Generate:OCESQLExecParams
    Generate:COMMIT
    Generate:OCESQLDisconnect
    Generate:ROLLBACK
    =======================================================
    celso@celso-Aspire-4740:~/Cobol$ ocesql FETCHTBL.cbl fetchtbl.cob
    precompile start: FETCHTBL.cbl
    =======================================================
                  LIST OF CALLED DB Library API            
    =======================================================
    Generate:OCESQLConnect
    Generate:OCESQLExecSelectIntoOne
    Generate:OCESQLCursorDeclare
    Generate:OCESQLCursorOpen
    Generate:OCESQLCursorFetchOne
    Generate:OCESQLCursorFetchOne
    Generate:OCESQLCursorClose
    Generate:COMMIT
    Generate:OCESQLDisconnect
    Generate:ROLLBACK
    =======================================================
    celso@celso-Aspire-4740:~/Cobol$ export COBCPY=/home/celso/Cobol/copy
    celso@celso-Aspire-4740:~/Cobol$ cobc -x -locesql inserttbl.cob
    celso@celso-Aspire-4740:~/Cobol$ cobc -x -locesql fetchtbl.cob
    celso@celso-Aspire-4740:~/Cobol$ ./inserttbl
    *** INSERTTBL STARTED ***
    libcob: Cannot find module 'OCESQLConnect'
    celso@celso-Aspire-4740:~/Cobol$ ./fetchtbl
    *** FETCHTBL STARTED ***
    libcob: Cannot find module 'OCESQLConnect'
    

    Where am I going wrong.

    Celso Henrique

     

    Last edit: celsofigueiredo 2020-07-21
    • Simon Sobisch

      Simon Sobisch - 2020-07-04

      Does it change if you add -static to the compile command? Just a wild guess ..

       
  • celsofigueiredo

    celsofigueiredo - 2020-07-07

    Dear.

    I did the test again, but using the -static option, and kept giving the same error. Where am I going wrong?

    Celso Henriqe

     
  • Simon Sobisch

    Simon Sobisch - 2020-07-08

    Just checked - the FAQ entry is a bit outdated (@btiffin: you may want to fix this and also get esqlEC listed either directly before or after ocesql instead of down in 7.22).
    The current release is the version 1.2, do you use that?

    Hm, if you add -static the error should go away, either you should see a link-time error (whhen executing cobc -x -static -locesql inserttbl.cob or everything should work.

    So I guess you see the link-time error when doing cobc -x -static inserttbl.cob, don't you?

    Note: instead of using static calls you could also switch to pre-loading the library:

    COB_PRE_LOAD=libocsql COB_LIBRARY_PATH=/path/to/libocsql cobcrun --runtime-env (and you either see that the preload worked, or that it did not)

     
  • celsofigueiredo

    celsofigueiredo - 2020-07-08

    Dear.

    This is the "esqlOC" version:
    esqlOC
    esqlOC: ESQL for GnuCOBOL/OpenCobol Version 2 (2019.02.26) Build Jul 18 2019
    Usage: esqlOC [-Q] [-F] [-static] [-I <copybook-directory> [| -I <copybook-directory>]</copybook-directory></copybook-directory>] [-o <output-file>]</output-file> <filename> ...
    -Q Use double quotes
    -F Force unknown SQL statements to be accepted as "execute immediate"
    -static Use static calls to OCSQL library
    ===============================================================
    and
    COB_PRE_LOAD=libocsql
    COB_LIBRARY_PATH=/usr/local/lib/libocsql cobcrun --runtime-env
    cobc -x -static -locesql inserttbl.cob
    configuration error:
    default.conf: No such file or directory
    =====================================================
    I don't know what to do anymore, or am I too stupid.</filename>

    Celso Henrique

     
    • Brian Tiffin

      Brian Tiffin - 2020-07-08

      Nope, just in a swamp of details.

      You need to find default.conf, and make sure overwrite installs aren't getting cross wired or confusing things.

      ::text
      prompt$ sudo updatedb
      prompt$ locate default.conf
      

      See how many copies might be on system,

      ::text
      prompt$ strace 2>&1 cobc -x -static -locesql inserttbl.cob | grep default.conf
      

      See where cobc is looking. Merge the two views by perhaps manually moving files around, Celso. It's a sign that things are pretty mungled for the cobc in $PATH and the install that happened last. Hopefully seeing where cobc is looking can help figure out what might be causing the grief.

      Cheers,
      Blue

       
    • Simon Sobisch

      Simon Sobisch - 2020-07-08

      cobc --info will tell you where it looks for and gives a hint what environment variable you may tweak to point it to the correct config directory.

       
  • celsofigueiredo

    celsofigueiredo - 2020-07-08

    Dear.

    After some adjustments and corrections, I managed to get to this point, using the -static option:

    celso@celso-Aspire-4740:~/Cobol$ cobc -x -static -locesql inserttbl.cob
    /tmp/cob3874_0.c: In function INSERTTBL_:
    /tmp/cob3874_0.c:119:9: warning: implicit declaration of function OCESQLConnect [-Wimplicit-function-declaration]
       b_1 = OCESQLConnect (b_30, b_24, (cob_s32_t)30LL, b_25, (cob_s32_t)10LL, b_23
             ^
    /tmp/cob3874_0.c:142:9: warning: implicit declaration of function OCESQLExec [-Wimplicit-function-declaration]
       b_1 = OCESQLExec (b_30, b_49);
             ^
    /tmp/cob3874_0.c:239:11: warning: implicit declaration of function OCESQLStartSQL [-Wimplicit-function-declaration]
         b_1 = OCESQLStartSQL ();
               ^
    /tmp/cob3874_0.c:247:11: warning: implicit declaration of function OCESQLSetSQLParams [-Wimplicit-function-declaration]
         b_1 = OCESQLSetSQLParams ((cob_s32_t)3LL, (cob_s32_t)4LL, (cob_s32_t)0LL, b
               ^
    /tmp/cob3874_0.c:270:11: warning: implicit declaration of function OCESQLExecParams [-Wimplicit-function-declaration]
         b_1 = OCESQLExecParams (b_30, b_61, (cob_s32_t)3LL);
               ^
    /tmp/cob3874_0.c:274:11: warning: implicit declaration of function OCESQLEndSQL [-Wimplicit-function-declaration]
         b_1 = OCESQLEndSQL ();
               ^
    /tmp/cob3874_0.c:315:9: warning: implicit declaration of function OCESQLDisconnect [-Wimplicit-function-declaration]
       b_1 = OCESQLDisconnect (b_30);
             ^
    /usr/local/lib/libocesql.so: referência indefinida para `log10'
    /usr/local/lib/libocesql.so: referência indefinida para `ceil'
    collect2: error: ld returned 1 exit status
    

    Without that -static option the program compiles, but the following appears:

    celso @ celso-Aspire-4740: ~ / Cobol $ ./inserttbl
    *** INSERTTBL STARTED ***
    libcob: Cannot find module 'OCESQLConnect'
    

    celso @ celso-Aspire-4740: ~ / Cobol $
    I really don't know what I'm doing wrong.

     

    Last edit: Simon Sobisch 2020-07-08
    • Simon Sobisch

      Simon Sobisch - 2020-07-08

      The implicit declarations are strange, cobc should generate those on the fly.
      What does cobc -Vsays?

      The link errors for log10 and ceil are shown as dependecies of the libocesql library - adjust to:
      cobc -x -static -lm -locesql inserttbl.cob and it should work

      The "missing module" is also clear to me now - there's simply no such module, either use static linking (also possible "per entry point" with multiple -K entryName, for all the entry points noted in "LIST OF CALLED DB Library API" summaries instead of the global "everything that is CALL 'literal' that you get with -static) together with -llibname as done above, or preload the library as noted above which will remove the need to specify a link library (and ease later updates: just pre-load another one, no re-link needed).

       
  • celsofigueiredo

    celsofigueiredo - 2020-07-08

    Dear.

    I've tried everything, here, to solve this example, if you can give me the solution I'll thank you very much.
    But what I don't understand is that I managed to solve another example, whose link is this: "https://sourceforge.net/p/open-cobol/contrib/HEAD/tree/trunk/samples/DBsample/PostgreSQL/". And it uses practically the same tools.

    Celso Henrique.

     
    • Simon Sobisch

      Simon Sobisch - 2020-07-09

      Isn't cobc -x -static -lm -locesql inserttbl.cob the solution (what GC-version do you use in this setup btw)?

       
    • James K. Lowden

      James K. Lowden - 2020-07-09

      Ceslo, one part of "everything" you didn't try was answering Simon's question:

      The implicit declarations are strange, cobc should generate those on the fly.
      What does cobc -V says?

      It seems your compiler is not behaving normally. The version information might explain why not.

       
  • celsofigueiredo

    celsofigueiredo - 2020-07-09

    Dear.
    I tried with all versions of GNUcobol, but these current results are with the version "cobc (GnuCOBOL) 3.1-rc1.0".

    The most intriguing of all is that with the other example "https://sourceforge.net/p/open-cobol/contrib/HEAD/tree/trunk/samples/DBsample/PostgreSQL/"; I did all the examples and they worked correctly without errors. The only difference is the number of libraries added to the program. The database is the same "Postgres". I've honestly tried everything to find out, where I'm going wrong.

    Celso Henrique.

     
    • Simon Sobisch

      Simon Sobisch - 2020-07-10

      We totally believe you that you've did this.
      Two questions:

      • What environment (32/64bit, OS) are you on?
      • What is the output of LANG=EN cobc -x -static --verbose -lm -locesql inserttbl.cob (if that doesn't work then without the LANG=EN)?
       
  • celsofigueiredo

    celsofigueiredo - 2020-07-10

    Dear, Simon Sobisch.

    I am testing this example in a Linux Ubuntu 16.04 64-bit environment and the result you requested gave the following result:

    celso@celso-Aspire-4740:~/Cobol$ LANG=EN cobc -x -static --verbose -lm -locesql inserttbl.cob
    cobc (GnuCOBOL) 3.0-rc1.0
    Built     Jul 08 2020 21:25:57  Packaged  Apr 22 2018 22:26:37 UTC
    C version "5.4.0 20160609"
    loading standard configuration file 'default.conf'
    command line:   cobc -x -static --verbose -lm -locesql inserttbl.cob 
    preprocessing:  inserttbl.cob -> ./cob3764_0.cob
    return status:  0
    parsing:    ./cob3764_0.cob (inserttbl.cob)
    return status:  0
    translating:    ./cob3764_0.cob -> ./cob3764_0.c (inserttbl.cob)
    executing:  gcc -c -I/usr/local/include -Wno-unused -fsigned-char
            -Wno-pointer-sign -pipe -o "./cob3764_0.o" "./cob3764_0.c"
    return status:  0
    executing:  gcc -Wl,--export-dynamic -o "inserttbl" "./cob3764_0.o"
            -L/usr/local/lib -lcob -lm -lgmp -lncurses -ldb-5.3 -ldl -l"m"
            -l"ocesql"
    /usr/local/lib/libocesql.so: undefined reference to `log10'
    /usr/local/lib/libocesql.so: undefined reference to `ceil'
    collect2: error: ld returned 1 exit status
    return status:  256
    celso@celso-Aspire-4740:~/Cobol$ 
    

    What am I doing wrong?

    Celso Henrique

     
    • Simon Sobisch

      Simon Sobisch - 2020-07-10

      looks correct. Any change with LANG=EN cobc -x -static --verbose -locesql -lm inserttbl.cob?

       
  • celsofigueiredo

    celsofigueiredo - 2020-07-10

    Dear,
    With this format, it gave:

    celso@celso-Aspire-4740:~/Cobol$ LANG=EN cobc -x -static --verbose -locesql -lm inserttbl.cob
    cobc (GnuCOBOL) 3.0-rc1.0
    Built     Jul 08 2020 21:25:57  Packaged  Apr 22 2018 22:26:37 UTC
    C version "5.4.0 20160609"
    loading standard configuration file 'default.conf'
    command line:   cobc -x -static --verbose -locesql -lm inserttbl.cob 
    preprocessing:  inserttbl.cob -> ./cob3398_0.cob
    return status:  0
    parsing:    ./cob3398_0.cob (inserttbl.cob)
    return status:  0
    translating:    ./cob3398_0.cob -> ./cob3398_0.c (inserttbl.cob)
    executing:  gcc -c -I/usr/local/include -Wno-unused -fsigned-char
            -Wno-pointer-sign -pipe -o "./cob3398_0.o" "./cob3398_0.c"
    return status:  0
    executing:  gcc -Wl,--export-dynamic -o "inserttbl" "./cob3398_0.o"
            -L/usr/local/lib -lcob -lm -lgmp -lncurses -ldb-5.3 -ldl
            -l"ocesql" -l"m"
    return status:  0
    celso@celso-Aspire-4740:~/Cobol$ 
    

    Celso henrique

     
  • celsofigueiredo

    celsofigueiredo - 2020-07-10

    Dear.

    And the results of the two programs were:

    celso@celso-Aspire-4740:~/Cobol$ ./inserttbl
    *** INSERTTBL STARTED ***
    *** SQL ERROR ***
    SQLCODE: -0000000402 Undefined error
    ERRCODE: 08001
    
    celso@celso-Aspire-4740:~/Cobol$ ./fetchtbl
    *** FETCHTBL STARTED ***
    *** SQL ERROR ***
    SQLCODE: -0000000402 Undefined error
    ERRCODE: 08001
    
    celso@celso-Aspire-4740:~/Cobol$ 
    

    At least the programs work, now it must be a database connection problem, right.

    Celso henrique.

     
    • Anonymous

      Anonymous - 2024-06-04

      Hi @celsofigueiredo, since I don't see the final result in this thread, maybe you don't need it anymore but I'm putting here my solution after gone through various answers in this thread and others. Hope someone else get away difficulties.

      The error above is related postgresql connection string standard, you have to:

      • First, create password for entry user (in this case, postgres):
        • $sudo -u postgres -i psql
        • postgres=# \password
        • enter your password
      • Then, change your input like this:
                 MOVE  'dbtraining@localhost'    TO DBNAME.    *> <dbname>@<server>
                 MOVE  'postgres'                TO USERNAME.  *> <username>
                 MOVE  'postgres1234'            TO PASSWD.    *> <your password above>
      
      • Recompile and run

      Hope you doing well,
      Manh

       
      👍
      1

      Last edit: Simon Sobisch 2024-06-04
  • celsofigueiredo

    celsofigueiredo - 2020-07-13

    Dear
    What is the difference between these two ways of running "cobc":

    celso@celso-Aspire-4740:~/Cobol$ export COBCPY=/home/celso/Cobol/copy
    celso@celso-Aspire-4740:~/Cobol$ LANG=EN cobc -x -static --verbose -locesql -lm inserttbl.cob

    and

    celso@celso-Aspire-4740:~/Cobol$ export COBCPY=/home/celso/Cobol/copy
    celso@celso-Aspire-4740:~/Cobol$ cobc -x -locesql inserttbl.cob

    Celso Henrique.

     
  • Simon Sobisch

    Simon Sobisch - 2020-07-13

    There are 4 big differences in those ways:

    1. Helping non-native speakers to understand the messages from both cobc and the programs it calls by specifying via LANG=EN that all messages should be returned in English. This has nothing to do with any result (other than the language used to find the message-catalogs).

    2. Specify via --verbose that cobc will output what it does, this is something that often helps to "debug" some things related to that.

    3. Specify via --static that all CALL "literal" should be directly resolved, internally this leads to a C function call with that name - if the linker cannot resolve that it will output an error.

    4. Specify an additional library. libocesql uses math functions that are not part of the compiler in your specific setup. The linker "sees" those and can not resolve them, leading to error messages. When looking at the manpages for those functions or "on the internet" one can see where to find them, which is libmath in this case. As many systems resolve the dependencies in order (in most cases also removing "unneeded" entries (optimization and security) = those that were not referenced before) - from left to right - it is important to use the correct order (which is the reason that it does not work when specified different - in your case, on other machines it doesn't matter [and also wouldn't matter if the linker was told to not remove these additional entry points]).

     
  • celsofigueiredo

    celsofigueiredo - 2020-07-13

    Dear.
    Thanks for your help, I'm almost done with this program, but I just remembered that I didn't do a process at the beginning of the compilation:

    5. Installation
    ===============
    
    To install Ocesql:
    
        ./configure
        make
        make install
    
    For use with PostgreSQL 9.0 or later:
    
        export CPPFLAGS="-I/usr/pgsql-9.x/include" # -->1
        export LDFLAGS="-L/usr/pgsql-9.x/lib"      # -->2
        ./configure
        make
        make install
    

    I am using postgres 9.5 and in place of that item (2) export LDFLAGS="-L/usr/pgsql-9.x/lib"; I put the following, which corresponds to where the postgres is: export LDFLAGS="-L/usr/lib/postgresql/9.5/lib"; already the item (1), I could not find the folder" include ". The error must be at this point: export CPPFLAGS="-I/usr/pgsql-9.x/include".
    And as you already know, I am very bad at configuring.
    In this CPPFLAGS variable, do I have to configure how?

    Celso Henrique.

     

    Last edit: Simon Sobisch 2020-07-18
    • Simon Sobisch

      Simon Sobisch - 2020-07-18

      It all depends on where your include files (= sql headers) are. and this also depends how you've installed postgresql.

      I'm also a bit confused as you've previously mentioned esqlOC version 2.0 and also reference OCESQL. The first one is hosted at https://sourceforge.net/p/open-cobol/contrib/HEAD/tree/trunk/esql and works via ODBC, the second is hosted at https://github.com/opensourcecobol/Open-COBOL-ESQL/releases (at version 1.2) and uses direct link to postgresql.

      Please help me summarize:

      • using OCESQL 1.2 (correct?)
      • using postgresql 9.5 (installed how?)

      In any case I'd suggest to not export those variables but specify them during configure (this should work and be more self-contained).

       
  • celsofigueiredo

    celsofigueiredo - 2020-07-18

    Dear Simon,

    -- using OCESQL 1.2 (correct?), yes it is correct
    -- using postgresql 9.5 (installed as?), like using ubuntu, postgres comes in the package, installed through the synaptic package manager.

    Explain me better (In any case I'd suggest to not export those variables but specify them during configure ).

    I do not really understand this question of variables, where it is better to specify them.

    What is the best place to specify these variables:
    CPPFLAGS
    LDFLAGS
    and the other GNUcobol variables, postgres, mysql and other auxiliary programs.

    Celso Henrique.

     
  • celsofigueiredo

    celsofigueiredo - 2020-07-25

    Dear.

    I redid this example again, from the beginning, but it continues to fail, this time I complained about the lack of lib "libocesql.so.0"; but this lib exists and is in the "usr / local / lib" directory. I ask again, what am I doing WRONG?

    celso@celso-Inspiron-3583:~/Cobol/sample$ cobc -x inserttbl.cob -locesql
    celso@celso-Inspiron-3583:~/Cobol/sample$ ocesql INSERTTBL.cbl inserttbl.cob
    precompile start: INSERTTBL.cbl
    =======================================================
                  LIST OF CALLED DB Library API            
    =======================================================
    Generate:OCESQLConnect
    Generate:OCESQLExec
    Generate:OCESQLExec
    Generate:OCESQLExec
    Generate:OCESQLExec
    Generate:OCESQLExecParams
    Generate:COMMIT
    Generate:OCESQLDisconnect
    Generate:ROLLBACK
    =======================================================
    celso@celso-Inspiron-3583:~/Cobol/sample$ LANG=EN cobc -x -static --verbose -locesql -lm inserttbl.cob
    cobc (GnuCOBOL) 3.1-rc1.0
    Built     Jul 25 2020 09:21:01  Packaged  Jul 01 2020 00:39:30 UTC
    C version "5.4.0 20160609"
    loading standard configuration file 'default.conf'
    command line:   cobc -x -static --verbose -locesql -lm inserttbl.cob 
    preprocessing:  inserttbl.cob -> /tmp/cob27668_0.cob
    return status:  0
    parsing:    /tmp/cob27668_0.cob (inserttbl.cob)
    return status:  0
    translating:    /tmp/cob27668_0.cob -> /tmp/cob27668_0.c (inserttbl.cob)
    executing:  gcc -c -I/usr/local/include -Wno-unused -fsigned-char
            -Wno-pointer-sign -pipe -o "/tmp/cob27668_0.o"
            "/tmp/cob27668_0.c"
    return status:  0
    executing:  gcc -Wl,--export-dynamic -o "inserttbl" "/tmp/cob27668_0.o"
            -L/usr/local/lib -lcob -lm -l"ocesql" -l"m"
    return status:  0
    celso@celso-Inspiron-3583:~/Cobol/sample$ ./inserttbl
    ./inserttbl: error while loading shared libraries: libocesql.so.0: cannot open shared object file: No such file or directory
    celso@celso-Inspiron-3583:~/Cobol/sample$ 
    

    Celso Henrique.

     
1 2 > >> (Page 1 of 2)

Anonymous
Anonymous

Add attachments
Cancel