Microsoft KB Archive/65463

INF: COBOL and Other Language Support for DB-LIBRARY

PSS ID Number: Q65463 Article last modified on 12-18-1992

1.10 1.11 4.20 OS/2

Summary: In SQL Server version 1.1 and 1.11, the manuals include examples that use DB-LIBRARY (db-lib) routines within C and BASIC programs. Other Microsoft languages can also call db-lib routines. The db-lib routines can be used with C, COBOL, and other languages that conform to C calling conventions, including the following: - Microsoft BASIC Compiler - Microsoft C Optimizing Compiler - Microsoft COBOL Optimizing Compiler - Microsoft FORTRAN Optimizing Compiler - Microsoft Macro Assembler - Microsoft Pascal Compiler

More Information: An example follows showing how to use these libraries in Microsoft COBOL. Do not use null-terminated strings because they are troublesome. The purpose of the INSPECT statements is to insert x’00’ to create a null-terminated string. The STRING…DELIMITED statement is used to copy the null-terminated string returned by db-lib into a buffer without causing a segment violation. The rest of SQLFRONT should be converted to level 78’s. working-storage section. 01 login POINTER. 01 dbproc POINTER. 01 msghp PROCEDURE-POINTER. 01 usr pic x(16) value “username”. 01 svr pic x(16) value “isv_server”. 01 cmd pic x(40). 01 FILLER pic x(1) values x’00’. 01 msgtext2 pic x(255). 01 objname pic x(30). 78 NO-MORE-ROWS value -2. 78 DBSETUSER value 2. 78 FAIL value 0. 78 CHARBIND value 4. 78 SIZEOF-SHORT value 2. 78 SIZEOF-LONG value 4. local-storage section. linkage section. 01 dbpr pointer. 01 msgno pic S9(9) comp-5. 01 state pic S9(4) comp-5. 01 sev pic S9(4) comp-5. 01 msgtext pic x(255). procedure division. main section. INSPECT usr REPLACING FIRST SPACE BY x’00’. INSPECT svr REPLACING FIRST SPACE BY x’00’. SET msghp TO ENTRY “MSGH”. CALL &quot;_dbmsghandle&quot; USING BY VALUE msghp. CALL &quot;_dblogin&quot; RETURNING login. CALL &quot;_dbsetlname&quot; USING BY VALUE login, BY REFERENCE usr, BY VALUE DBSETUSER SIZE 2. CALL &quot;_dbopen&quot; USING BY VALUE login, BY REFERENCE svr RETURNING dbproc. display “Enter SQL” accept cmd. CALL &quot;_dbcmd&quot; USING BY VALUE dbproc, BY REFERENCE cmd. CALL &quot;_dbsqlexec&quot; USING BY VALUE dbproc. CALL &quot;_dbresults&quot; USING BY VALUE dbproc. * CALL &quot;_dbprhead&quot; USING BY VALUE dbproc. * CALL &quot;_dbprrow&quot; USING BY VALUE dbproc. CALL &quot;_dbbind&quot; USING BY VALUE dbproc, BY VALUE 1 SIZE 2, BY VALUE CHARBIND SIZE 2, BY VALUE 0 SIZE 4, BY REFERENCE objname. perform until RETURN-CODE = NO-MORE-ROWS CALL &quot;_dbnextrow&quot; USING BY VALUE dbproc if RETURN-CODE not = NO-MORE-ROWS display objname end-perform. stop run. handle-msg section. ENTRY “MSGH” USING BY REFERENCE dbpr, BY VALUE msgno, BY VALUE state, BY VALUE sev, BY REFERENCE msgtext. display “Msgno=” msgno &quot; Sev=&quot; sev &quot; State=&quot; state. move spaces to msgtext2. STRING msgtext DELIMITED BY x’00’ INTO msgtext2. display msgtext2. EXIT PROGRAM RETURNING 0.

= Additional reference words: dblib =

Copyright Microsoft Corporation 1992.