EQ Eloquence B.07.10 Release Notes
Overview / Language Changes / Eloquence Odbc.DLL

The Eloquence Odbc.DLL

Using the Eloquence ODBC (Open Data Base Connectivity) DLL, Eloquence programs can now interface external database systems such as Oracle, Microsoft SQL Server or MySQL through the ODBC API on HP-UX, Linux and Windows platforms.

Contents:


Prerequisites

The Eloquence Odbc.DLL requires the following components to be installed:

Before ODBC can be used, the appropriate data source(s) must be defined. A data source definition specifies:

Except for the name of the data source and the driver these parameters depend on the requirements of the particular database and must be correctly specified according to the database vendor's documentation.

After appropriate configuration, the data source(s) can be accessed with the DSN (data source name) as shown in the examples below.

On Windows, the ODBC Data Sources applet in the Windows Control Panel is used for data source administration. It supports three different types of data sources:

The Eloquence Odbc.DLL supports System and User data sources. File data sources cannot be used.

On HP-UX or Linux, the unixODBC driver manager uses two configuration files which are typically located either in the /etc or in the /etc/unixODBC or in the /etc/opt/unixODBC directory:


Using the Odbc.DLL

The Odbc.DLL must be loaded before it can be used in a program:

 LOAD DLL Odbc,1024

This loads the Odbc.DLL from its default location and establishes a communication buffer of 1024 bytes. For details about the Eloquence LOAD DLL statement please refer to the Eloquence documentation.

The DEL DLL statement may be used to unload the DLL:

 DEL DLL Odbc

The following procedures are available to return information on the Odbc.DLL or enable logging.


ODBC connections and statements

Example:

    INTEGER Conn_id,Stmt1,Stmt2
    DIM Dsn$[256],Sql$[256]

! Load the ODBC module
    LOAD DLL Odbc,1024
!
! Connect to ODBC data source named 'SAMPLE'
! authorize with Login$ and Password$
    Login$="mike"
    Password$="secret"
    Dsn$="DSN=SAMPLE;UID="&Login$&";PWD="&Password$
    CALL DLL Odbc("Connect",Dsn$,Conn_id)

! Execute SQL statement
    Sql$="SELECT * FROM CUSTOMERS"
    CALL DLL Odbc("ExecDirect",Conn_id,Sql$,Stmt1)

! Prepare another SQL statement with two embedded parameters
    Sql$="SELECT * FROM CUSTOMERS WHERE MATCHCODE>=? AND MATCHCODE<=?"
    CALL DLL Odbc("Prepare",Conn_id,Sql$,Stmt2)


The ODBC statement

Once a statment id has been returned by the Odbc.DLL the following procedures may be called.

Example:

! Using the first SQL statement from the previous example
!
! Sequentially fetch rows
    CALL DLL Odbc("GetNumColumns",Stmt_id,Num_columns)
    LOOP
       CALL DLL Odbc("Fetch",Stmt1,Has_data)
       EXIT IF NOT Has_data
       FOR Col=1 TO Num_columns
          CALL DLL Odbc("GetData",Stmt1,Col,Buf$)
          PRINT Buf$;"|";
       NEXT Col
       PRINT
    END WHILE

! Using the second SQL statement from the previous example
!
! Query matchcodes from A to E
    CALL DLL Odbc("Execute",Stmt2,"A","E")
!
! Fetch the data as shown above
    LOOP
       CALL DLL Odbc("Fetch",Stmt2,Has_data)
       EXIT IF NOT Has_data
       ...
    END LOOP

! Now query customer numbers F to M using SetParam
    CALL DLL Odbc("SetParam",Stmt2,1,"F")
    CALL DLL Odbc("SetParam",Stmt2,2,"M")
    CALL DLL Odbc("Execute",Stmt2)
    LOOP
       CALL DLL Odbc("Fetch",Stmt2,Has_data)
       EXIT IF NOT Has_data
       ...
    END LOOP


Using the XPACK format to retrieve data

As an option, the Fetch procedure may return the data in XPACK format. In this case, the variables are equivalent to the statement's result columns. For example, the statement

 SELECT CUSTNO, NAME1 FROM CUSTOMERS
would use the variable names Custno and Name1.

If a column title contains space or dot characters, they are replaced by underscores in the resulting variable name.

If a column title however cannot be transferred into a valid variable name (for example MIN(ORDER_DATE)) a generic variable name is used, artificial such as Column_1.

Example:

! Execute SQL statement
    Sql$="SELECT CUSTNO,NAME1 FROM CUSTOMERS"
    CALL DLL Odbc("ExecDirect",Conn_id,Sql$,Stmt)

! Sequentially fetch rows
    LOOP
       CALL DLL Odbc("Fetch",Stmt,Has_data,Xbuf$)
       EXIT IF NOT Has_data
       XUNPACK Xbuf$
       PRINT Custno$,Name1$
    END LOOP


ODBC Column Information

The following procedures are available to retrieve information or change the data type on a result column of a statement. Column numbering starts at 1.

Example:

! Execute SQL statement
    Sql$="SELECT * FROM CUSTOMERS"
    CALL DLL Odbc("ExecDirect",Conn_id,Sql$,Stmt_id)

! Print column titles
    CALL DLL Odbc("GetNumColumns",Stmt_id,Num_columns)
    FOR Col=1 TO Num_columns
       CALL DLL Odbc("GetColumnTitle",Stmt_id,Col,Col_title$)
       PRINT Col_title$,
    NEXT Col
    PRINT


ODBC Parameter Information

The following procedures are available to retrieve information on statement parameters. Parameter numbering starts at 1.


ODBC Error Handling

The Eloquence Odbc.DLL introduces the following new error codes:

1110 Failed to allocate ODBC resource.
The ODBC driver manager could not be loaded or ran out of internal resources.
1111 Internal ODBC failure.
An internal problem has occurred with the ODBC driver manager or the data source.
1112 Function sequence error.
A function sequence has been executed in a wrong order (eg. data has not yet been fetched).
1113 Failed to connect.
The ODBC driver could not be loaded, the data source does not exist or the authorization has failed.
1114 Failed to disconnect.
An internal problem has occurred while disconnecting.
1115 Already connected.
Tried to connect while a connection is already present.
1116 Not connected.
Tried to disconnect while no connection is present.
1117 Failed to prepare statement.
An invalid SQL statement has been provided.
1118 Failed to execute statement.
The provided SQL statement cannot be executed.
1119 Statement has not yet been prepared.
The provided SQL statement must be prepared before it can be executed.
1120 Statement has no result.
Tried to fetch data from a statement which does not have any result.
1121 Failed to fetch next row of data.
An internal problem has occurred while fetching the next row of data.
1122 Invalid column or parameter number.
An invalid column or parameter number has been provided.

The GetError procedure may be used to obtain detailed ODBC error information.

Executing an ODBC operation can cause errors of varying complexity. The problem may be recognized at different functional layers such as the ODBC driver manager or the database server involved in the particular operation.

Therefore, a single ODBC operation may provide information about multiple errors. After an ODBC function has failed, repeated use of the GetError procedure will sequentially obtain all error information.

Each error return consists of a text message, the ODBC SQL error code (called 'SQL state' according to the X/Open and SQL Access Group SQL CAE specifications) and the native error code which was returned by the particular ODBC driver.

 CALL DLL Odbc("GetError",Message$,Sql_state$,Native_code,Has_data)

Example:

    ON ERROR GOTO Error
 ...

Error:!
    OFF ERROR
    PRINT ERRM$
    IF (ERRN>=1110) AND (ERRN<=1122) THEN Odbc_error
    PRINT ERRMSG$(ERRN)
    STOP
! 
! ODBC.DLL specific error codes
! 
Odbc_error:!
    DIM Sql_msg$[256],Sql_state$[16]
    INTEGER Sql_native_code,Sql_has_data
    RESTORE Odbc_error
    REPEAT 
      READ Err,Sql_msg$
    UNTIL NOT Err OR (Err=ERRN)
    IF Err THEN PRINT Sql_msg$
    LOOP
      CALL DLL Odbc("GetError",Sql_msg$,Sql_state$,Sql_native_code,Sql_has_data)
      EXIT IF NOT Sql_has_data
      PRINT "ODBC Error: ";Sql_msg$
      PRINT "SQL State: ";Sql_state$;", Native code: ";Sql_native_code
    END LOOP
    STOP
! 
    DATA 1110,"ODBC resource failure (ERR_ODBCRESOURCE)"
    DATA 1111,"ODBC internal failure (ERR_ODBCINTERNAL)"
    DATA 1112,"Invalid call sequence (ERR_SEQUENCE)"
    DATA 1113,"Connection failed (ERR_CONNECT)"
    DATA 1114,"Disconnect failed (ERR_DISCONNECT)"
    DATA 1115,"Already connected (ERR_CONNECTED)"
    DATA 1116,"Not connected (ERR_NOTCONNECTED)"
    DATA 1117,"Statement preparation failed (ERR_PREPARE)"
    DATA 1118,"Statement execution failed (ERR_EXECUTE)"
    DATA 1119,"Statement not prepared (ERR_NOTPREPARED)"
    DATA 1120,"Statement has no result (ERR_NORESULT)"
    DATA 1121,"Failed to fetch next row (ERR_FETCH)"
    DATA 1122,"Column/parameter number out of range (ERR_INVALIDCOLUMN)"
    DATA 0,"Unknown error code"


Example programs

The following examples document how the Odbc.DLL could be used in a program.

The first example illustrates how to retrieve data using Prepare/Execute. It is installed as ODBC1.PROG in the Eloquence share/example installation subdirectory.

! RE-STORE "ODBC1,EXAMPLE"
! 
! Eloquence ODBC DLL example program
! Retrieve data from the SAMPLE DSN using Prepare/Execute
! 
  DIM Buf$[256],Sql_msg$[256],Sql_state$[16]
  INTEGER Conn,Stmt,Col,Num_cols,Row,Has_data,Sql_native_code,Nrows,Col_type,Col_prec,Col_scale
  ON ERROR GOTO Error
  IF BACKGROUND THEN PRINTER IS STDOUT
! 
! Load the Eloquence Odbc.DLL and print version number
! 
  PRINT LIN(1);"** Loading the Eloquence Odbc.DLL"
  LOAD DLL Odbc,1024
  CALL DLL Odbc("Revision",Buf$)
  PRINT "Revision ";Buf$
! 
! The Eloquence Odbc.DLL can setup a debug log
! By default only critical messages are output to stderr
! 
! CALL DLL Odbc("LogFile","odbcdll.log")
! CALL DLL Odbc("LogFlags","*2")
! 
! Connect to the data source
! 
  Buf$="DSN=SAMPLE"
  PRINT LIN(1);"** Connecting to the data source ";Buf$
  CALL DLL Odbc("Connect",Buf$,Conn)
! 
! The completed connection string (by the ODBC driver manager)
  CALL DLL Odbc("GetConnection",Conn,Buf$)
  PRINT "Connection #"&VAL$(Conn)&": "&Buf$
! 
! Prepare a SQL statement
! 
  PRINT LIN(1);"** Preparing SQL statement"
  Buf$="SELECT * FROM CUSTOMERS WHERE MATCHCODE LIKE ? ORDER BY CUSTNO"
  CALL DLL Odbc("Prepare",Conn,Buf$,Stmt)
  PRINT "Statement #"&VAL$(Stmt)&": "&Buf$
! 
! The prepared statement has a result set
! 
  PRINT LIN(1);"** Result set"
  CALL DLL Odbc("GetNumColumns",Stmt,Num_cols)
  FOR Col=1 TO Num_cols
    PRINT "Col";Col;": ";
    CALL DLL Odbc("GetColumnTitle",Stmt,Col,Buf$)
    PRINT Buf$&" [";
    CALL DLL Odbc("GetColumnVarName",Stmt,Col,Buf$)
    PRINT Buf$&"]";
    CALL DLL Odbc("GetColumnType",Stmt,Col,Col_type)
    PRINT " Type=";VAL$(Col_type);
    CALL DLL Odbc("GetColumnPrecision",Stmt,Col,Col_prec)
    PRINT ",Prec=";VAL$(Col_prec);
    CALL DLL Odbc("GetColumnScale",Stmt,Col,Col_scale)
    PRINT ",Scale=";VAL$(Col_scale)
  NEXT Col
! 
! Execute the prepared statement
! 
  PRINT LIN(1);"** Executing prepared statement"
! The Execute call is used to specify any parameters (positional)
! Parameter not specified is assumed NULL
! 
  CALL DLL Odbc("Execute",Stmt,"KEL%")
! 
! As an alternative, the SetParam call may be used.
! CALL DLL Odbc("SetParam",Stmt,1,"KEL%")
! CALL DLL Odbc("Execute",Stmt)
! 
! For some calls, the server may already know the number of results
! If the value returned is -1 then it is unknown
! 
  CALL DLL Odbc("RowCount",Stmt,Nrows)
  PRINT Nrows;"results available"
! 
! Retrieve the data
! 
  PRINT LIN(1);"** Fetching results"
  Row=0
  LOOP
    CALL DLL Odbc("Fetch",Stmt,Has_data)
    EXIT IF NOT Has_data
    Row=Row+1
    PRINT "[";Row;"] ";
    CALL DLL Odbc("GetData",Stmt,1,Buf$)
    PRINT " "&CHR$(34)&Buf$&CHR$(34);
    CALL DLL Odbc("GetData",Stmt,2,Buf$)
    PRINT " "&CHR$(34)&Buf$&CHR$(34);
    CALL DLL Odbc("GetData",Stmt,3,Buf$)
    PRINT " "&CHR$(34)&Buf$&CHR$(34);
    CALL DLL Odbc("GetData",Stmt,9,Turnover)
    PRINT Turnover
  END LOOP
  PRINT Row;"rows fetched"
! 
  PRINT LIN(1);"** Disconnecting"
  CALL DLL Odbc("DropStatement",Stmt)
  CALL DLL Odbc("Disconnect",Conn)
  PRINT "done."
  STOP
! 
! Catch program error
! 
Error:! 
  OFF ERROR
  PRINT ERRM$
  IF (ERRN>=1110) AND (ERRN<=1122) THEN Odbc_error
  PRINT ERRMSG$(ERRN)
  STOP
! 
! ODBC.DLL specific error codes
! 
Odbc_error:! 
  ! PRINT "Problem detected by Odbc.DLL"
  RESTORE Odbc_error
  REPEAT 
    READ Err,Sql_msg$
  UNTIL NOT Err OR (Err=ERRN)
  IF Err THEN PRINT Sql_msg$
  LOOP
    CALL DLL Odbc("GetError",Sql_msg$,Sql_state$,Sql_native_code,Has_data)
    EXIT IF NOT Has_data
    PRINT "ODBC Error: ";Sql_msg$
    PRINT "SQL State: ";Sql_state$;", Native code: ";Sql_native_code
  END LOOP
  STOP
! 
  DATA 1110,"ODBC resource failure (ERR_ODBCRESOURCE)"
  DATA 1111,"ODBC internal failure (ERR_ODBCINTERNAL)"
  DATA 1112,"Invalid call sequence (ERR_SEQUENCE)"
  DATA 1113,"Connection failed (ERR_CONNECT)"
  DATA 1114,"Disconnect failed (ERR_DISCONNECT)"
  DATA 1115,"Already connected (ERR_CONNECTED)"
  DATA 1116,"Not connected (ERR_NOTCONNECTED)"
  DATA 1117,"Statement preparation failed (ERR_PREPARE)"
  DATA 1118,"Statement execution failed (ERR_EXECUTE)"
  DATA 1119,"Statement not prepared (ERR_NOTPREPARED)"
  DATA 1120,"Statement has no result (ERR_NORESULT)"
  DATA 1121,"Failed to fetch next row (ERR_FETCH)"
  DATA 1122,"Column/parameter number out of range (ERR_INVALIDCOLUMN)"
  DATA 0,"Unknown error code"


The second example illustrates how to retrieve data using XPACK. It is installed as ODBC2.PROG in the Eloquence share/example installation subdirectory.

! RE-STORE "ODBC2,EXAMPLE"
! 
! Eloquence ODBC DLL example program
! Retrieve data from the SAMPLE DSN using XPACK
! 
  DIM Buf$[256],Sql_msg$[256],Sql_state$[16],Xbuf$[1024]
  INTEGER Conn,Stmt,Col,Num_cols,Row,Has_data,Sql_native_code
  DIM Custno$[6],Matchcode$[10],Name1$[32]
  REAL Turnover
  ON ERROR GOTO Error
  IF BACKGROUND THEN PRINTER IS STDOUT
! 
! Load the Eloquence Odbc.DLL and print version number
! 
  PRINT LIN(1);"** Loading the Eloquence Odbc.DLL"
  LOAD DLL Odbc,1024
  CALL DLL Odbc("Revision",Buf$)
  PRINT "Revision ";Buf$
! 
! Connect to the data source
! 
  Buf$="DSN=SAMPLE"
  PRINT LIN(1);"** Connecting to the data source ";Buf$
  CALL DLL Odbc("Connect",Buf$,Conn)
! 
! The completed connection string (by the ODBC driver manager)
  CALL DLL Odbc("GetConnection",Conn,Buf$)
  PRINT "Connection #"&VAL$(Conn)&": "&Buf$
! 
! Execute a SQL statement
! 
  PRINT LIN(1);"** Executing SQL statement"
  Buf$="SELECT CUSTNO,MATCHCODE,NAME1,TURNOVER__1 Turnover FROM CUSTOMERS WHERE MATCHCODE LIKE 'KEL%'"
  CALL DLL Odbc("ExecDirect",Conn,Buf$,Stmt)
  PRINT "Statement #"&VAL$(Stmt)&": "&Buf$
! 
! The prepared statement has a result set
! 
  PRINT LIN(1);"** Result set"
  CALL DLL Odbc("GetNumColumns",Stmt,Num_cols)
  FOR Col=1 TO Num_cols
    PRINT "Col";Col;": ";
    CALL DLL Odbc("GetColumnTitle",Stmt,Col,Buf$)
    PRINT Buf$&" [";
    CALL DLL Odbc("GetColumnVarName",Stmt,Col,Buf$)
    PRINT Buf$&"]"
  NEXT Col
! 
! Retrieve the data
! 
  PRINT LIN(1);"** Fetching results"
  Row=0
  LOOP
! The Fetch CALL returns all columns in the Xbuf$ variable in XPACK format
    CALL DLL Odbc("Fetch",Stmt,Has_data,Xbuf$)
    EXIT IF NOT Has_data
    Row=Row+1
! Unpack the result variables
    XUNPACK Xbuf$
! As an alternative the XUNPACK may also specify a subset of variables
    ! XUNPACK Buf$ FROM Custno$,Matchcode$,Name1$,Turnover
    PRINT "[";Row;"]";
    PRINT " "&CHR$(34)&Custno$&CHR$(34);
    PRINT " "&CHR$(34)&Matchcode$&CHR$(34);
    PRINT " "&CHR$(34)&Name1$&CHR$(34);
    PRINT Turnover
  END LOOP
  PRINT Row;"rows fetched"
! 
  PRINT LIN(1);"** Disconnecting"
  CALL DLL Odbc("DropStatement",Stmt)
  CALL DLL Odbc("Disconnect",Conn)
  PRINT "done."
  STOP
! 
! Catch program error
! 
Error:! 
  OFF ERROR
  PRINT ERRM$
  IF (ERRN>=1110) AND (ERRN<=1122) THEN Odbc_error
  PRINT ERRMSG$(ERRN)
  STOP
! 
! ODBC.DLL specific error codes
! 
Odbc_error:! 
  ! PRINT "Problem detected by Odbc.DLL"
  RESTORE Odbc_error
  REPEAT 
    READ Err,Sql_msg$
  UNTIL NOT Err OR (Err=ERRN)
  IF Err THEN PRINT Sql_msg$
  LOOP
    CALL DLL Odbc("GetError",Sql_msg$,Sql_state$,Sql_native_code,Has_data)
    EXIT IF NOT Has_data
    PRINT "ODBC Error: ";Sql_msg$
    PRINT "SQL State: ";Sql_state$;", Native code: ";Sql_native_code
  END LOOP
  STOP
! 
  DATA 1110,"ODBC resource failure (ERR_ODBCRESOURCE)"
  DATA 1111,"ODBC internal failure (ERR_ODBCINTERNAL)"
  DATA 1112,"Invalid call sequence (ERR_SEQUENCE)"
  DATA 1113,"Connection failed (ERR_CONNECT)"
  DATA 1114,"Disconnect failed (ERR_DISCONNECT)"
  DATA 1115,"Already connected (ERR_CONNECTED)"
  DATA 1116,"Not connected (ERR_NOTCONNECTED)"
  DATA 1117,"Statement preparation failed (ERR_PREPARE)"
  DATA 1118,"Statement execution failed (ERR_EXECUTE)"
  DATA 1119,"Statement not prepared (ERR_NOTPREPARED)"
  DATA 1120,"Statement has no result (ERR_NORESULT)"
  DATA 1121,"Failed to fetch next row (ERR_FETCH)"
  DATA 1122,"Column/parameter number out of range (ERR_INVALIDCOLUMN)"
  DATA 0,"Unknown error code"


The third example illustrated how to write data using a prepared statement. It is installed as ODBC3.PROG in the Eloquence share/example installation subdirectory.

! RE-STORE "ODBC3,EXAMPLE"
! 
! Eloquence ODBC DLL example program
! Add data record using prepared statement
! 
  DIM Buf$[256],Sql$[256],Sql_msg$[256],Sql_state$[16]
  INTEGER Conn,Stmt,Has_data,Sql_native_code,Cnt
  ON ERROR GOTO Error
  IF BACKGROUND THEN PRINTER IS STDOUT
! 
! Load the Eloquence Odbc.DLL and print version number
! 
  PRINT LIN(1);"** Loading the Eloquence Odbc.DLL"
  LOAD DLL Odbc,1024
  CALL DLL Odbc("Revision",Buf$)
  PRINT "Revision ";Buf$
! 
  CALL DLL Odbc("LogFile","odbcdll.log")
  CALL DLL Odbc("LogFlags","*3")
! 
! Connect to the data source
! 
  Buf$="DSN=SAMPLE"
  PRINT LIN(1);"** Connecting to the data source ";Buf$
  CALL DLL Odbc("Connect",Buf$,Conn)
! 
! The completed connection string (by the ODBC driver manager)
  CALL DLL Odbc("GetConnection",Conn,Buf$)
  PRINT "Connection #"&VAL$(Conn)&": "&Buf$
! 
! Disable Autocommit
! 
  CALL DLL Odbc("SetAutocommit",Conn,0)
! 
! Prepare an INSERT SQL statement
! NOTE: All columns not specified will be set to NULL
! 
  PRINT LIN(1);"** Preparing SQL statement"
  Sql$="INSERT INTO CUSTOMERS(CUSTNO,MATCHCODE,NAME1) VALUES (?,?,?)"
  CALL DLL Odbc("Prepare",Conn,Sql$,Stmt)
  PRINT "Statement #"&VAL$(Stmt)&": "&Buf$
! 
! Execute the prepared statement
! 
  PRINT LIN(1);"** Add 3 customer records"
  CALL DLL Odbc("Execute",Stmt,"999990","TEST1","Test Name #1")
  CALL DLL Odbc("RowCount",Stmt,Cnt)
  PRINT "Affected rows:";Cnt
  CALL DLL Odbc("Execute",Stmt,"999991","TEST2","Test Name #2")
  CALL DLL Odbc("RowCount",Stmt,Cnt)
  PRINT "Affected rows:";Cnt
  CALL DLL Odbc("Execute",Stmt,"999992","TEST3","Test Name #3")
  CALL DLL Odbc("RowCount",Stmt,Cnt)
  PRINT "Affected rows:";Cnt
! 
! Read new entries
! 
  Sql$="SELECT COUNT(*) FROM CUSTOMERS WHERE CUSTNO IN('999990','999991','999992')"
  CALL DLL Odbc("ExecDirect",Conn,Sql$,Stmt)
  CALL DLL Odbc("Fetch",Stmt,Has_data)
  CALL DLL Odbc("GetData",Stmt,1,Cnt)
  PRINT "Found";Cnt;"entries"
! 
! ROLLBACK transaction
! NOTE #1: COMMIT or ROLLBACK will reset all active cursors
!          for the connection
! NOTE #2: The unixODBC driver manager has bug and also invalidates
!          any prepared statements
! 
  PRINT LIN(1);"** ROLLBACK transaction"
  CALL DLL Odbc("Rollback",Conn)
! 
! Check again for the new entries
! 
  CALL DLL Odbc("ExecDirect",Conn,Sql$,Stmt)
  CALL DLL Odbc("Fetch",Stmt,Has_data)
  CALL DLL Odbc("GetData",Stmt,1,Cnt)
  PRINT "Found";Cnt;"entries"
! 
  PRINT LIN(1);"** Disconnecting"
  CALL DLL Odbc("DropStatement",Stmt)
  CALL DLL Odbc("Disconnect",Conn)
  PRINT "done."
  STOP
! 
! Catch program error
! 
Error:! 
  OFF ERROR
  PRINT ERRM$
  IF (ERRN>=1110) AND (ERRN<=1122) THEN Odbc_error
  PRINT ERRMSG$(ERRN)
  STOP
! 
! ODBC.DLL specific error codes
! 
Odbc_error:! 
  ! PRINT "Problem detected by Odbc.DLL"
  RESTORE Odbc_error
  REPEAT 
     READ Err,Sql_msg$
  UNTIL NOT Err OR (Err=ERRN)
  IF Err THEN PRINT Sql_msg$
  LOOP
     CALL DLL Odbc("GetError",Sql_msg$,Sql_state$,Sql_native_code,Has_data)
     EXIT IF NOT Has_data
     PRINT "ODBC Error: ";Sql_msg$
     PRINT "SQL State: ";Sql_state$;", Native code: ";Sql_native_code
  END LOOP
  STOP
! 
  DATA 1110,"ODBC resource failure (ERR_ODBCRESOURCE)"
  DATA 1111,"ODBC internal failure (ERR_ODBCINTERNAL)"
  DATA 1112,"Invalid call sequence (ERR_SEQUENCE)"
  DATA 1113,"Connection failed (ERR_CONNECT)"
  DATA 1114,"Disconnect failed (ERR_DISCONNECT)"
  DATA 1115,"Already connected (ERR_CONNECTED)"
  DATA 1116,"Not connected (ERR_NOTCONNECTED)"
  DATA 1117,"Statement preparation failed (ERR_PREPARE)"
  DATA 1118,"Statement execution failed (ERR_EXECUTE)"
  DATA 1119,"Statement not prepared (ERR_NOTPREPARED)"
  DATA 1120,"Statement has no result (ERR_NORESULT)"
  DATA 1121,"Failed to fetch next row (ERR_FETCH)"
  DATA 1122,"Column/parameter number out of range (ERR_INVALIDCOLUMN)"
  DATA 0,"Unknown error code"


© 2005 Marxmeier Software AG - 2005-12-28