简体   繁体   中英

Convert SQL query “SELECT UNIQUE 1…” in Informix-4GL program to Java code

I want to convert Informix-4GL program to Java, and I have some problems. I have a Java code and connect to Informix with success, but I'm having some problems.

  1. How can I use "SELECT UNIQUE 1..." in method executeQuery() because UNIQUE 1 not TSQL.
  2. SQLCA.SQLCODE means SQL query correct then return 0. How can I get SQLCA.SQLCODE variable in Java or Java can provide the same function.

Looking at the 4GL code segment below; it means if SQL query returns any rows then SQLCA.SQLCODE returns 0 and set 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

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

The query is testing whether there are any rows in your table FBFIL:FBRDPF1 (which means the table FBRDPF1 in the database FBFIL ) which satisfy the conditions:

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

In that condition, it is a reasonable guess that g_deptwn is a global variable (many people use the g_ prefix to indicate a global variable), and io_fonly.prtdat is probably a variable too. So, you'll need to pass those values to your Java SQL statement. The names on the LHS of the conditions are probably columns in the table rather than more I4GL variables. You'll need to decide where the table referenced lives in your SQL Server system.

In Java, you'll be using JDBC, so you'll need to execute the query and attempt to fetch a row (probably providing a variable to receive the value 1). If that query succeeds, then you'll set the Java analogue of SW_FBCHK to 1; otherwise, you'll set it to 0. Don't forget to release the resources from the query.

Since you're only testing for success, there are a few other options.

SELECT DISTINCT INSU01 ...

seems the most obvious candidate. If you don't have a fixed predicate like that in your query, you might have to consider testing the output of SELECT COUNT(*) ... , which would mean altering your logic slightly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM