SQLCODE in Cobol
Moderator: Rathinagiri
SQLCODE in Cobol
Hi all,
I remember that in Cobol there was the SQLCODE variable which returned the result of a DB instruction
0-> everything ok
100-> not found
etc ...
Is there an equivalent thing in HMG too?
Thanks, Carlo.
I remember that in Cobol there was the SQLCODE variable which returned the result of a DB instruction
0-> everything ok
100-> not found
etc ...
Is there an equivalent thing in HMG too?
Thanks, Carlo.
- dragancesu
- Posts: 931
- Joined: Mon Jun 24, 2013 11:53 am
- DBs Used: DBF, MySQL, Oracle
- Location: Subotica, Serbia
Re: SQLCODE in Cobol
Every database system get error code
What do you want?
What do you want?
Re: SQLCODE in Cobol
How can I test if an insert/update operation was successful?
- Claudio Ricardo
- Posts: 367
- Joined: Tue Oct 27, 2020 3:38 am
- DBs Used: DBF, MySQL, MariaDB
- Location: Bs. As. - Argentina
Re: SQLCODE in Cobol
Hello ... I use some functions that I create to automate the process and simplify the code, there are 4 in total:
One, "SQL_StartConn ()" upon entering the program establishes the connection to the database.
One function for SELECT "SQL_Q (cQuery)" returns a two-dimensional array with the data,
or empty if there is no data or it failed. And another for INSERT, DELETE, Etc. "SQL_E (cQuery)"
And one last "SQL_EndConn ()" to close the connection when exiting the program.
If for some reason the connection is lost, they try to reestablish it.
Each one with its respective error messages that you can translate into Italian.
They also return .T. if all good or .F. if it failed.
One, "SQL_StartConn ()" upon entering the program establishes the connection to the database.
One function for SELECT "SQL_Q (cQuery)" returns a two-dimensional array with the data,
or empty if there is no data or it failed. And another for INSERT, DELETE, Etc. "SQL_E (cQuery)"
And one last "SQL_EndConn ()" to close the connection when exiting the program.
If for some reason the connection is lost, they try to reestablish it.
Each one with its respective error messages that you can translate into Italian.
They also return .T. if all good or .F. if it failed.
- Attachments
-
- MySQL.zip
- (1.76 KiB) Downloaded 120 times
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
WhatsApp / Telegram: +54 911-63016162
- serge_girard
- Posts: 3420
- Joined: Sun Nov 25, 2012 2:44 pm
- DBs Used: 1 MySQL - MariaDB
2 DBF - Location: Belgium
- Contact:
Re: SQLCODE in Cobol
Carlazza,
SQLCODE like Cobol on mainframe... that would be nice...!
We have another solution, I use this:
Minimal and you have to investigate the content of NetErr() to know what is the problem. Also to know number of affected rows after an update is missing, as far as I know.
But overaal SQL works great in HMG!
Serge
SQLCODE like Cobol on mainframe... that would be nice...!
We have another solution, I use this:
Code: Select all
cQuery1a := " SELECT NR, PLAATS, LAND "
cQuery1a += " FROM GEN_PLAATS_LND "
cQuery1a += " WHERE LAND > '' "
cQuery1a += " AND PLAATS > '' "
cQuery1a += " ORDER BY 3,2 "
cSQLa := cQuery1a
cQuery1a := dbo:Query( cQuery1a )
IF cQuery1a:NetErr()
MSGINFO(cSQLa + cQuery1a:ERROR() )
RETURN
ENDIF
cQuery1 := " DELETE FROM NEW_VERSION "
cQuery1 += " WHERE FILE = 'BETOZPDF' "
cQuery1 += " AND PERSON_ID = '" + xNR2 + "' "
cSQL := cQuery1
cQuery1 := dbo:Query( cQuery1 )
IF cQuery1:NetErr()
Write_Trace_RED( PROCNAME(),cSQL, cQuery1:ErrOR())
RETURN
ENDIF
But overaal SQL works great in HMG!
Serge
There's nothing you can do that can't be done...
Re: SQLCODE in Cobol
Thanks a lot Claudio, I will take a lookClaudio Ricardo wrote: ↑Tue Nov 23, 2021 11:40 pm Hello ... I use some functions that I create to automate the process and simplify the code, there are 4 in total:
One, "SQL_StartConn ()" upon entering the program establishes the connection to the database.
One function for SELECT "SQL_Q (cQuery)" returns a two-dimensional array with the data,
or empty if there is no data or it failed. And another for INSERT, DELETE, Etc. "SQL_E (cQuery)"
And one last "SQL_EndConn ()" to close the connection when exiting the program.
If for some reason the connection is lost, they try to reestablish it.
Each one with its respective error messages that you can translate into Italian.
They also return .T. if all good or .F. if it failed.
Re: SQLCODE in Cobol
serge_girard wrote: ↑Wed Nov 24, 2021 9:40 am Carlazza,
SQLCODE like Cobol on mainframe... that would be nice...!
We have another solution, I use this:Minimal and you have to investigate the content of NetErr() to know what is the problem. Also to know number of affected rows after an update is missing, as far as I know.Code: Select all
cQuery1a := " SELECT NR, PLAATS, LAND " cQuery1a += " FROM GEN_PLAATS_LND " cQuery1a += " WHERE LAND > '' " cQuery1a += " AND PLAATS > '' " cQuery1a += " ORDER BY 3,2 " cSQLa := cQuery1a cQuery1a := dbo:Query( cQuery1a ) IF cQuery1a:NetErr() MSGINFO(cSQLa + cQuery1a:ERROR() ) RETURN ENDIF cQuery1 := " DELETE FROM NEW_VERSION " cQuery1 += " WHERE FILE = 'BETOZPDF' " cQuery1 += " AND PERSON_ID = '" + xNR2 + "' " cSQL := cQuery1 cQuery1 := dbo:Query( cQuery1 ) IF cQuery1:NetErr() Write_Trace_RED( PROCNAME(),cSQL, cQuery1:ErrOR()) RETURN ENDIF
But overaal SQL works great in HMG!
Serge
Great. I will try it
Tks
Re: SQLCODE in Cobol
I have never been able to sql to work. I am using hmg.3.4.4. I think I need to add something to my compiler.
Here is what I would like to do. I can do this in VISUAL FOXPRO but there seems to be no sql in HMG.
What I do now and works ok is.
I would like to learn how to use sql.
Any thoughts.
Thanks, Franco
Here is what I would like to do. I can do this in VISUAL FOXPRO but there seems to be no sql in HMG.
Code: Select all
#include <hmg.ch>
Local cQueryla, sQla //I did this in fox SELECT NAME,CITY,PROVINCE FROM CUSTOMER WHERE CITY > ' ' INTO TABLE 'TEMP.DBF'
cQuery1a := " SELECT NAME " // I have table CUSTOMER with fields NAME,CITY,PROVINCE
cQuery1a += " FROM CUSTOMER "
cQuery1a += " WHERE CITY > '' "
cQuery1a += " AND PROVINCE > '' "
cQuery1a += " ORDER BY NAME "
cQuery1a += " INTO TABLE 'TEMP.DBF' "
cSQLa := cQuery1a
cQuery1a := dbo:Query( cQuery1a )
If file('TEMP.DBF')
USE TEMP // If I USE CUSTOMER this works but I can not USE SQL TO CREATE TEMP
set device to printer
set printer to "Temp1.txt" //Creates a text file.
list NAME, CITY, PROVINCE to printer
set device to screen
CLOSE TEMP
endif
*cQuery1a := " SELECT NR, PLAATS, LAND "
*cQuery1a += " FROM GEN_PLAATS_LND "
*cQuery1a += " WHERE LAND > '' "
*cQuery1a += " AND PLAATS > '' "
*cQuery1a += " ORDER BY 3,2 "
*cSQLa := cQuery1a
*cQuery1a := dbo:Query( cQuery1a )
*IF cQuery1a:NetErr()
* MSGINFO(cSQLa + cQuery1a:ERROR() )
* RETURN
*ENDIF
RETURN
Code: Select all
use CUSTOMER NEW SHARED
index on NAME TO TEMP FOR LEN(ALLTRIM(CITY)) > 0
** Then do something
close CUSTOMER
TEMP := 'TEMP.DBF'
erase (temp)
Any thoughts.
Thanks, Franco
All The Best,
Franco
Canada
Franco
Canada
- serge_girard
- Posts: 3420
- Joined: Sun Nov 25, 2012 2:44 pm
- DBs Used: 1 MySQL - MariaDB
2 DBF - Location: Belgium
- Contact:
Re: SQLCODE in Cobol
Franco,
Plenty of demo's in this forum.
First of all you will need a database and XAMPP and maybe some internet site.
How far are you?
Maybe also start new topic...
Serge
Plenty of demo's in this forum.
First of all you will need a database and XAMPP and maybe some internet site.
How far are you?
Maybe also start new topic...
Serge
There's nothing you can do that can't be done...
- dragancesu
- Posts: 931
- Joined: Mon Jun 24, 2013 11:53 am
- DBs Used: DBF, MySQL, Oracle
- Location: Subotica, Serbia
Re: SQLCODE in Cobol
@franco look viewtopic.php?f=5&t=5107&hilit=myhmg&start=10
this is my early works on this forum, software and manual for work with MySQL
this is my early works on this forum, software and manual for work with MySQL