Jargon Software
Getting Started with Jargon Writer
ODBC Example



Here is an example of a simple script that accesses an Oracle 9i Lite "POlite" demo database, using ODBC connectivity and SQL statements. The image shows the user interface in Jargon Writer.


ODBC Test Program



Script contents:


    var DBEngine    = "ODBC";
    var Datasource  = "POlite";
    var User        = "SYSTEM";
    var Password    = "SYSTEM";
    var db = "";
    var TRUE = 1;
    var FALSE = 0;
    function init() {
      frame0.SetVisible(true);
    }
    function Exit() {
      sys.MessageBox("Goodbye!");
      sys.Exit();
    }
    function DBConnect() {
      if (db) {
        if (db.connected()) {
          sys.MessageBox("Already connected");
        }
      }
      else {
        db = new Database;
      }
      db.connect(DBEngine, Datasource, User, Password);
      if (! db.connected()) {
        sys.MessageBox("Can't connect to database");
      }
    }
    function DBDisconnect() {
      if (db) {
        if (db.connected()) {
          db.disconnect();
        }
      }
    }
    function Display(sqlstr) {
      id = tCustNum.GetText();
      sqlstr = "select * from customer where CUSTID=" + id;
      CustDisplay(sqlstr);
    }
    function CustDisplay(sqlstr) {
      if (db == "") {
        sys.MessageBox("Not connected to database");
        return;
      }
      if (! db.connected()) {
        sys.MessageBox("Not connected to database");
        return;
      }
      if (sqlstr == "") {
        sys.MessageBox("Empty SQL request");
      }
      custs = db.cursor(sqlstr, Database.dynaset);
      if (! custs.next()) return FALSE;
      tCustNum.SetText(custs.CUSTID);
      tCustName.SetText(custs.NAME);
      tCustAddr1.SetText(custs.ADDRESS);
      tCustCity.SetText(custs.CITY);
      tCustState.SetText(custs.STATE);
      tCustZip.SetText(custs.ZIP);
      custs.close();
      return TRUE;
    }
    function Next() {
      id = tCustNum.GetText();
      sqlstr = "select * from customer where CUSTID > " + id;
      if (! CustDisplay(sqlstr)) {
          First();
      }
    }
    function Prev() {
      id = tCustNum.GetText();
      sqlstr = "select * from customer where CUSTID < "
               + id + " order by CUSTID desc";
      if (! CustDisplay(sqlstr)) {
        Last();
      }
    }
    function First() {
      sqlstr = "select * from customer where CUSTID > 0";
      CustDisplay(sqlstr);
    }
    function Last() {
      sqlstr = "select * from customer where CUSTID > 0"
               + " order by CUSTID desc";
      CustDisplay(sqlstr);
    }
    function DoClear() {
        tCustNum.SetText("");
        tCustName.SetText("");
        tCustAddr1.SetText("");
        tCustCity.SetText("");
        tCustState.SetText("");
        tCustZip.SetText("");
    }
    function Exit() {
      DBDisconnect();
      sys.MessageBox("Goodbye!");
      sys.Exit();
    }


<-- Previous Section      Up to Top      Return to Help Index      Next Section -->