<<

USOO58093O2A United States Patent (19) 11 Patent Number: 5,809,302 Wang et al. (45) Date of Patent: Sep. 15, 1998

54 SYSTEM AND METHOD FOR ENABLING “Concert/C:Supporting Distributed Programming with Lan POINTERS TO BE PASSED FROM guage', Auerbach et al., Distr. Computing System, 1994 COMPUTER PROGRAMS WRITTEN USING LANGUAGES Int’l Conf., pp. 152-159. THAT DO NOT SUPPORT POINTERS 75 Inventors: I-Shin Andy Wang, San Jose; Primary Examiner Kevin A. Kriess Frederick Thomas Sharp, Menlo Park; ASSistant Examiner Kakali Chaki Rita Shiao-yuan Wu; John Shek-Luen Attorney, Agent, or Firm-Prentiss Wayne Johnson; Sterne, Ng, both of San Jose; Kuo-Wei Kessler, Goldstein & Fox, plc Hwang, Milpitas; David Y. Chen, San Jose, all of Calif. 57 ABSTRACT 73 Assignee: International Business Machines Described herein is a System and method for enabling an Corp., Armonk, N.Y. application to pass a Structure containing a pointer member to an external entity, wherein the application represents a 21 Appl. No.: 521,806 computer program executing in a computer System, and the 22 Filed: Aug. 31, 1995 computer program is written in a computer programming language that does not Support pointers. The application (51) Int. Cl...... G06F 9/44 declares a variable V, a Structure type having a member P. 52 U.S. Cl...... 395/680; 395/710; 395/685 and a variable M of the structure type. The application 58 Field of Search ...... 395/685, 680, invokes a function written in a computer programming 395/710 language that Supports pointers. A reference to the variable 56) References Cited V is passed to the function. The function, when executed, obtains and returns an address of the variable V. The U.S. PATENT DOCUMENTS application sets the member P in the variable M equal to the 5,369,766 11/1994 Nakano et al...... 395/700 address of the variable V. The application then passes the 5,515,536 5/1996 Corbett et al...... 395/700 variable M to an external entity. In this manner, the present OTHER PUBLICATIONS invention enables a structure having a pointer embedded “Smart Remote Procedure Calls:Transparent Treatment of therein to be passed to the external entity. Remote Pointers”, Kono et al., Distributed Computing Sys tem, 1994 Int’l Conf., pp. 142-151. 41 Claims, 5 Drawing Sheets

602 START

606 DECLARE A WARIABEY

DECLARE A STRUCTURE TYPE SO8 CONTAINING AWARIABLE P OF TYPE LONG INTEGER

OECLARE AWARIABLEM GO OF THE STRUCTURE IYPE

INYOKE A FUNCTION PROVIDED BY THE SECOND COMPUTING 12 ENVIRONMENT TO OBTAIN THE ADDRESS OF WARIABLE W

SET WARIABLEP INSTRUCTURE 14 WARIABLE MEOUA T0 THIS AOCRESS

U.S. Patent Sep. 15, 1998 Sheet 1 of 5 5,809,302

FIG 1A 101

N

FIRST COMPUTING ENVIRONMENT SECOND COMPUTING ENVIRONMENT PROCEDURE 110 FIRST 104 LIBRARY APPLICATION SECOND 108 APPLICATION

FIG. 1B SYSTEM 150 N 152 154 U.S. Patent Sep. 15, 1998 Sheet 2 of 5 5,809,302 FIG. 2 204 1. 2O2 PROCESSOR 206 2OB

SECONOARY MEMORY

216

REMOVABLE REMOVABLE

STORAGE STORAGE DRIVE UNIT

FIG 3 302 304

306

RECEIVE REFERENCE (ADDRESS) TO WARIABLE

RETURN ADDRESS U.S. Patent Sep. 15, 1998 Sheet 3 of 5 5,809,302 FIG. 4 404 408 HANDLE POINTER 402 4O6 STRING POINTER

FIG. 5 504 502

RECEIVE REFERENCE ADDRESS) - 506 TO HANDLE (IE, RECEIVE HANDLE POINTER)

UTILIZE HANDLE POINTER 508 TO ACCESS HANDLE AND OBTAIN STRING POINTER

LOCK STRING POINTER TO 510 PREVENT STRING POINTER FROM CHANGING

512 RETURN STRING POINTER

514 U.S. Patent Sep. 15, 1998 Sheet 4 of 5 5,809,302

FIG. 6 604 602

606 DECLARE A WARIABLE V

DECLARE A STRUCTURE TYPE GO CONTAINING AWARIABLE P OF TYPE LONG INTEGER

DECLARE A WARIABLEM G10 OF THE STRUCTURE TYPE

INVOKE A FUNCTION PROVIDED BY THE SECOND COMPUTING 612 ENVIRONMENT TO OBTAIN THE ADDRESS OF WARIABLE N

SET WARIABLE PIN STRUCTURE - 614 WARIABLE MEOUAL TO THIS ADDRESS U.S. Patent Sep. 15, 1998 Sheet 5 of 5 5,809,302 FIG. 7 DESCRIPTOR 104

NUMBER OF DIMENSIONS SIZE OF AN ARRAY ELEMENT DESCRIPTOR SIZE OF THE ARRAY POINTER POINTER TO DIMENSION DIMENSION O INFO INFORMATION (LOWER BOUND DIMENSION 1 INFO AND NUMBER OF ELEMENTS FOREACH DIMENSION) DIMENSION 2 INFO POINTER TO THE ARRAY DATA

DATA ITEM O DATA ITEM 1 DATA ITEM 2

FIG. 9 802

RECEIVE REFERENCE (ADDRESS) 804 TO ARRAY DESCRIPTOR

USE DESCRIPTOR STRUCTURE 806 INFORMATION TO OBTAIN POINTER TO FIRST ARRAY ELEMENT

RETURN POINTER TO 808 FIRST ELEMENT

810 5,809,302 1 2 SYSTEMAND METHOD FOR ENABLING Thus, what is required is a System and method for POINTERS TO BE PASSED FROM enabling a pointer to be passed from a first executing COMPUTER PROGRAMS WRITTEN USING computer program, written in a language that does not COMPUTER PROGRAMMING LANGUAGES Support pointers, to a Second executing computer program, THAT DO NOT SUPPORT POINTERS written in a language that does Support pointers. CROSS-REFERENCE TO OTHER DISCLOSURE OF INVENTION APPLICATIONS Briefly Stated, the present invention is directed to a System The following applications of common assignee contain and method for enabling an application to pass a pointer to Some common disclosure, and are believed to have an an external entity, wherein the application represents a effective filing date identical with that of the present appli computer program executing in a computer System, and the cation. computer program is written in a computer programming “SYSTEMAND METHOD FOR ENABLING A COM language that does not Support pointers. According to the PILED COMPUTER PROGRAM TO INVOKE AN present invention, the application declares a variable V, a INTERPRETIVE COMPUTER PROGRAM,” Attorney 15 structure type having a member P, and a variable M of the Docket No. ST9-95-028 (1252.2230000)Ser. No. 07/521, Structure type. The application invokes a function written in 805, incorporated herein by reference in its entirety. a computer programming language that Supports pointers. A “PLATFORM-TRANSPARENT REGISTRATION AND reference to the variable V is passed to the function. The BUILD OF STORED PROCEDURES AND USER function, when executed, obtains and returns an address of DEFINED FUNCTIONS,” Attorney Docket No. ST9-95 the variable V. The application sets the member P in the 032 (1252.2290000)Ser. No. 07/521,804, now U.S. Pat. No. variable M equal to the address of the variable V. The 5,657,447, incorporated herein by reference in its entirety. application then passes the variable M to an external entity. “PASSING STRUCTURES OR ARRAYS AS HOST In this manner, the present invention enables a structure VARIABLES.” Attorney Docket No. ST9-95-027 having a pointer embedded therein to be passed to the (1252.2240000)Ser. No. 07/521,710, incorporated herein by 25 external entity. reference in its entirety. Further features and advantages of the invention, as well “NO PREPROCESSOR AND A SOURCE LEVEL as the Structure and operation of various embodiments of the DEBUGGER FOR EMBEDDED SQL IN A3GL,” Attorney invention, are described in detail below with reference to the Docket No. ST9-95-024 (1252.2270000)Ser. No. 07/521, accompanying drawings. In the drawings, like reference 711, incorporated herein by reference in its entirety. numbers generally indicate identical, functionally similar, and/or structurally Similar elements. The drawing in which TECHNICAL FIELD an element first appears is indicated by the digit(s) to the left of the two rightmost digits in the corresponding reference The present invention relates generally to a System and number. method for enabling a pointer to be passed from a first 35 executing computer program, Written in a language that does BRIEF DESCRIPTION OF DRAWINGS not Support pointers, to a Second executing computer program, written in a language that does Support pointers. The present invention will be described with reference to the accompanying drawings, wherein: BACKGROUND ART 40 FIG. 1A is a block diagram of a data processing environ Computer programs written in different computer pro ment according to a preferred embodiment of the present gramming languages are often required to interact during invention; run-time (one program may invoke another program, for FIG. 1B is a database System representing an application example). These computer programming languages do not of the invention; all Support the Same Set of functions or features. Thus, 45 problems may arise when a first computer program, written FIG. 2 is a block diagram of a computer System useful for in a first computer programming language, is interacting implementing components of the invention; with a Second computer program, written in a Second FIGS. 3, 5, 6 and 8 are flowcharts representing the computer programming language, and the first computer preferred operation of the invention; program is attempting to utilize a feature that is Supported by 50 FIG. 4 illustrates a String representation; and the first computer programming language but not Supported FIG. 7 illustrates an array representation. by the Second computer programming language. For example, consider the well known BASIC computer BEST MODE FOR CARRYING OUT THE programming language. Although Some BASIC interpreters INVENTION provide a means of passing a BASIC variable to an external 55 FIG. 1 is a block diagram of a data processing environ procedure by reference, that is, as a pointer, BASIC does not ment 101 according to a preferred embodiment of the Support or recognize pointers internally. In the BASIC present invention. The data processing environment 101 language you cannot, for example, obtain a value by using includes a first computing environment 102 in which a first a pointer to a variable. Consider a Scenario where a program application 104 executes, and a Second computing environ written in BASIC attempts to invoke a procedure written in 60 ment 106 in which a second application 108 executes. The C (or Some other computer language that Supports pointers) Second computing environment 106 also includes a proce and where the C procedure requires an argument that is a dure library 110. Structure containing a pointer to a variable in the BASIC The first application 104 interacts with the second appli program. Since BASIC does not Support pointers, the cation 108 and the procedure library 110. For example, the BASIC program cannot properly interact with the C proce 65 first application 104 may pass data to the Second application dure; it cannot initialize the required Structure containing the 108, or invoke procedures contained in the procedure library pointer. 110. 5,809,302 3 4 The first computing environment 102 represents a first FIG. 1B illustrates a possible application of the invention. computer System implemented using a computer Such as that Shown in FIG. 1B is a database system 150 comprising a shown in FIG. 2 (described in detail below). The first client 152 and a server 154. The database system 150 application 104 represents a computer program executing in corresponds to the data processing environment 101, the the first computer system. The first application 104 is written client 152 corresponds to the first computing environment in a first computer programming language that does not 102, and the server 154 corresponds to the second comput Support pointers. The first computer programming language ing environment 106. may be the well known BASIC computer programming The server 154 represents a database system, preferably language, or any other language that does not Support the DB2 database system produced by International Busi pointers. ness Machines (IBM) Corporation of Armonk, N.Y. The Second computing environment 106 represents a (although any other database System employing a computer Second computer System implemented using a computer programming language that Supports pointers could alterna such as that shown in FIG. 2. The second application 108 tively be used). The procedure library 110 preferably rep represents a computer program executing in the Second resents a dynamic link library (DLL) that may be called from computer system. The second application 108 is written in a a BASIC program (i.e., the first application 104). The client Second computer programming language that Supports 15 152 interacts with the server 154 to access the services and pointers (Such as C, Fortran, Ada, Cobol, etc.). The proce data offered by the server 154. dure library 110 contains procedures that, when invoked, Referring again to FIG. 1A, the procedure library 110 execute in the Second computer System. Preferably, the includes routines for enabling a pointer to be passed from an procedure library 110 is written in the second computer application, written in a language that does not Support programming language, or any other language that Supports pointers, to another application, written in a language that pointers. does Support pointers. More particularly, the procedure Referring now to FIG. 2, the computer system 202 library 110 includes routines that enable a pointer to be includes one or more processors, Such as processor 204. The passed from the first application 104 to the Second applica processor 204 is connected to a communication bus 206. tion 108 and/or a procedure of the procedure library 110. The computer System 202 also includes a main memory 25 These procedures of the procedure library 110 that enable 208, preferably random access memory (RAM), and a this functionality shall now be described. secondary memory 210. The secondary memory 210 Passing a Pointer to a Non-String Variable includes, for example, one or more hard disk drives 212 According to the present invention, the procedure library and/or one or more removable Storage drives 214, each 110 includes an ADDR function (ADDR stands for representing a floppy disk drive, a magnetic tape drive, a “address”). As indicated by a flowchart 302 shown in FIG. compact disk drive, etc. These devices may be connected 3, the ADDR function, when executed, receives a reference directly to the bus 206 or may be connected over a network to a variable (step 306). This reference represents an address (not shown). The removable storage drives 214 each reads of the variable. The ADDR function then returns this address from and/or writes to a removable storage unit 216 in a well 35 to the calling entity (step 308). known manner. An example implementation of the ADDR function is Removable Storage unit 216, also called a program Stor shown below in Code Example 1 (for illustrative purposes, age device or a computer program product, represents a the ADDR function is written in C, but it should be under floppy disk, magnetic tape, compact disk, etc. AS will be stood that the ADDR function could alternatively be written appreciated, the removable Storage unit 216 includes a 40 in any language that Supports pointers). computer uSable Storage medium having Stored therein computer Software and/or data. 1. void ADDR (void p) Computer programs (also called computer control logic) 2 { are stored in main memory 208 and/or the secondary 3 return p; memory 210. Such computer programs, when executed, 45 4 enable the computer system 202 to perform the features of Code Example 1 the present invention as discussed herein. In particular, the computer programs, when executed, enable the processor Line 1 indicates that the ADDR function receives a pointer 204 to perform the features of the present invention. p, representing a reference (i.e., an address) to a variable (or Accordingly, Such computer programs represent controllers 50 function). Line 1 also indicates that the ADDR function of the computer System 202. For example, the first applica returns a pointer (i.e., an address). This return of a pointer is tion 104, second application 108, and procedure library 110 performed in line 3, where the pointer p is returned to the represent computer programs executing in one or more calling entity. computer systems 202. Example computer code for invoking the ADDR function In another embodiment, the invention is directed to a 55 is shown in Code Example 2. This code is contained in the computer program product comprising a computer readable first application 104. For illustrative purposes, this code is medium having control logic (computer Software) stored written in BASIC, but it should be understood that this code therein. The control logic, when executed by the processor could alternatively be written in any language that does not 204, causes the processor 204 to perform the functions of the Support pointers. invention as described herein. 60 1 declare function ADDR (y as any) as long Preferably, the first computing environment 102 is imple 2 dim X as integer mented using one computer System 202, and the Second 3 dim ptras long computing environment 102 is implemented using another 4 ptr=ADDR(x) computer system 202 (the computer systems 202 being connected via a network, for example). Alternatively, the 65 CODE EXAMPLE 2 first and second computing environments 102, 106 may be Line 1 of Code Example 2, when executed, operates to implemented on the same computer System 202. declare the function ADDR. (This statement enables the first 5,809,302 S 6 application 104 to later invoke the function ADDR from the access the handle 404 and retrieve the string pointer 406 procedure library 110.) Function ADDR as declared in line stored therein (step 508). The ADDRSTRING function 1 of Code Example 2 has a passed parametery, which may then locks this String pointer 406 So as to prevent the String be any data type, and returns a long integer. variable 408 from moving from one memory location to another. Finally, the ADDRSTRING function returns the It is noted that, in 32-bit computer Systems, a pointer (or String pointer 406. Later, the locked String either is aban address) is four bytes long. Along integer is also four bytes doned when the variable goes out of Scope or when the long. (Generally speaking, the size of a pointer is always program terminates (during which the System frees memory equal to the size of a long integer.) Accordingly, a pointer associated with the program), or is explicitly unlocked by can be represented as a long integer. Thus, line 1 in Code the user by using another function provided by the present Example 1 is consistent with line 1 in Code Example 2. invention, called UNLOCKSTRING (implementation of Line 2 in Code Example 2 declareS X to be an integer UNLOCKSTRING will be apparent to persons skilled in variable. Line 3 defines ptr to be a long integer variable. In the relevant art(s)). line 4, the function ADDR from the procedure library 110 is An example implementation of the ADDRSTRING invoked. According to the present invention, eXecution of function is shown below in Code Example 4 (for illustrative line 4 is Such that a reference to variable X is passed to the 15 purposes, the ADDRSTRING function is written in C, but function ADDR in the procedure library 110 (such operation it should be understood that the ADDRSTRING function is Standard, Since the variable X merely represents a location could alternatively be written in any language that Supports in memory). In other words, the address of variable X is pointers). passed to the function ADDR. The function ADDR operates as described above, and Sets ptr equal to the address of 1. void ADDR STRING (void handle ptr) variable X. 2 { Passing a Pointer to a String Variable 3 void p; The ADDR function described above can be used with 4 p = dereference handle pointer (handle ptr); variables of most, if not all, data types. However, in Systems 5 lock (p) that employ handles to strings, the ADDR function cannot be 25 6 return p; used with String variables. Code Example 4 Consider the Scenario presented in FIG. 4. A String variable 408 is addressed by a string pointer 406. The string pointer 406 is not directly accessible, however. Instead, the Line 1 indicates that the ADDR STRING function receives string pointer 406 is stored in a handle 404 that is associated a handle pointer 402, representing a reference (i.e., an with the string variable 408. A handle pointer 402 addresses address) to a handle 404. Line 1 also indicates that the the handle 404. The handle pointer 402, not the string ADDR STRING function returns a pointer (i.e., an pointer 406, is what is available to applications to access address). In line 3, a pointer p is declared. In line 4, a String variables. (Handles are used for function called “dereference handlepointer is called. reasons. Often times, Strings must be moved from one 35 The dereference handle pointer function receives the location in memory to another. In Such cases, the String handle pointer 402, uses the handle pointer 402 to access the pointerS Stored in the associated handles must be modified. handle 404, and retrieves the string pointer 406 contained in However, it is not necessary to modify the handle pointers. the handle 404. The dereference handle pointer function Thus, the handle pointerS represent an indirect but stable is preferably part of a run-time library provided by the 40 Second computer programming language. Implementation mechanism for accessing Strings.) of the dereference handlepointer function will be appar Consider Code Example 3, where an attempt is made to ent to persons skilled in the relevant art(s). use the ADDR function with a string variable S. The dereference handlepointer function returns the 1 declare function ADDR (y as any) as long string pointer 406. Pointer variable p is set equal to the string 2 dim S as String 45 pointer 406. 3 dim ptras long In line 5, a lock function is called to lock the String 4 ptr=ADDR(s) variable 408 referenced by the string pointer 406. The lock function is preferably part of a run-time library provided by CODE EXAMPLE 3 the Second computer programming language. Implementa 50 tion of the lock function will be apparent to perSons skilled ASSume that the System in which this code is executed in the relevant art(s). maintains Strings as shown in FIG. 4, Such that S references In line 6, the string pointer 406 is returned to the calling the handle 404, instead of the string 408. In this case, the entity. ADDR function would return the address of the handle 404, Example computer code for invoking the instead of the address to the string variable 408. This is not 55 ADDRSTRING function is shown in Code Example 5. the desired result. Instead, it is desired to return the address This code is contained in the first application 104. For of the string variable 408. illustrative purposes, this code is written in BASIC, but it According to the present invention, an ADDRSTRING should be understood that this code could alternatively be function is also stored in the procedure library 110. This written in any language that does not Support pointers. function is invoked for String variables in those Systems that 60 1 declare function ADDRSTRING (y as any) as long maintain String variables as shown in FIG. 4. 2 dim S as String The ADDRSTRING function, when invoked, performs 3 dim ptras long the steps shown in a flowchart 502 of FIG. 5. Specifically, 4 ptr=ADDRSTRING(s) the ADDRSTRING function receives a reference to a CODE EXAMPLE 5 handle 404 (step 506). This reference represents an address 65 of the handle 404 (i.e., the handle pointer 402). The Line 1 of Code Example 5, when executed, operates to ADDRSTRING function utilizes the handle pointer 402 to declare the function ADDRSTRING. (This statement 5,809,302 7 8 enables the first application 104 to later invoke the function beginning of the data type/structure is not necessarily the ADDRSTRING from the procedure library 110.) Function Same as the beginning of the data value in the data type/ ADDRSTRING as declared in line 1 of Code Example 2 structure. Any needed modifications to the ADDRARRAY has a passed parametery, which may be any data type, and function would be apparent to perSons skilled in the relevant returns a long integer. art(s).) Line 2 in Code Example 2 declares S to be a String An example implementation of the ADDRARRAY variable. Line 3 defines ptr to be a long integer variable. In function is shown below in Code Example 6 (for illustrative line 4, the function ADDRSTRING from the procedure purposes, the ADDRARRAY function is shown below as library 110 is invoked. The function ADDRSTRING oper being written in C, but it should be understood that the ates as described above and Sets ptr equal to the String ADDRARRAY function could alternatively be written in pointer 406. any language that Supports pointers). Passing a Pointer to an Array Variable Passing a pointer to a String variable is a special case of 1. typedef struct ArrayTag *PArray; passing a pointer to a language construct that has an external 2 typedef struct ArrayTag { or internal Structure. The beginning of the Structure is not 15 3 intuiNumDim:14 f* Number of dimensions in necessarily the same as the beginning of the data value in the the array */ Structure. Another Such language construct is an array 4 short cbElements: /* Size of an array element (bytes) */ (although the following applies to any simple or complex 5 long uiSize; /* Size of the array, in data type or structure for which the beginning of the data bytes. */ type/structure is not necessarily the same as the beginning of 6 void plata; /* Pointer to array data. */ the data value in the data type/structure). 7 Dimension *pDim; f Pointer to dimension information. f ADDR and ADDRSTRING can be used for most scalar 8 Array; variables in BASIC; however, they cannot be used for 9 void ADDR ARRAY (Array descriptor ptr) returning the address of the first element of an array in a language Such as BASIC. Like the handle Structure for a 25 11 Return descriptor ptr->pData; String variable, an array variable may begin with an internal 12 descriptor Structure, which Specifies, for example, its data type, its dimensions, and the upper and lower bound for each dimension. Furthermore, in BASIC, an array of varying CODE EXAMPLE 6 length Strings in an array does not give its true address Line 9 indicates that the ADDRARRAY function because the value of the fixed length String is copied to a receives a descriptor pointer 702, representing a reference varying length String for the purpose of calling an external (i.e., an address) to an array descriptor 704 (which is procedure. preferably implemented as a structure). Line 9 also indicates Some procedures that should be callable from a language that the ADDRARRAY function returns a pointer (i.e., an such as BASIC require the address of the first element of a 35 address). In line 6, a pointer to the data in the array is String array in which each element is Sequential in a con declared for the array descriptor 704. In line 11, the pointer tiguous block of memory. One Such procedure is the well to the first element of the array is returned. known ODBC API SQLExtended Fetch, which requires that Example computer code for invoking the the address of the first element of an array be bound, using ADDRSTRING function is shown in Code Example 7. SOLBindCol, to each column in the result set to be fetched. 40 This code is contained in the first application 104. For A third procedure of the procedure library 110, illustrative purposes, this code is written in BASIC, but it ADDRARRAY, therefore, returns a pointer to the first should be understood that this code could alternatively be element of an array variable (more generally, the written in any language that does not Support pointers. ADDRARRAY function returns a pointer to a memory 1 Declare function ADDRARRAY (a as Any) as Long location containing the data associated with the variable). 45 2 Declare function SQLAllocConnect (ByVal henv as long, This function is invoked for array variables in those systems phdbc as long) as integer that maintain array variables as shown in FIG. 7. FIG. 7 3 Declare function SQLAllocEnv (phenvas long) as integer shows a descriptor pointer 702 that points to an array 4 Declare function SQLAllocStmt (ByVal hdbc as long, descriptor 704 (implemented as a structure). The array phstmt as long) as integer descriptor 704 has fields that store the following informa 50 5 Declare function SQLConnect (ByValhdbcas long, ByVal tion: number of dimensions in array, Size of an array SZDSN as string, ByVal cbDSN as integer, ByVal SZUID element, size of the array, a pointer to dimension information as string, ByVal cbUID as integer, ByVal SZAuthStras 706 (i.e., the lower bound and the number of elements for String, ByVal cb AuthStras integer) as integer each dimension), and a pointer to the array data 708. 6 Declare function SQLSetStmtOption (ByVal stimt as long, The operation of the ADDRARRAY function is illus 55 ByVal foption as integer, ByVal VParam as long) as trated in flowchart form in FIG. 8. The ADDRARRAY integer function receives a reference to an array descriptor 702 (Step 7 Declare function SQLExecDirect (ByVal hstmt as long, 804). This reference represents an address of the descriptor ByVal SzSqlStr as string, ByVal cbSqlStr as long) as 704. The ADDRARRAY function uses the information integer contained in the descriptor 704 to obtain a pointer to the first 60 8 Declare function SQLBindCol (ByVal hstmt as long, element of the array (i.e., data item 0 in the array information ByVal icol as integer, ByVal f(Type as integer, ByVal 708). This occurs in step 806. The ADDRARRAY function rgbValue as long, ByVal cbValueMax as long, pcbValue returns this pointer to the first array element (step 808). as long) as integer (While the invention has been described with reference to 9 Declare function SQLExtended Fetch (ByVal hstmt as an array, it should be understood that the ADDRARRAY 65 long, ByVal fetchType as integer, ByVal iRow as long, function could be used with little or no modifications with pcRow as long, rgfRowStatus as integer) as integer any simple or complex data type or structure for which the 10 Dim rc as integer 5,809,302 9 10 11 Dim henV as long, hdbc as long In step 608, the first application 104 declares a structure 12 Dim salarr(ROWSET, SIZE) as string*COLWIDTH type having a member p that is declared as a long integer. 13 Dim Row Stat(ROWSETSIZE) as integer (More generally, variable p is declared as any data type 14 Dim Stmt as String wherein the memory allocated to an instance of the data type 15 Stmt-“SELECT SALARY FROM STAFF is greater than or equal to memory allocated to a pointer.) 16 server=" SAMPLE”: uid=*USERID”: pw d= In step 610, the first application 104 declares a variable M “PASSWORD of the Structure type. 17 rc=SQLAllocEnv(henv) In step 612, the first application 104 invokes either ADDR 18 rc=SQLAllocConnect(henv,hdbc) (if the variable v is not a string) or ADDRSTRING (if the 19 rc=SQLAllocStmt(hdbc.hstmt) variable v is a string) to obtain the address of variable v. 20 r c=S Q L C on n e c t ( h d b c , s e r v e r, In step 614, the first application 104 sets member p in len(Server),uid,len(uid).pwd,len(pwd)) variable M equal to this address of variable v. 21 rc=SQLSetStmtOption(hstmt, SQLROWSETSIZE, Processing of flowchart 602 is now complete. ROWSET, SIZE) At this point, the first application 104 can pass variable M 22 rc=SQLExecDirect(hstmt, stimt, len(stmt)) 15 to an external entity (during a procedure invocation, for 23 rc=SQLBindCol (hstmt, 1, SQL BASICSTRING, example). (Alternatively, the first application 104 can pass ADDR ARRAY (salarr), ROWSET SIZE, member p directly to the external entity.) Variable M con COLWIDTH) tains the long integer member p that Stores the address of 24rc=SQLExtended Fetch(hstmt, SQLFETCH NEXT, 0, variable v. From the perspective of the external entity, pcrow, Row Stat(O)) member p is a pointer (recall that pointers are the same size CODE EXAMPLE 7 as long integers). Accordingly, the external entity can per Line 1 of Code Example 7, when executed, operates to form conventional pointer operations using member p. AS declare the function ADDRARRAY. Similar Declare state just one example, the external entity can utilize member p to ments in lines 2-9 exist for each of the well known ODBC gain access to variable V. Other pointer operations will be APIs used in the example. For ease of readability (given that 25 apparent to persons skilled in the relevant art(s). Code Example 7 is an example invocation of the Note that the first application 104 cannot perform pointer ADDRARRAY function), not all declarations are shown, operations using member p, even though member p Stores and constants are not defined in Code Example 7. the address of variable v. This is the case, because the first Lines 15 and 16 initialize strings for the SQL SELECT application 104 was written in a computer programming Statement to be executed and for the database, userid, and language that does not Support or recognize pointers. Thus, password to be used in connecting to the database. the first application 104 cannot or manipulate point Lines 17-19 allocate environment, connection, and State CS. ment handles. Accordingly, the invention enables the first application Line 20 connects to the SAMPLE database. 104 to pass pointers to external entities that Support pointers. 35 However, the invention does not enable the first application Line 21 directs the database manager to return 104 to itself utilize pointers. This represents an advantage of ROWSETSIZE rows for each extended fetch. the invention, Since pointer manipulation represents a pow Line 22 executes the SQL SELECT statement, which erful yet dangerous functionality. It is not advantageous to directs the database manager to create a result Set with one allow Such functionality to exist in interpreter execution result column containing the Salaries of the employees in the 40 environments, Such as BASIC, where uncompiled computer STAFF table. programs are executed (since the checks associated with Line 23 binds salarro array to the salary column of the compilation would not be present). result Set by passing the address of the first element of the Example computer code for implementing that part of the array with the size of each element of the array. The first application 104 that passes pointerS is presented in Code ADDRARRAY function operates as described above and 45 Example 6. For illustrative purposes, this code is written in returns a pointer to the first element of SalarrO to the BASIC, but it should be understood that this code could SOLBindCol API. alternatively be written in any language that does not Line 24 fetches ROWSETSIZE rows from the result set, Support pointers. which places ROWSET SIZE rows into the 1 declare function ADDRSTRING (y as any) as long ROWSETSIZE elements of the salarr() array. Subsequent 50 2 dim V as String program code can reference the Salary values directly from 3 type pointerinside salarro, the BASIC array. Operation of the First Application 4 p as long The operation of the first application 104 pertaining to the 5 end type passing of a pointer shall now be described with reference to 55 6 dim m as pointerinside a flowchart 602 presented in FIG. 6. For illustrative 7 m.p=ADDRSTRING(v) purposes, flowchart 602 shall be described with respect to a Scenario where the first application 104 is passing a structure CODE EXAMPLE 6 containing a pointer to an external entity that Supports In line 1, the first application 104 declares the pointers (the external entity represents Something that is 60 ADDRSTRING function so it can invoke this function external to the first application 104, Such as the Second later. In line 2, the first application 104 declares variable v application 108 or a procedure from the procedure library as a String. In lines 3-5, the first application 104 declares a 110, for example). Flowchart 602 begins with step 604, new structure type called pointerinside that contains a where control immediately passes to step 606. member p declared as long integer (line 4). In line 6, the first In step 606, the first application 104 declares a variable v. 65 application 104 declares a variable m as a pointerinside Ultimately, a pointer to this variable v will be passed to the structure. In line 7, the first application 104 invokes the external entity. ADDRSTRING and sets member p in variable m equal to 5,809,302 11 12 the returned address of variable v. At this point, the first 7. The method of claim 1, wherein in step (1) said variable application 104 can pass variable m to an external entity. V is declared as an array, and wherein step (4) comprises the While various embodiments of the present invention have Step of: been described above, it should be understood that they have invoking an ADDRARRAY function written in a com been presented by way of example only, and not limitation. puter programming language that Supports pointers, a Thus, the breadth and scope of the present invention should reference to an array descriptor associated with Said not be limited by any of the above-described exemplary variable V being passed to said ADDRARRAY embodiments, but should be defined only in accordance with function, said ADDRARRAY function when the following claims and their equivalents. executed performing the Steps of: Having thus described our invention, what we claim as 1O (i) receiving said array descriptor reference; new and desire to Secure by letters patent is: (ii) using said array descriptor reference to access said 1. A method performed by an application representing a array descriptor and to retrieve a pointer Stored computer program executing in a computer System, the therein, Said pointer referencing a data element of computer program written in a computer programming said variable V; and language that does not Support pointers, the method enabling 15 (iii) returning said pointer. the application to pass a pointer to an external entity, the 8. The method of claim 1, wherein in step (1) said variable method comprising the Steps of V is declared as a data type or Structure for which a memory (1) declaring a variable V; location of Said variable V is not equal to a memory location of data associated with said variable V, and wherein said (2) declaring a structure type having a member P; function when invoked in Step (4) obtains and returns a (3) declaring a variable M of Said structure type; pointer that references Said memory location containing Said (4) invoking a function written in a computer program data associated with said variable V. ming language that Supports pointers, a reference to 9. The method of claim 1, wherein in step (4) said Said variable V being passed to Said function, Said function receives a pointer to Said variable V, Said pointer function when executed obtaining and returning an 25 not referencing a memory location of data associated with address of said variable V; said variable V, and wherein said function when invoked in (5) setting said member Pin said variable M equal to said Step (4) obtains and returns a pointer that references said address of said variable V; and memory location containing Said data associated with Said (6) passing said variable M to an external entity. variable V. 2. The method of claim 1, wherein step (2) comprises the 10. A computer System having a memory and an appli Step of cation Stored therein, the application including a module for declaring a Structure type having a member P of a data enabling the application to pass a pointer to an external type, wherein memory allocated to an instance of Said entity, the application representing a computer program data type is greater than or equal to memory allocated executing in the computer System, the computer program to a pointer. 35 written in a computer programming language that does not 3. The method of claim 2, wherein Said data type is equal Support pointers, the module comprising: to long integer. first declaring means for declaring a variable V, 4. The method of claim 1, wherein in step (1) said variable Second declaring means for declaring a structure type V is declared as a non-String, and wherein Step (4) comprises having a member P; the step of: 40 third declaring means for declaring a variable M of Said invoking an ADDR function written in a computer pro Structure type; gramming language that Supports pointers, a reference invoking means for invoking a function written in a to said variable V being passed to said ADDR function, computer programming language that Supports said ADDR function when executed performing the pointers, a reference to Said variable V being passed to Steps of 45 Said function, Said function when executed obtaining (i) receiving said reference to said variable V; and and returning an address of Said variable V, (ii) returning said reference to said variable V. Setting means for Setting Said member P in Said variable 5. The method of claim 1, wherein in step (1) said variable M equal to said address of said variable V; and V is declared as a string, and wherein Step (4) comprises the 50 passing means for passing Said variable M to an external Step of entity. invoking an ADDRSTRING function written in a com 11. The system of claim 10, wherein said second declaring puter programming language that Supports pointers, a means comprises: reference to a handle associated with said variable V means for declaring a structure type having a member P being passed to said ADDRSTRING function, said 55 of a data type, wherein memory allocated to an instance ADDRSTRING function when executed performing of Said data type is greater than or equal to memory the Steps of: allocated to a pointer. (i) receiving said handle reference; 12. The system of claim 11, wherein said data type is (ii) utilizing Said handle reference to access said handle equal to long integer. and to retrieve a String pointer Stored therein, Said 60 13. The system of claim 10, wherein said first declaring String pointer referencing Said variable V; and means declares Said variable V as a non-String, and wherein (iii) returning said String pointer. Said invoking means comprises: 6. The method of claim 5, wherein said ADDRSTRING means for invoking an ADDR function written in a function when executed further performs the following Step computer programming language that Supports between Steps (ii) and (iii): 65 pointers, a reference to Said variable V being passed to locking Said String pointer So as to prevent Said String said ADDR function, said ADDR function when pointer from changing. executed performing the Steps of: 5,809,302 13 14 (i) receiving said reference to said variable V; and entity being an invocation of a computer program (ii) returning said reference to said variable V. Written in a computer programming language that 14. The system of claim 10, wherein said first declaring Supports pointers. means declares Said variable V as a String, and wherein Said 19. The database system of claim 18, wherein said second invoking means comprises: 5 declaring means comprises: means for invoking an ADDRSTRING function written means for declaring a structure type having a member P in a computer programming language that Supports of a data type, wherein memory allocated to an instance pointers, a reference to Said variable V being passed to of Said data type is greater than or equal to memory said ADDRSTRING function, said ADDRSTRING allocated to a pointer. function when executed performing the Steps of: 20. The database system of claim 19, wherein said data (i) receiving said handle reference; type is equal to long integer. (ii) utilizing Said handle reference to access said handle 21. The database system of claim 18, wherein said first and to retrieve a String pointer Stored therein, Said declaring means declares Said variable V as a non-String, and String pointer referencing Said variable V; and wherein said procedure library includes an ADDR function (iii) returning said String pointer. 15 written in a computer programming language that Supports 15. The system of claim 14, where in said pointers, and wherein Said invoking means comprises: ADDRSTRING function when executed further performs means for invoking Said ADDR function, a reference to the following step between steps (ii) and (iii): said variable V being passed to said ADDR function, locking Said String pointer So as to prevent Said String said ADDR function when executed performing the pointer from changing. Steps of 16. The system of claim 10, wherein said first declaring (i) receiving said reference to said variable V; and means declares Said variable V as an array, and wherein Said (ii) returning said reference to said variable V. invoking means comprises: 22. The database system of claim 18, wherein said first means for invoking an ADDRARRAY function written declaring means declares said variable V as a String, and in a computer programming language that Supports 25 where in Said procedure library include S an pointers, a reference to a descriptor for Said variable V ADDRSTRING function written in a computer program being passed to said ADDRARRAY function, said ming language that Supports pointers, and wherein Said ADDRARRAY function when executed performing invoking means comprises: the Steps of: means for invoking said ADDRSTRING function, a (i) receiving said descriptor reference; reference to Said variable V being passed to Said (ii) using said descriptor reference to access said ADDRSTRING function, said ADDRSTRING descriptor and to retrieve a pointer Stored therein, function when executed performing the Steps of: Said pointer referencing a data element of Said vari (i) receiving said handle reference; able V; and (ii) utilizing Said handle reference to access said handle (iii) returning said pointer. 35 and to retrieve a String pointer Stored therein, Said 17. The system of claim 10, wherein said function String pointer referencing Said variable V; and invoked by Said invoking means receives a pointer to Said (iii) returning said String pointer. variable V, Said pointer not referencing a memory location of 23. The database system of claim 22, wherein said data associated with Said variable V, and wherein Said ADDRSTRING function when executed further performs function when executed obtains and returns a pointer that 40 the following step between steps (ii) and (iii): references said memory location containing Said data asso locking Said String pointer So as to prevent Said String ciated with said variable V. pointer from changing. 18. A database System, comprising: 24. The database system of claim 18, wherein said pro a client; 45 cedure library represents a dynamic link library, and wherein a Server coupled to Said client and comprising a procedure Said application represents a computer program written in library, Said procedure library including a function that, BASIC and being executed by an interpreter in said client. when executed, obtains and returns an address of a 25. A program Storage device readable by a machine, parameter passed to Said function; and tangibly embodying a program of instructions executable by an application executing in Said client, Said application 50 the machine to perform method steps for enabling an appli being an invocation of a computer program written in cation to pass a pointer to an external entity, the application a computer programming language that does not Sup representing a computer program executing in the machine, port pointers, said application comprising: the computer program written in a computer programming first declaring means for declaring a variable V; language that does not Support pointers, Said method steps Second declaring means for declaring a Structure type 55 comprising: having a member P; (1) declaring a variable V; third declaring means for declaring a variable M of Said (2) declaring a structure type having a member P; Structure type, invoking means for invoking Said function in Said (3) declaring a variable M of said structure type; procedure library, a reference to Said variable V 60 (4) invoking a function written in a computer program being passed to Said function, Said function when ming language that Supports pointers, a reference to executed obtaining and returning an address of Said Said variable V being passed to Said function, Said variable V: function when executed obtaining and returning an Setting means for Setting Said member Pin Said variable address of said variable V; M equal to said address of said variable V; and 65 (5) setting said member Pin said variable M equal to said passing means for passing Said variable M to an exter address of said variable V; and nal entity executing in Said Server, Said external (6) passing said variable M to an external entity. 5,809,302 15 16 26. The program Storage device of claim 25, wherein Step 34. A computer program product comprising a computer (2) comprises the step of: uSeable medium having computer program logic recorded declaring a Structure type having a member P of a data thereon for enabling a processor in a computer System to enable an application to pass a pointer to an external entity, type, wherein memory allocated to an instance of Said the application representing a computer program executing data type is greater than or equal to memory allocated in the computer System, the computer program written in a to a pointer. computer programming language that does not Support 27. The program Storage device of claim 26, wherein Said pointers, Said computer program logic comprising: data type is equal to long integer. first declaring means for enabling the processor to declare 28. The program storage device of claim 25, wherein in a variable V; Step (1) said variable V is declared as a non-String, and 1O Second declaring means for enabling the processor to wherein step (4) comprises the step of: declare a structure type having a member P; invoking an ADDR function written in a computer pro third declaring means for enabling the processor to gramming language that Supports pointers, a reference declare a variable M of Said structure type, to said variable V being passed to said ADDR function, invoking means for enabling the processor to invoke a said ADDR function when executed performing the 15 function written in a computer programming language Steps of that Supports pointers, a reference to Said variable V (i) receiving said reference to said variable V; and being passed to Said function, Said function when (ii) returning said reference to said variable V. executed enabling the processor to obtain and return an 29. The program storage device of claim 25, wherein in address of said variable V; Step (1) said variable V is declared as a string, and wherein Setting means for enabling the processor to Set Said Step (4) comprises the Step of: member P in said variable M equal to said address of invoking an ADDRSTRING function written in a com said variable V; and puter programming language that Supports pointers, a passing means for enabling the processor to pass Said reference to a handle associated with said variable V variable M to an external entity. being passed to said ADDRSTRING function, said 25 35. The computer program product of claim 34, wherein ADDRSTRING function when executed performing Said Second declaring means comprises: the Steps of: means for enabling the processor to declare a structure (i) receiving said handle reference; type having a member P of a data type, wherein (ii) utilizing Said handle reference to access said handle memory allocated to an instance of Said data type is and to retrieve a String pointer Stored therein, Said greater than or equal to memory allocated to a pointer. String pointer referencing Said variable V; and 36. The computer program product of claim 35, wherein (iii) returning said String pointer. Said data type is equal to long integer. 30. The program storage device of claim 29, wherein said 37. The computer program product of claim 34, wherein ADDRSTRING function when executed further performs 35 Said first declaring means enables the processor to declare the following step between steps (ii) and (iii): Said variable V as a non-String, and wherein Said invoking locking Said String pointer So as to prevent Said String means comprises: pointer from changing. means for enabling the processor to invoke an ADDR 31. The program storage device of claim 25, wherein in function written in a computer programming language Step (1) said variable V is declared as an array, and wherein 40 that Supports pointers, a reference to Said variable V Step (4) comprises the Step of: being passed to said ADDR function, said ADDR invoking an ADDRARRAY function written in a com function when executed enabling the processor to per puter programming language that Supports pointers, a form the steps of: reference to an array descriptor associated with Said (i) receiving said reference to said variable V; and variable V being passed to said ADDRARRAY 45 (ii) returning said reference to said variable V. function, said ADDRARRAY function when 38. The computer program product of claim 34, wherein executed performing the Steps of: Said first declaring means enables the processor to declare (i) receiving said array descriptor reference; Said variable V as a String, and wherein Said invoking means (ii) using said array descriptor reference to access said comprises: array descriptor and to retrieve a pointer Stored 50 means for enabling the processor to invoke an therein, Said pointer referencing a data element of ADDRSTRING function written in a computer pro said variable V; and gramming language that Supports pointers, a reference (iii) returning said pointer. to Said variable V being passed to Said 32. The program Storage device of claim 25, wherein in ADDRSTRING function, said ADDRSTRING Step (1) said variable V is declared as a data type or structure 55 function when executed enabling the processor to per for which a memory location of said variable V is not equal form the steps of: to a memory location of data associated with Said variable V, (i) receiving said handle reference; and wherein said function when invoked in Step (4) obtains (ii) utilizing Said handle reference to access said handle and returns a pointer that references Said memory location and to retrieve a String pointer Stored therein, Said containing Said data associated with Said variable V. 60 String pointer referencing Said variable V; and 33. The program storage device of claim 25, wherein in (iii) returning said String pointer. Step (4) said function receives a pointer to said variable V, 39. The computer program product of claim 38, wherein Said pointer not referencing a memory location of data said ADDR STRING function when executed further asSociated with Said variable V, and wherein Said function enables the processor to perform the following Step between when invoked in Step (4) obtains and returns a pointer that 65 Steps (ii) and (iii): references said memory location containing Said data asso locking Said String pointer So as to prevent Said String ciated with said variable V. pointer from changing. 5,809,302 17 18 40. The computer program product of claim 34, wherein (ii) using said descriptor reference to access said Said first declaring means enables the processor to declare descriptor and to retrieve a pointer Stored therein, Said variable V as an array, and wherein Said invoking means Said pointer referencing a data element of Said vari able V; and comprises: (iii) returning said pointer. means for enabling the processor to invoke an 41. The computer program product of claim 34, wherein ADDRARRAY function written in a computer pro Said function invoked by Said invoking means receives a gramming language that Supports pointers, a reference pointer to Said variable V, Said pointer not referencing a to a descriptor for Said variable V being passed to Said memory location of data associated with Said variable V, and wherein Said function when executed enables the processor ADDRARRAY function, said ADDRARRAY 10 to obtain and return a pointer that references said memory function when executed enabling the processor to per location containing Said data associated with Said variable V. form the steps of: (i) receiving said descriptor reference; k k k k k