Open In App

How to Convert Data From SQL to C Data Types?

Last Updated : 06 Oct, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

At the point when an application calls SQLExecute or SQLExecDirect, the driver recovers the data for any boundaries bound with SQLBindParameter from capacity areas in the application. At the point when an application calls SQLSetPos, the driver recovers the data for an update or adds activity from sections bound with SQLBindCol. For data-at-execution boundaries, the application sends the boundary data with SQLPutData. If important, the driver changes over the data from the data type determined by the ValueType contention in SQLBindParameter to the data type determined by the ParameterType contention in SQLBindParameter, and then, at that point, sends the data to the data source.

The upheld conversions between ODBC SQL data types and ODBC C data types are recorded in the table underneath. The default conversion for a SQL data type (the C data type to which the data will be converted when the worth of TargetType is SQL C DEFAULT) is indicated by a filled circle. A circle that is empty means the conversion was successful. Conversion from driver-specific data configurations probably won’t be upheld for an ODBC 3x application utilizing an ODBC 2x driver.

The configuration of the converted data isn’t affected by the Windows setting.

 

SQL DATA TYPE

C DATA TYPE

 SQL_CHAR

 SQL_VARCHAR
 

 SQL_LONGVARCHAR

 

SQL_WCHAR            

SQL_WVARCHAR

SQL_WLONGVARCHAR

SQL_DECIMAL

SQL_NUMERIC

SQL_BIT

SQL_TINY INT(signed

SQL_TINYINT(unsigned)

SQL_SMALL INT(signed)

SQL_SMALLINT(unsigned)

SQL_INTEGER(signed)

SQL_INTEGER(unsigned)

SQL_BIG INT(signed)

SQL_BIG INT(unsigned)

SQL_REAL

SQL_FLOAT

SQL_C_CHAR

  •  
  •  
  •  

ο

ο

ο

  •  
  •  

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

οSQL_C_WCHAR

ο

ο

ο

  •  
  •  
  •  

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

SQL_C_BIT 

ο

ο

ο

ο

ο

ο

ο

ο

  •  

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

SQL_C_NUMERIC

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

SQL_C_STINYINT   

ο

ο

ο

ο

ο

ο

ο

ο

ο

  •  

ο

ο

ο

ο

ο

ο

ο

ο

ο

SQL_C_UTINYINT 

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

  •  

ο

ο

ο

ο

ο

ο

ο

ο

SQL_C_TINYINT  

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

SQL_C_SBIGINT 

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

  •  

ο

ο

ο

SQL_C_UBIGINT 

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

  •  

ο

ο

SQL_C_SSHORT

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

  •  

ο

ο

ο

ο

ο

ο

ο

SQL_C_USHORT 

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

  •  

ο

ο

ο

ο

ο

ο

SQL_C_SHORT   

ο

ο

 

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

SQL_C_SLONG 

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

  •  

ο

ο

ο

ο

ο

SQL_C_ULONG  

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

  •  

ο

ο

ο

ο

SQL_C_LONG 

ο

ο

ο

ο

ο

ο

ο

ο

ο

 

ο

ο

ο

ο

ο

ο

ο

ο

ο

SQL_C_FLOAT

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

  •  

ο

SQL_C_DOUBLE     

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

  •  

SQL_C_BINARY 

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

SQL_C_TYPE_DATE

ο

ο

ο

ο

ο

ο

 

 

 

 

 

 

 

 

 

 

 

 

 

SQL_C_TYPE_TIME       

ο

ο

ο

ο

ο

ο

 

 

 

 

 

 

 

 

 

 

 

 

 

SQL_C_TYPE_TIMESTAMP       

ο

ο

ο

ο

ο

ο

 

 

 

 

 

 

 

 

 

 

 

 

 

INTERVAL_C(DATE-TIME)

ο

ο

ο

ο

ο

ο

ο

ο

 

ο

ο

ο

ο

ο

ο

ο

ο

 

 

INTERVAL_C(YEAR-MONTH)   

ο

ο

ο

ο

ο

ο

ο

ο

 

ο

ο

ο

ο

ο

ο

ο

ο

 

 

SQL_C_GUID     

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SQL DATA TYPE & C DATA TYPE SQL_DOUBLE SQL_BINARY SQL_VARBINARY SQL_LONGVARBINARY SQL_TYPE_DATE SQL_TYPE_TIME SQL_TYPE_TIMESTAMP  INTERVAL_SQL(DATE-TIME) INTERVAL_SQL(YEAR-MONTH) SQL_GUID
SQL_C_CHAR

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

οSQL_C_WCHAR

ο

ο

ο

ο

ο

ο

ο

ο

ο

ο

SQL_C_BIT 

ο

 

 

 

 

 

 

ο

ο

 

SQL_C_NUMERIC

ο

 

 

 

 

 

 

ο

ο

 

SQL_C_STINYINT   

ο

 

 

 

 

 

 

ο

ο

 

SQL_C_UTINYINT 

ο

 

 

 

 

 

 

ο

ο

 

SQL_C_TINYINT  

ο

 

 

 

 

 

 

ο

ο

 

SQL_C_SBIGINT 

ο

 

 

 

 

 

 

ο

ο

 

SQL_C_UBIGINT 

ο

 

 

 

 

 

 

ο

ο

 

SQL_C_SSHORT

ο

 

 

 

 

 

 

ο

ο

 

SQL_C_USHORT 

ο

 

 

 

 

 

 

ο

ο

 

SQL_C_SHORT   

ο

 

 

 

 

 

 

ο

ο

 

SQL_C_SLONG 

ο

 

 

 

 

 

 

ο

ο

 

SQL_C_ULONG  

ο

 

 

 

 

 

 

ο

ο

 

SQL_C_LONG 

ο

 

 

 

 

 

 

ο

ο

 

SQL_C_FLOAT

ο

 

 

 

 

 

 

 

 

 

SQL_C_DOUBLE     
  •  

 

 

 

 

 

 

 

 

 

SQL_C_BINARY 

ο

  •  
  •  
  •  

ο

ο

ο

ο

ο

ο

SQL_C_TYPE_DATE

 

 

 

 

  •  

 

ο

 

 

 

SQL_C_TYPE_TIME       

 

 

 

 

 

  •  

ο

 

 

 

SQL_C_TYPE_TIMESTAMP       

 

 

 

 

 

    ο

  •  

 

 

 

INTERVAL_C(DATE-TIME)

 

 

 

 

 

 

 

  •  

 

 

INTERVAL_C(YEAR-MONTH)   

 

 

 

 

 

 

 

 

  •  

 

SQL_C_GUID     

 

 

 

 

 

 

 

 

 

ο

The tables in the accompanying sections describe how the driver or data source converts data shipped off the data source; drivers are expected to help conversions from all ODBC C data types to the ODBC SQL data types that they support. For a given ODBC C data type, the main column of the table records the legitimate info upsides of the Boundary Type contention in SQLBindParameter. The second column records the outcomes of a test that the driver performs to decide whether it can convert the data. The third column records the SQLSTATE returned for each outcome by SQLExecDirect, SQLExecute, SQLBulkOperations, SQLSetPos, or SQLPutData. Data is shipped off the data source provided that SQL_SUCCESS is returned.

Assuming that the ParameterType contention in SQLBindParameter contains the identifier of an ODBC SQL data type that isn’t displayed in that frame of mind for a given C data type, SQLBindParameter returns SQLSTATE 07006 (Restricted data type property infringement). On the off chance that the Boundary Type contention contains a driver-specific identifier and the driver doesn’t uphold the conversion from the specific ODBC C data type to that driver-specific SQL data type, SQLBindParameter returns SQLSTATE HYC00 (Discretionary element not executed).

Assuming the ParameterValuePtr and StrLen_or_IndPtr contentions specified in SQLBindParameter are both invalid pointers, that function returns SQLSTATE HY009 (Invalid utilization of invalid pointer). Although it isn’t displayed in the tables, an application sets the worth of the length/indicator cushion highlighted by the StrLen_or_IndPtr contention of SQLBindParameter or the worth of the StrLen_or_IndPtr contention of SQLPutData to SQL_NULL_DATA to specify an Invalid SQL data esteem. (The StrLen_or_IndPtr contention corresponds to the SQL_DESC_OCTET_LENGTH_PTR field of the APD.) The application sets these qualities to SQL_NTS to specify that the worth in *ParameterValuePtr in SQLBindParameter or *DataPtr in SQLPutData (highlighted by the SQL_DESC_DATA_PTR field of the APD) is an invalid ended string.

The Accompanying Terms are Utilized in Tables:

  1. The byte length of data – Number of bytes of SQL data accessible to ship off the data source, whether the data will be truncated before it is shipped off the data source. For string data, this doesn’t include space for the invalid end character.
  2. Column byte length – Number of bytes expected to store the data at the data source.
  3. Character byte length – Most extreme number of bytes expected to show data in character structure. This is as characterized for each SQL data type in Show Size, except character byte length is in bytes, while the presentation size is in characters.
  4. A number of digits – The number of characters used to address a number, including the less sign, decimal point, and example (if necessary).


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads