Dev C++ Get Data From Function

admin
Dev C++ Get Data From Function 7,0/10 9313 votes
-->

Pass your strings by reference and that will allow the called function to change them so the variables in the calling function will have the assigned values. The way you have it passing by value now, you are just sending a copy of the variables so the new values are lost when Input returns. As in C each function can return only one variable so here we need to have the getters equal to number of the data members so that each getter returns the value of one data member. The code below in this tutorial will have getters which will make things more clearer.

Conformance
Version Introduced: ODBC 1.0 Standards Compliance: ISO 92

Summary
SQLGetData retrieves data for a single column in the result set or for a single parameter after SQLParamData returns SQL_PARAM_DATA_AVAILABLE. It can be called multiple times to retrieve variable-length data in parts.

Syntax

Arguments

StatementHandle
[Input] Statement handle.

Col_or_Param_Num
[Input] For retrieving column data, it is the number of the column for which to return data. Result set columns are numbered in increasing column order starting at 1. The bookmark column is column number 0; this can be specified only if bookmarks are enabled.

Jul 21, 2016  A Guide to the Best Traktor Controllers. Need help finding the best Traktor controller for your needs? This is a comprehensive guide for Traktor Kontrol: a line of hardware for DJs by Native Instruments designed to integrate perfectly with Traktor software. Best controller for traktor pro 2. DJ Controller TRAKTOR has kept dancefloors moving for almost 20 years. Our DJ controllers are designed to help you create powerful DJ mixes with TRAKTOR PRO 3 software. From DJ controllers designed for the club, to portable DJ controllers you can fit in a backpack, there's a way for everybody to share the music and mixes they love. TRAKTOR controllers are designed and engineered in-house just a few steps away from TRAKTOR PRO 3. Native Instruments is the industry’s leading manufacturer for integrated hardware.

For retrieving parameter data, it is the ordinal of the parameter, which starts at 1.

TargetType
[Input] The type identifier of the C data type of the *TargetValuePtr buffer. For a list of valid C data types and type identifiers, see the C Data Types section in Appendix D: Data Types. Voice auto tune free download.

If TargetType is SQL_ARD_TYPE, the driver uses the type identifier specified in the SQL_DESC_CONCISE_TYPE field of the ARD. If TargetType is SQL_APD_TYPE, SQLGetData will use the same C data type that was specified in SQLBindParameter. Otherwise, the C data type specified in SQLGetData overrides the C data type specified in SQLBindParameter. If it is SQL_C_DEFAULT, the driver selects the default C data type based on the SQL data type of the source.

You can also specify an extended C data type. For more information, see C Data Types in ODBC.

TargetValuePtr
[Output] Pointer to the buffer in which to return the data.

TargetValuePtr cannot be NULL.

BufferLength
[Input] Length of the *TargetValuePtr buffer in bytes.

The driver uses BufferLength to avoid writing past the end of the *TargetValuePtr buffer when returning variable-length data, such as character or binary data. Note that the driver counts the null-termination character when returning character data to *TargetValuePtr. *TargetValuePtr must therefore contain space for the null-termination character, or the driver will truncate the data.

When the driver returns fixed-length data, such as an integer or a date structure, the driver ignores BufferLength and assumes the buffer is large enough to hold the data. It is therefore important for the application to allocate a large enough buffer for fixed-length data or the driver will write past the end of the buffer.

SQLGetData returns SQLSTATE HY090 (Invalid string or buffer length) when BufferLength is less than 0 but not when BufferLength is 0.

StrLen_or_IndPtr
[Output] Pointer to the buffer in which to return the length or indicator value. If this is a null pointer, no length or indicator value is returned. This returns an error when the data being fetched is NULL.

SQLGetData can return the following values in the length/indicator buffer:

  • The length of the data available to return

  • SQL_NO_TOTAL

  • SQL_NULL_DATA

For more information, see Using Length/Indicator Values and 'Comments' in this topic.

Returns

SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_NO_DATA, SQL_STILL_EXECUTING, SQL_ERROR, or SQL_INVALID_HANDLE.

Diagnostics

When SQLGetData returns either SQL_ERROR or SQL_SUCCESS_WITH_INFO, an associated SQLSTATE value can be obtained by calling SQLGetDiagRec with a HandleType of SQL_HANDLE_STMT and a Handle of StatementHandle. The following table lists the SQLSTATE values commonly returned by SQLGetData and explains each one in the context of this function; the notation '(DM)' precedes the descriptions of SQLSTATEs returned by the Driver Manager. The return code associated with each SQLSTATE value is SQL_ERROR, unless noted otherwise.

SQLSTATEErrorDescription
01000General warningDriver-specific informational message. (Function returns SQL_SUCCESS_WITH_INFO.)
01004String data, right truncatedNot all of the data for the specified column, Col_or_Param_Num, could be retrieved in a single call to the function. SQL_NO_TOTAL or the length of the data remaining in the specified column prior to the current call to SQLGetData is returned in *StrLen_or_IndPtr. (Function returns SQL_SUCCESS_WITH_INFO.)
For more information on using multiple calls to SQLGetData for a single column, see 'Comments.'
01S07Fractional truncationThe data returned for one or more columns was truncated. For numeric data types, the fractional part of the number was truncated. For time, timestamp, and interval data types containing a time component, the fractional portion of the time was truncated.
(Function returns SQL_SUCCESS_WITH_INFO.)
07006Restricted data type attribute violationThe data value of a column in the result set cannot be converted to the C data type specified by the argument TargetType.
07009Invalid descriptor indexThe value specified for the argument Col_or_Param_Num was 0, and the SQL_ATTR_USE_BOOKMARKS statement attribute was set to SQL_UB_OFF.
The value specified for the argument Col_or_Param_Num was greater than the number of columns in the result set.
The Col_or_Param_Num value was not equal to the ordinal of the parameter that is available.
(DM) The specified column was bound. This description does not apply to drivers that return the SQL_GD_BOUND bitmask for the SQL_GETDATA_EXTENSIONS option in SQLGetInfo.
(DM) The number of the specified column was less than or equal to the number of the highest bound column. This description does not apply to drivers that return the SQL_GD_ANY_COLUMN bitmask for the SQL_GETDATA_EXTENSIONS option in SQLGetInfo.
(DM) The application has already called SQLGetData for the current row; the number of the column specified in the current call was less than the number of the column specified in the preceding call; and the driver does not return the SQL_GD_ANY_ORDER bitmask for the SQL_GETDATA_EXTENSIONS option in SQLGetInfo.
(DM) The TargetType argument was SQL_ARD_TYPE, and the Col_or_Param_Num descriptor record in the ARD failed the consistency check.
(DM) The TargetType argument was SQL_ARD_TYPE, and the value in the SQL_DESC_COUNT field of the ARD was less than the Col_or_Param_Num argument.
08S01Communication link failureThe communication link between the driver and the data source to which the driver was connected failed before the function completed processing.
22002Indicator variable required but not suppliedStrLen_or_IndPtr was a null pointer and NULL data was retrieved.
22003Numeric value out of rangeReturning the numeric value (as numeric or string) for the column would have caused the whole (as opposed to fractional) part of the number to be truncated.
For more information, see Appendix D: Data Types.
22007Invalid datetime formatThe character column in the result set was bound to a C date, time, or timestamp structure, and the value in the column was an invalid date, time, or timestamp, respectively. For more information, see Appendix D: Data Types.
22012Division by zeroA value from an arithmetic expression that resulted in division by zero was returned.
22015Interval field overflowAssigning from an exact numeric or interval SQL type to an interval C type caused a loss of significant digits in the leading field.
When returning data to an interval C type, there was no representation of the value of the SQL type in the interval C type.
22018Invalid character value for cast specificationA character column in the result set was returned to a character C buffer, and the column contained a character for which there was no representation in the character set of the buffer.
The C type was an exact or approximate numeric, a datetime, or an interval data type; the SQL type of the column was a character data type; and the value in the column was not a valid literal of the bound C type.
24000Invalid cursor state(DM) The function was called without first calling SQLFetch or SQLFetchScroll to position the cursor on the row of data required.
(DM) The StatementHandle was in an executed state, but no result set was associated with the StatementHandle.
A cursor was open on the StatementHandle and SQLFetch or SQLFetchScroll had been called, but the cursor was positioned before the start of the result set or after the end of the result set.
HY000General errorAn error occurred for which there was no specific SQLSTATE and for which no implementation-specific SQLSTATE was defined. The error message returned by SQLGetDiagRec in the MessageText buffer describes the error and its cause.
HY001Memory allocation errorThe driver was unable to allocate memory required to support execution or completion of the function.
HY003Program type out of range(DM) The argument TargetType was not a valid data type, SQL_C_DEFAULT, SQL_ARD_TYPE (in case of retrieving column data), or SQL_APD_TYPE (in case of retrieving parameter data).
(DM) The argument Col_or_Param_Num was 0, and the argument TargetType was not SQL_C_BOOKMARK for a fixed-length bookmark or SQL_C_VARBOOKMARK for a variable-length bookmark.
HY008Operation canceledAsynchronous processing was enabled for the StatementHandle. The function was called, and before it completed execution, SQLCancel or SQLCancelHandle was called on the StatementHandle, and then the function was called again on the StatementHandle.
The function was called, and before it completed execution, SQLCancel or SQLCancelHandle was called on the StatementHandle from a different thread in a multithread application, and then the function was called again on the StatementHandle.
HY009Invalid use of null pointer(DM) The argument TargetValuePtr was a null pointer.
HY010Function sequence error(DM) The specified StatementHandle was not in an executed state. The function was called without first calling SQLExecDirect, SQLExecute or a catalog function.
(DM) An asynchronously executing function was called for the connection handle that is associated with the StatementHandle. This asynchronous function was still executing when the SQLGetData function was called.
(DM) An asynchronously executing function (not this one) was called for the StatementHandle and was still executing when this function was called.
(DM) SQLExecute, SQLExecDirect, SQLBulkOperations, or SQLSetPos was called for the StatementHandle and returned SQL_NEED_DATA. This function was called before data was sent for all

Variable-length bookmarks can be returned in parts by SQLGetData. As with other data, a call to SQLGetData to return variable-length bookmarks in parts will return SQLSTATE 01004 (String data, right truncated) and SQL_SUCCESS_WITH_INFO when there is more data to be returned. This is different than the case when a variable-length bookmark is truncated by a call to SQLFetch or SQLFetchScroll, which returns SQL_ERROR and SQLSTATE 22001 (String data, right truncated).

SQLGetData cannot be used to return fixed-length data in parts. If SQLGetData is called more than one time in a row for a column containing fixed-length data, it returns SQL_NO_DATA for all calls after the first.

Retrieving Streamed Output Parameters

If a driver supports streamed output parameters, an application can call SQLGetData with a small buffer many times to retrieve a large parameter value. For more information about streamed output parameter, see Retrieving Output Parameters Using SQLGetData.

Retrieving Data with SQLGetData

To return data for the specified column, SQLGetData performs the following sequence of steps:

  1. Returns SQL_NO_DATA if it has already returned all of the data for the column.

  2. Sets *StrLen_or_IndPtr to SQL_NULL_DATA if the data is NULL. If the data is NULL and StrLen_or_IndPtr was a null pointer, SQLGetData returns SQLSTATE 22002 (Indicator variable required but not supplied).

    If the data for the column is not NULL, SQLGetData proceeds to step 3.

  3. If the SQL_ATTR_MAX_LENGTH statement attribute is set to a nonzero value, if the column contains character or binary data, and if SQLGetData has not previously been called for the column, the data is truncated to SQL_ATTR_MAX_LENGTH bytes.

    Note

    The SQL_ATTR_MAX_LENGTH statement attribute is intended to reduce network traffic. It is generally implemented by the data source, which truncates the data before returning it across the network. Drivers and data sources are not required to support it. Therefore, to guarantee that data is truncated to a particular size, an application should allocate a buffer of that size and specify the size in the BufferLength argument.

  4. Converts the data to the type specified in TargetType. The data is given the default precision and scale for that data type. If TargetType is SQL_ARD_TYPE, the data type in the SQL_DESC_CONCISE_TYPE field of the ARD is used. If TargetType is SQL_ARD_TYPE, the data is given the precision and scale in the SQL_DESC_DATETIME_INTERVAL_PRECISION, SQL_DESC_PRECISION, and SQL_DESC_SCALE fields of the ARD, depending on the data type in the SQL_DESC_CONCISE_TYPE field. If any default precision or scale is not appropriate, the application should explicitly set the appropriate descriptor field by a call to SQLSetDescField or SQLSetDescRec.

  5. If the data was converted to a variable-length data type, such as character or binary, SQLGetData checks whether the length of the data exceeds BufferLength. If the length of character data (including the null-termination character) exceeds BufferLength, SQLGetData truncates the data to BufferLength less the length of a null-termination character. It then null-terminates the data. If the length of binary data exceeds the length of the data buffer, SQLGetData truncates it to BufferLength bytes.

    If the data buffer supplied is too small to hold the null-termination character, SQLGetData returns SQL_SUCCESS_WITH_INFO and SQLSTATE 01004.

    SQLGetData never truncates data converted to fixed-length data types; it always assumes that the length of *TargetValuePtr is the size of the data type.

  6. Places the converted (and possibly truncated) data in *TargetValuePtr. Note that SQLGetData cannot return data out of line.

  7. Places the length of the data in *StrLen_or_IndPtr. If StrLen_or_IndPtr was a null pointer, SQLGetData does not return the length.

    • For character or binary data, this is the length of the data after conversion and before truncation due to BufferLength. If the driver cannot determine the length of the data after conversion, as is sometimes the case with long data, it returns SQL_SUCCESS_WITH_INFO and sets the length to SQL_NO_TOTAL. (The last call to SQLGetData must always return the length of the data, not zero or SQL_NO_TOTAL.) If data was truncated due to the SQL_ATTR_MAX_LENGTH statement attribute, the value of this attribute - as opposed to the actual length - is placed in *StrLen_or_IndPtr. This is because this attribute is designed to truncate data on the server before conversion, so the driver has no way of figuring out what the actual length is. When SQLGetData is called multiple times in succession for the same column, this is the length of the data available at the start of the current call; that is, the length decreases with each subsequent call.

    • For all other data types, this is the length of the data after conversion; that is, it is the size of the type to which the data was converted.

  8. If the data is truncated without loss of significance during conversion (for example, the real number 1.234 is truncated when converted to the integer 1) or because BufferLength is too small (for example, the string 'abcdef' is placed in a 4-byte buffer), SQLGetData returns SQLSTATE 01004 (Data truncated) and SQL_SUCCESS_WITH_INFO. If data is truncated without loss of significance due to the SQL_ATTR_MAX_LENGTH statement attribute, SQLGetData returns SQL_SUCCESS and does not return SQLSTATE 01004 (Data truncated).

The contents of the bound data buffer (if SQLGetData is called on a bound column) and the length/indicator buffer are undefined if SQLGetData does not return SQL_SUCCESS or SQL_SUCCESS_WITH_INFO.

Successive calls to SQLGetData will retrieve data from the last column requested; prior offsets become invalid. For example, when the following sequence is performed:

the second call to SQLGetData(icol=n) retrieves data from the start of the n column. Any offset in the data due to earlier calls to SQLGetData for the column is no longer valid.

Descriptors and SQLGetData

SQLGetData does not interact directly with any descriptor fields.

If TargetType is SQL_ARD_TYPE, the data type in the SQL_DESC_CONCISE_TYPE field of the ARD is used. If TargetType is either SQL_ARD_TYPE or SQL_C_DEFAULT, the data is given the precision and scale in the SQL_DESC_DATETIME_INTERVAL_PRECISION, SQL_DESC_PRECISION, and SQL_DESC_SCALE fields of the ARD, depending on the data type in the SQL_DESC_CONCISE_TYPE field.

Code Example

In the following example, an application executes a SELECT statement to return a result set of the customer IDs, names, and phone numbers sorted by name, ID, and phone number. For each row of data, it calls SQLFetch to position the cursor to the next row. It calls SQLGetData to retrieve the fetched data; the buffers for the data and the returned number of bytes are specified in the call to SQLGetData. Finally, it prints each employee's name, ID, and phone number.

Related Functions

For information aboutSee
Assigning storage for a column in a result setSQLBindCol
Performing bulk operations that do not relate to the block cursor positionSQLBulkOperations
Canceling statement processingSQLCancel
Executing an SQL statementSQLExecDirect
Executing a prepared SQL statementSQLExecute
Fetching a block of data or scrolling through a result setSQLFetchScroll
Fetching a single row of data or a block of data in a forward-only directionSQLFetch
Sending parameter data at execution timeSQLPutData
Positioning the cursor, refreshing data in the rowset, or updating or deleting data in the rowsetSQLSetPos

See Also

ODBC API Reference
ODBC Header Files
Retrieving Output Parameters Using SQLGetData

Hi,

Dev C++ Programs

I have a txt file that contain certain data inside it.
Example of the txt file:
Name=John Age=20 Address=c-34, Newyork
Name=Martin Age=23 Address=123, New Delhi
..
..
and so on...
Now I have to process the each line get from the file and put the values into arrays.
arr_name, arr_age, arr_add will be filled from the file.
I have to read 1 line at a time, pass the values of arr_name, arr_age, arr_add to the other function to process it. Again back to the file processing function and read the second line, pass it to the function and similarly for other lines of the file.
How can I complete this task.

Thanks in advance.
Parvez

Dev C++ Get Data From Function Calculator

  • 2 Contributors
  • forum 5 Replies
  • 4,072 Views
  • 2 Days Discussion Span
  • commentLatest Postby Ancient DragonLatest Post

Ancient Dragon5,243

There are several ways to do it, but one way is: in a loop call getline() to read each line, then for each line read use stringstream object to split it into individual tokens. Post the code you have attempted and we can help you some more.

Landoop Fast Data Dev

Edited by Ancient Dragon