Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can "put" it on database using any tool that can run sql statements. This can be done by ISA (Informix Server Administrator), or SQL Editors working with ODBC or JDBC drivers. Of course you can use JDBC to this task:</p> <pre><code>stmt = conn.createStatement() stmt.execute(FUN_BODY) </code></pre> <p>I use it with Informix JDBC driver and Jython (so, no semicolons at line ends).</p> <p>You have some errors in procededure. It should be function, and if I understand its name it should compare two ints using their absolute values. I would write it that way:</p> <pre><code>FUN_BODY = """CREATE FUNCTION abs_eq (arg1 INTEGER, arg2 INTEGER) RETURNING BOOLEAN; IF (arg1 == arg2) THEN RETURN 't'; END IF; IF (arg1 == -arg2) THEN RETURN 't'; END IF; IF (-arg1 == arg2) THEN RETURN 't'; END IF; RETURN 'f'; END FUNCTION; """ </code></pre> <p>I would also add some tests, there is Jython code with test routine and tests:</p> <pre><code>def test_abs_eq(proc, arg1, arg2, expected): proc.setInt(1, arg1); proc.setInt(2, arg2); rs = proc.executeQuery(); while (rs.next()): r = rs.getBoolean(1) ok = 'ok' if r != expected: ok = ' ERROR!!!' print('%d, %d: %s %s' % (arg1, arg2, r, ok)) def test_multi(db_url, usr, passwd): try: db = DriverManager.getConnection(db_url, usr, passwd) conn = db.createStatement() conn.execute(FUN_BODY) proc = db.prepareCall("{ call abs_eq(?,?) }"); test_abs_eq(proc, 0, 0, True) test_abs_eq(proc, 3, 4, False) test_abs_eq(proc, 3, 3, True) test_abs_eq(proc, 20, 0, False) test_abs_eq(proc, -20, -20, True) test_abs_eq(proc, 20, -20, True) test_abs_eq(proc, -20, 20, True) test_abs_eq(proc, 20, 20, True) db.close() except: print("there were errors!") s = traceback.format_exc() sys.stderr.write("%s\n" % (s)) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload