Determines the length of a language string received from a client.
% INCLUDE SYGWPLI;
01 TDPROC PTR, 01 SQL_LENGTH FIXED BIN(31);
CALL TDSQLLEN (TDPROC, SQL_LENGTH);
(I) Handle for this client/server connection. This must be the same value specified in the associated TDACCEPT call. The TDPROC handle corresponds to the connection and command handles in Open Client Client-Library.
(O) The length of the incoming language string. For graphic datatypes, this is the number of double-byte characters; for other datatypes, it is the number of bytes.
This function has no RETCODE argument. It returns the length of the SQL string in the SQL_LENGTH argument. If the value in SQL_LENGTH is -1, call TDRESULT, and examine its return code to determine what the problem is.
The following code fragment illustrates the use of TDSQLLEN to determine the length of the incoming SQL string. This example is taken from the sample program in Appendix C, “Sample Language Application for CICS.”
/*------------------------------------------------------------------*/ READ_IN_SQL_TEXT: /*------------------------------------------------------------------*/ /* ------------------------------------------------------------*/ /* prepare for receive */ /* ------------------------------------------------------------*/ CALL TDRESULT (GWL_PROC, GWL_RC); /* ------------------------------------------------------------*/ /* load ptr to redefined sql text */ /* ------------------------------------------------------------*/ LANG_BUFFER_PTR = ADDR(LANG_BUFFER_DB2); /* ------------------------------------------------------------*/ /* get len of language text, ensure not too big for us */ /* (this could be handled without TDSQLLEN by checking */ /* LANG_ACTUAL_LEN doesn't exceed LANG_MAX_L in TDRCVSQL call) */ /* ------------------------------------------------------------*/ CALL TDSQLLEN (GWL_PROC, GWL_SQLLEN); LANG_MAX_L = STG(LANG_BUFFER_TEXT); IF GWL_SQLLEN > LANG_MAX_L THEN DO; MSG_TEXT = MSG_BAD_LEN; MSG_TEXT_L = STG(MSG_BAD_LEN); CALL SEND_ERROR_MESSAGE; GO TO END_PROGRAM; END; /* ------------------------------------------------------------*/ /* get language text */ /* ------------------------------------------------------------*/ CALL TDRCVSQL (GWL_PROC, GWL_RC, LANG_BUFFER_TEXT, LANG_MAX_L, LANG_ACTUAL_L); LANG_BUFFER_LL = LANG_ACTUAL_L;
A server application uses this function to determine the actual length of an incoming string.
Typically, an application calls TDSQLLEN after TDACCEPT and before TDRCVSQL to determine how large a storage area to allocate for the incoming string.
You can use TDSQLLEN to store incoming text in more than one variable. Read part of the text into one variable, using TDRCVSQL, then call TDSQLLEN to determine the length of the text that remains. Call TDRCVSQL again to move the remaining text into a second variable. Repeat as often as necessary.
Although this function is called TDSQLLEN, it does not differentiate between SQL strings and other language strings, such as math functions or single-byte katakana. It is up to the application to determine what kind of text is in the buffer and what to do with it.
Related functions
Copyright © 2005. Sybase Inc. All rights reserved. |
![]() |