VARKON Version 1.16 1998-10-13

### Communicating with ODBC databases

The WIndows95/NT version of VARKON includes MBS functions that can be used to establish a connection with a database or datasource through an ODBC interface. ODBC is a vendor independant interface to database systems like Oracle, Sybase, Informix, DB2 etc. You can even use ODBC to access data in files created with Microsoft Excel.

The purpose of the ODBC interface is to make it possible to integrate VARKON applications with traditional database applications. A VARKON application could for example automatically fetch parameter values for a specific design, automatically generate a drawing or model, calculate new data and put that data back into the database.

Here is a short example:

              MACRO MODULE show_price(INT dnr >"Detail number !");

              STRING sql_statement*132,price*10;
              INT    status;

              BEGINMODULE

              !*
              !***Connect to the database.
              !*
                 status:=odbc_connect("My_database", "My_name", "My_password");

                 if status < 0 then
                   exit(odbc_error());
                 endif;
              !*
              !***Build SELECT statement.
              !*
                 sql_statement:="SELECT price FROM My_table WHERE dnr="+str(dnr,-1,0));
              !*
              !***Execute.
              !*
                 status:=odbc_execdirect(sql_statement);

                 if status < 0 then
                   exit(odbc_error());
                 endif;
              !*
              !***Get first line of result.
              !*
                 status:=odbc_fetch();

                 if status < 0 then
                   exit(odbc_error());
                 endif;
              !*
              !***Get first data on this line.
              !*
                 status:=getstring(price);

                 if status < 0 then
                   exit(odbc_error());
                 endif;
              !*
              !***Close the connection.
              !*
                  odbc_disconnect();
              !*
              !***Display result.
              !*
                 lst_ini();
                 lst_lin("Price is:"+price);
                 lst_exi();

              ENDMODULE

This module connects to the database, searches for the price of a detail with specific detailnumber and displays the result. The errorhandling could easily be improved to check if the detail exists and if not ask for a new detailnumber.

VARKON Homepage | Index