Convert SQL query "SELECT UNIQUE 1 ..." in Informix-4GL program to Java code

I want to convert an Informix-4GL program to Java, and I have some problems. I have Java code and successfully connected to Informix, but I have problems.

  • How can I use "SELECT UNIQUE 1 ..." in the executeQuery () method, because UNIQUE 1 is not TSQL.
  • SQLCA.SQLCODE means the SQL query is correct and then returns 0. How can I get the SQLCA.SQLCODE variable in Java or Java, the same function can be provided.

Looking at the 4GL code segment below; this means that if the SQL query returns any rows, SQLCA.SQLCODE returns 0 and sets SW_FBCHK = 1 .

 SELECT UNIQUE 1 FROM FBFIL:FBRDPF1 WHERE COMPID = G_DEPTWN AND FPRDAT = IO_FONLY.PRTDAT AND INSU01 = '5' IF SQLCA.SQLCODE = 0 THEN LET SW_FBCHK = 1 ELSE LET SW_FBCHK = 0 END IF 
+4
source share
2 answers

Since you are only testing for success, there are several more options.

 SELECT DISTINCT INSU01 ... 

seems like the most obvious candidate. If you do not have a fixed predicate similar to your query, you might have to consider testing the output of SELECT COUNT(*) ... , which will slightly change your logic.

+1
source

In Informix, SELECT UNIQUE is the non-standard equivalent of a standard SELECT DISTINCT .

The query checks to see if your table FBFIL:FBRDPF1 any rows (which means table FBRDPF1 in the FBFIL database) that satisfy the conditions:

 WHERE COMPID = g_deptwn AND FPRDAT = io_fonly.prtdat AND INSU01 = '5' 

Under this condition, it is reasonable to assume that g_deptwn is a global variable (many use the g_ prefix to indicate a global variable), and io_fonly.prtdat is probably also a variable. Therefore, you need to pass these values ​​to the Java SQL statement. LHS condition names are likely to be columns in a table, and not more than I4GL variables. You will need to decide where the specified table lives on your SQL Server system.

In Java, you will use JDBC, so you will need to execute the query and try to extract the string (perhaps by providing a variable to get the value 1). If this request SW_FBCHK , you will set the Java counterpart of SW_FBCHK to 1; otherwise, you set the value to 0. Remember to free resources from the request.

+1
source

Source: https://habr.com/ru/post/1442086/


All Articles